Is it possible to quote code where the methods are already resolved? For example, instead of `+` being a symbol in the quoted code, it would be resolved to the + operator from the current module?
On Friday, May 23, 2014 8:31:19 PM UTC-4, Isaiah wrote: > > parse("...codez...") can be helpful too. > > For (1) & (2), the single-quoted numbers are interpreted as literals > rather than symbols. It is possible to create a Symbol called `:1` with > `symbol("1")`, if needed, but that seems strange. The entry syntax `:1` > might be disallowed for efficiency and disambiguation - I'm not sure. > > For (3), in general, a TopNode tells the compiler to resolve any names to > the current base module. It might be illustrative to look at the difference > between these expressions: > > julia> a = 1 > 1 > > julia> :($a + 1) > :(1 + 1) > > julia> :(1+:(a+2)) > :(1 + :(a + 2)) > > julia> :(1+:($a+2)) > :(1 + top(Expr)(:call,:+,a,2)) > > The last case asks for an interpolation which cannot be expanded at parse > time, because the interpolation is quoted. The `top(Expr)` and `call` are > generated to guarantee that `foo` - whatever the value of `foo` ends up as > in the Top module namespace - is used when the expression is evaluated. > > (as an aside, eval'ing those last two examples will give errors, > because it is not possible to add an Int and an Expr) > > > > > > On Fri, May 23, 2014 at 3:53 PM, Adam Smith <swiss.arm...@gmail.com > <javascript:>> wrote: > >> I find it quite helpful to use dump() on expressions to see the first few >> levels of the parsed AST. That makes it easier to see what Julia is doing >> with your expressions. >> >> >> On Thursday, May 22, 2014 5:17:13 PM UTC-4, Andrew McKinlay wrote: >>> >>> I have been trying to grok Julia macros, so I've dived into the >>> metaprogramming docs. Whilst playing around with the interpreter, I've run >>> into some peculiarities that I don't quite understand. >>> >>> julia> versioninfo() >>> Julia Version 0.3.0-prerelease+2690 >>> Commit e4c2f68* (2014-04-20 12:15 UTC) >>> ... >>> >>> >>> 1. Why is typeof( :(:(1+2)) ) == Expr, but typeof( :(:(1)) ) == >>> QuoteNode? >>> 2. Why is typeof( :(1) ) == Int64, but again typeof( :(:(1)) ) == >>> QuoteNode? >>> 3. Why is typeof( :(1+:($1+2)).args[3].args[1] ) == TopNode? >>> >>> >>> I was assuming that quoting was just a shorthand way for constructing >>> expressions, since the docs say: >>> >>>> There is special syntax for “quoting” code (analogous to quoting >>>> strings) that makes it easy to create expression objects without >>>> explicitly >>>> constructing Expr objects. >>> >>> But the types of objects constructed by quoting do not always take the >>> form of an Expr, as above. >>> >>> What is going on here? >>> >> >