Is there anything that can be done with the “whitespace significant” form of macros, that cannot be done with a normal argument list?
@parallel for i=1:100000
> OK, I hadn't yet used any of those macros... and haven't written anything
> other than the simplest macro myself yet.
> What determines the end of the argument(s) for the form with just
> whitespace syntax?
Newline or ;. I think the white-space rule in macro invocation is
simple: any space is treated as separator. There are other places in
julia where white-space is much more fiddly.
> (As somebody who also has written a number of parsers / compilers, the idea
> of significant whitespace drives me a bit to distraction...)
On Apr 30, 2015, at 9:17 AM, ele...@gmail.com wrote:
On Thursday, April 30, 2015 at 10:40:18 PM UTC+10, Mauro wrote:> OK, I hadn't yet used any of those macros... and haven't written anything
> other than the simplest macro myself yet.
> What determines the end of the argument(s) for the form with just
> whitespace syntax?
Newline or ;. I think the white-space rule in macro invocation is
simple: any space is treated as separator. There are other places in
julia where white-space is much more fiddly.I think it continues past the newline if the final Expr continues past it, for example @parallel gets the whole `for` Expr as an argument no matter how many lines it is.
> (As somebody who also has written a number of parsers / compilers, the idea
> of significant whitespace drives me a bit to distraction...)+1, but in this case the whitespace is not really significant, its just a separator, which is its usual purpose
On Thu, 2015-04-30 at 14:38, Mauro <maur...@runbox.com> wrote:
>> OK, I hadn't yet used any of those macros... and haven't written anything
>> other than the simplest macro myself yet.
>> What determines the end of the argument(s) for the form with just
>> whitespace syntax?
>
> Newline or ;. I think the white-space rule in macro invocation is
> simple: any space is treated as separator.
Well, newline after the end of a fully parsed Julia expression. So this
works:
julia> macro m(args...)
println(args)
end
julia> @m function f()
a = 1
end 5
(:(function f() # none, line 2:
a = 1
end),5)
> There are other places in julia where white-space is much more fiddly.
(At least from a users perspective)
Anyway, I think it works well, so no need for you to worry. I really
like the @ syntax as it clearly alerts the reader that now something
special is going on.
it looks to me like this consequence of having the Julia macros work after the parsing, instead ofworking on the text, like most other languages
Given that this is so different from the way most people would expect coming from other languages, I think it should be pointed out in big red letters in the documentation
On Apr 30, 2015, at 11:58 AM, Isaiah Norton <isaiah...@gmail.com> wrote:it looks to me like this consequence of having the Julia macros work after the parsing, instead ofworking on the text, like most other languagesJulia macros are syntactic like Lisp rather than textual like C. We say as much -- and emphasize the difference -- in the very first paragraph of the metaprogramming section of the manual:
I’d like to, I’m not really a good writer, but I’ll make a good attempt at it! (and hopefully it will get accepted, if I haven’t p*ssed off too many of the core team! ;-) )Scott