Thanks, this explains it. 

On Thursday, October 8, 2015 at 6:41:05 PM UTC+3, Isaiah wrote:
>
> It is the expanded AST, i.e. the same as this (except for line numbers):
>
> (:(x -> x + 1) |> expand).ast
>
> As far as `eval`: try eval'ing `:(x -> x+1) |> expand` directly, and then 
> look at the form of that expanded expression (hint: it is a 
> LambdaStaticData). Also see how this is done in `base/serialize.jl` -- or, 
> ideally, just reuse that functionality.
>
>
> On Wed, Oct 7, 2015 at 7:13 PM, Andrei Zh <faithle...@gmail.com 
> <javascript:>> wrote:
>
>> If `f` is anonymous function:
>>
>> f = x -> x + 1
>>
>> what is the format of AST returned by: 
>>
>> Base.uncompressed_ast(f.code)
>>
>> ? I expected it to be pure AST of a lambda function, but it's quite 
>> different from quoting lambda directly: 
>>
>> julia> dump(Base.uncompressed_ast(f.code))
>>  Expr
>>    head: Symbol lambda
>>    args: Array(Any,(3,))
>>      1: Array(Any,(1,))
>>        1: Expr
>>          head: Symbol ::
>>          args: Array(Any,(2,))
>>            1: Symbol x
>>            2: Symbol Any
>>          typ: Any
>>      2: Array(Any,(4,))
>>        1: Array(Any,(1,))
>>          1: Array(Any,(3,))
>>            1: Symbol x
>>            2: Symbol Any
>>            3: Int64 0
>>        2: Array(Any,(0,))
>>        3: Int64 0
>>        4: Array(Any,(0,))
>>      3: Expr
>>        head: Symbol body
>>        args: Array(Any,(2,))
>>          1: LineNumberNode
>>            file: Symbol /home/slipslop/work/jl/Sparta/src/fnserialization
>> .jl
>>            line: Int64 63
>>          2: Expr
>>            head: Symbol return
>>            args: Array(Any,(1,))
>>            typ: Any
>>        typ: Any
>>    typ: Any
>>
>> !julia> dump(quote x -> x + 1 end)
>>  Expr
>>    head: Symbol block
>>    args: Array(Any,(2,))
>>      1: LineNumberNode
>>        file: Symbol none
>>        line: Int64 1
>>      2: Expr
>>        head: Symbol ->
>>        args: Array(Any,(2,))
>>          1: Symbol x
>>          2: Expr
>>            head: Symbol block
>>            args: Array(Any,(2,))
>>            typ: Any
>>        typ: Any
>>    typ: Any
>>
>> And most important is that it doesn't resulting AST doesn't evaluate back 
>> to a proper anonymous function: 
>>
>>  julia> ast = Base.uncompressed_ast(f.code)
>>  :($(Expr(:lambda, Any[:(x::Any)], Any[Any[Any[:x,:Any,0]],Any[],0,Any
>> []], :(begin  # /home/slipslop/work/jl/Sparta/src/fnserialization.jl, 
>> line 63:                    
>>          return x + 1
>>      end))))
>>
>>
>>  julia> fn = eval(ast)
>>  (anonymous function)
>>
>>
>>  julia> fn(1)
>>  ERROR: wrong number of arguments
>>   in anonymous at no file
>>
>> So how do I read the output of `Base.uncompressed_ast` and what is the 
>> proper way to reconstruct (anonymous) function from AST? 
>>
>>
>

Reply via email to