Re: [julia-users] implicit begin for macro

201 views
Skip to first unread message

Tamas Papp

unread,
May 3, 2015, 2:01:55 PM5/3/15
to Julia Dev
On Sun, May 03 2015, Toivo Henningsson <toiv...@gmail.com> wrote:

> Yes, so far that is true. Any suggestions on how such a thing could work in practice? I belive that we would still want to be able to parse Julia code completely without knowing which macros have been defined.

(took this to julia-dev)

Been thinking about this the whole afternoon, in a more general context:
for example, if I wanted to create a destructuring let, similar to a CL
library I wrote [1], that works like this (hypothetical code):

@dlet Foo(a,b) = Foo(1,2), Dict(:a=>A, :b=>B) = Dict(:a=>3,:b=>4)
(a,b,c,d) # returns (1,2,3,4)
end

then I would run into an even more complicated issue. The main problem
is that the parsing happens before the macro is expanded. Possibly

@myfor i = something begin
...
end

and

@dlet .... begin
...
end

could work, but I need to think about it more and play with ASTs. I will
collect some cases and open an issue. If the price to pay is a single
begin, that's not a big deal.

M-expression macros are awfully hard. If I understand correctly, Dylan
had various types of macros to handle certain cases. [2] I am curious
what the designers of Julia macros thought about these things.

Best,

Tamas

[1] https://github.com/tpapp/let-plus
[2] https://opendylan.org/articles/macro-system/macro-types.html

Mauro

unread,
May 3, 2015, 2:09:14 PM5/3/15
to juli...@googlegroups.com
You're probably much further than I am with this... Anyway, the way
I've scanned for available syntax to be used in a macro is just wrap the
syntax in :( ) and see whether it gives a parser error or not. If not
take the thing it returns apart and do what you want with it. For
instance I use

@traitfn tf1{X, Y; Tr1{X}, Tr1{Y}}(a::X, b::Y) = fun1(a) + fun1(b)

Tamas Papp

unread,
May 4, 2015, 5:59:27 AM5/4/15
to juli...@googlegroups.com
Thanks, this is useful.

I am wondering if there are any sources/discussions I could read on the
design choices of the syntax and semantics of Julia macros.

Papers at http://julialang.org/publications/ say very little about
macros. I found
https://github.com/stevengj/Julia-EuroSciPy14/blob/master/Metaprogramming.ipynb
but even that has only very simple code.

Before I suggest anything, I would like to see what is possible with
more complicated examples and try to write a few of my own: can someone
recommend papers, or packages to study for more complex macros?

Best,

Tamas

Jake Bolewski

unread,
May 4, 2015, 11:48:33 AM5/4/15
to juli...@googlegroups.com
Let over lambda 

Tamas Papp

unread,
May 8, 2015, 2:04:40 AM5/8/15
to juli...@googlegroups.com
I have read LOL previously, but I thought I missed something so I looked
at it again, and I still don't understand what you mean. Is there
something in LOL that is helpful in understanding Julia macros (beyond
general Lisp macrology stuff)?

What motivated the choices in Julia such as

1. not having an equivalent of MACROLET

2. not having symbol macros (which can be quite powerful in avoiding a
code walker), and of course SYMBOL-MACROLET

3. the specific macro hygenie scheme chosen by Julia?

Sorry for asking so many questions, I just want to understand these
things better.

Best,

Tamas


On Mon, May 04 2015, Jake Bolewski <jakebo...@gmail.com> wrote:

> Let over lambda
>
> On Monday, May 4, 2015 at 5:59:27 AM UTC-4, Tamas Papp wrote:
>>
>> Thanks, this is useful.
>>
>> I am wondering if there are any sources/discussions I could read on the
>> design choices of the syntax and semantics of Julia macros.
>>
>> Papers at http://julialang.org/publications/ say very little about
>> macros. I found
>>
>> https://github.com/stevengj/Julia-EuroSciPy14/blob/master/Metaprogramming.ipynb
>> but even that has only very simple code.
>>
>> Before I suggest anything, I would like to see what is possible with
>> more complicated examples and try to write a few of my own: can someone
>> recommend papers, or packages to study for more complex macros?
>>
>> Best,
>>
>> Tamas
>>
>> On Sun, May 03 2015, Mauro <maur...@runbox.com <javascript:>> wrote:
>>
>> > You're probably much further than I am with this... Anyway, the way
>> > I've scanned for available syntax to be used in a macro is just wrap the
>> > syntax in :( ) and see whether it gives a parser error or not. If not
>> > take the thing it returns apart and do what you want with it. For
>> > instance I use
>> >
>> > @traitfn tf1{X, Y; Tr1{X}, Tr1{Y}}(a::X, b::Y) = fun1(a) + fun1(b)
>> >
>> > On Sun, 2015-05-03 at 20:01, Tamas Papp <tkp...@gmail.com <javascript:>>
>> wrote:
>> >> On Sun, May 03 2015, Toivo Henningsson <toiv...@gmail.com <javascript:>>
Reply all
Reply to author
Forward
0 new messages