-
Notifications
You must be signed in to change notification settings - Fork 50
Partial Block Macros Not Possible #72
Comments
What are the benefits this approach brings to the language? Other thing is how IMO introducing this kind of syntactic sugar to the language at this point will just make a lot harder to implement the language in itself in the future. |
It allows for macros that can extend the head of any block statement, Yes No, I of course wouldn't suggest a separate keyword for that, it's not Going by 'macros can only be implemented in top lvl scope' (not sure 'Macros can be written as one liners, in which case they end at the A second approach could be the one C takes, similar one-liner policy Macros aren't anything new, neither is this problem, other languages Personally I'd go for the second solutions since it's quite clean if 'at this point will just make a lot harder to implement the language in itself in the future.' |
I think that this is not really necessary. I don't see myself in a scenario where this would be useful. Aside from that, I wanted to point out a couple things:
The language isn't indentation based, this isn't python. The language is meant to identify blocks by having a keyword that starts the block ( As for the C approach, I don't have anything to say, except that it breaks the consistency of having |
Not quite, if you go with the following example code macro ifTrue \
dup 1 = \
end You can see that any line that is not supposed to be lexed, |
Other examples: macro repeat \
while dup 0 < do \
1 - \
end 5 repeat
"test\n" 1 1 syscall3 drop
end |
allowing macro max 2dup > if drop else swap drop end end
macro min 2dup < if drop else swap drop end end |
That's as I see right now mostly for ease of the writing code. 1 10 2 for_range
dup print
end drop drop drop
// 1 3 5 7 9 You can do this with partial // in: start end step
macro for_range
// end step (start - step)
rot over -
// end step num
while
// end step (num + step)
over +
// step (num + step) end
rot
// end step (num + step) ((num + step) < end)
if 2dup < do
rot rot true
else
rot rot false
end
do
// no `end` for `while`
end So obviously your code gonna become nightmare if you will just expand this macro by hand every time you want this behaviour (image two nested ranges), and all that is because of impossibility to use partial macros. Yeah, that not complete implementation of python range, because it doesn't work with negative step, but you got the idea. |
'Half' macros like this sadly don't work currently
As far as I can see, the lexer goes through the macro
content and actually evaluates the if end sequence
instead of ignoring it until all macros are expanded.
Correct me if I'm wrong.
The text was updated successfully, but these errors were encountered: