Thanks for adding some details.

I'm a CoffeeScript programmer, and programming languages is like a hobby.
> I've looked into several languages to see how AST works, Ruby does that,
> Elixir does that. Julia's AST is acutally quite similar to them, but not
> the same, it does not generate code from AST.
>

Hmmm... I hope I didn't give that impression (or maybe I'm not
understanding your statement).  Julia generates code from the AST as soon
as the AST is evaluated.  So, for example, if I can do

julia> e = :(inc(x) = x + 1)
:(inc(x) = begin  # none, line 1:
            x + 1
        end)

julia> typeof(e)
Expr

julia> eval(e)
inc (generic function with 1 method)

julia> inc(2)
3

In this case, I created the Expr directly, using quote syntax, but I could
also create it using

julia> e2 = Expr(:(=), Expr(:call, :inc2, :x), Expr(:call, :+, :x, 1))
:(inc2(x) = x + 1)

julia> eval(e2)
inc2 (generic function with 1 method)

julia> inc2(3)
4

which is more cumbersome manually, but probably easier programmatically.


> I'm interested in indentation-based syntax and started my project. I tried
> to pull out Julia's AST as a compiler backend and use my project named
> Cirru as the frontend. Which can be see at
> https://github.com/Cirru/CirruSepal.jl#usage CirruSepal.jl will generate
> Julia AST from my syntax.
>

It sounds like all you need to do is call eval() on your generated AST.

So if there's an approach to generate Julia code from AST, then there's
> another interesting way to write Julia. Like we always do in JavaScript.
> Julia is great from my view that it's like a dynamic language, but
> internally it generates LLVM IR, which is far more interesting than
> JavaScript. JavaScript is like a compling target, and JavaScript AST is
> also a very good one. Compared to JavaScript AST, Julia's AST is
> interesting but lack of such features.
>

Hopefully the above clears some things up, but post again if you still have
thoughts/questions.  Good luck on your Cirru project!

Cheers!
   Kevin





>
>
> On Sun, Jun 21, 2015 at 11:52 PM Kevin Squire <[email protected]>
> wrote:
>
>> There is no such function right now.  In Julia, the common paradigm for
>> manipulating code is to manipulate the expression itself.
>>
>> You can, of course, output the expression, and it often looks better than
>> what David posted above (e.g., this is what parse outputs).
>>
>> Perhaps you can discuss a little more about what you're trying to do, and
>> someone here can tell you how (or if) it's typically done in Julia?
>>
>> Cheers,
>>    Kevin
>>
>>
>> On Sunday, June 21, 2015 at 8:04:21 AM UTC-7, Jiyin Yiyong wrote:
>>>
>>> No. I'm looking for a function that takes in Julia AST Expr and returns
>>> Julia code in string, a opposite of the function `parse`.
>>>
>>> On Sun, Jun 21, 2015 at 10:55 PM Peter Brady <[email protected]>
>>> wrote:
>>>
>>>> Are you looking for 'eval'?
>>>
>>>

Reply via email to