Closed stugol closed 8 years ago
Cough, cough: #14 - all in place :-)
Fast recap (but check #14 out, consider it docs)
say [1, 12, 14].select(~.> 10).map(~.* 2).map(~.to-s)
say [1, 12, 14].select(~> _1 > 10).map(~> (_1 * 2).to-s)
-- or if you prefer
say [1, 12, 14]
.select ~> _1 > 10
.map ~> (_1 * 2).to-s
As you see the only gotcha for the ~.
notation is that no parentheses can go before it (resulting in a additional map in the first case). I'll look into if I can improve that without syntax-clashes.
The last example would be nicer if it worked with indentation, probably should add lenience for that.
Your suggested @n
instead of _n
might be better also. Of course %n
would parallel "fresh var" in macros (provided it turns out to be impossible to re-work).
Hmm, this reminded me of another idea - I'll put that in #21.
I would prefer @n
or %n
. _n
is just....ugly.
Yes, indentation would be nice.
Looking at it I feel your auto-parametrization naming suggestions are a definite go. Don't know which one just yet. Will be changed as soon as that is clear.
I think @
makes the most sense.
@n
confuses the relation to membership, these are args, so I think it's better to skip to not convey the wrong idea about fragments.%n
is good. The common hassle I've come across is that you often use these implicit param vars in string interpolation, and then it forms a macro-delimiter unless spaced: say "foo {%1}"
I like the %n style, so, some alternatives:
{% ... %}
- I would like something else anyway.{% if foo %}
, {%if foo%}
%n
over {%...
One solution don't necessarily eliminate also another.
Require macro delimiters to be spaced from content
This. We need to enforce some spacing in the language, else we'll never get anything done. See #57.
Also, while %var
is often used for "fresh variables" in macros, they are never numeric, so there is no conflict.
%n
variation implemented. The prior syntax, _n
, will be kept for a while for real life comparison, but will likely be dropped soon.
Consider the following Ruby example:
Wouldn't it be better phrased like this?
In other words, for any given call
x.y
, we can omit thex
, whereupon the first argument to the block is inserted.Alternatively, have implicit block arguments:
The block is assumed to have sufficient arguments. For example, a block containing a reference to
@4
is assumed to have the signature|@1,@2,@3,@4|
. Alternatively, we could use%
or&
.