On Tue, Aug 18, 2015 at 11:24 AM, Sisyphuss <[email protected]> wrote:
>
>
> On Tuesday, August 18, 2015 at 2:11:40 PM UTC+2, Yichao Yu wrote:
>>
>> On Tue, Aug 18, 2015 at 6:49 AM, Sisyphuss <[email protected]> wrote:
>> > I'm reading the documentation Metaprogramming chapter.
>> > To me, the `$` operator is different from the one in the string
>> > interpolation.
>> > In the string, `$` is a runtime interpolation.
>> > In the expression, `$` is a compile-time interpolation.
>>
>> No. Both of them happens at whenever the expression is evaluated. It
>> happens for `@eval` at "compile time" because that's when the macro
>> expansion happens.
>>
> for i in 1:3
>     println("$(rand())")
> end
> It prints different values each iteration, so it's run-time interpolation.

julia> for i in 1:3
          println(:($(rand())))
      end
0.0513060369910221
0.006705158934253941
0.2977791327125763

>
>>
>> >
>> > In one example provided, `ex = :(a in $:((1,2,3)) )`,
>> > I find that it's equal to `ex = :(a in (1,2,3) )`.
>> > So I do not see the intention of `$`.
>>
>> The examples are meant to show you the basic rules not necessarily the
>> best/only way to do it.
>
>
> Really don't see the rules from these examples.

The rule is to show you how to splice an expression.

> In this example, the tuple (1,2,3) is **interpolated as an expression into a 
> conditional test:**

>
>>
>>
>> >
>> > In the next example, there is `:a + :b` in the expression,
>> > but the sum of `Symbols` is not defined. Is it wrong?
>>
>> It just construct an expression and to show you that the result is
>> quoted symbol rather than the symbol themselves.

Reply via email to