A Python indented Ruby would probably able to do without [ ] but I should think about whether there are some unresolvable ambiguities with that approach. I won't recommend that personally because syntactical spaces introduce bugs. I run into one a few days ago when I moved code around a file and forgot to fix the indentation of a few lines. Luckily this one cost me only five minutes. Many people like Python though.
Overall I like the terseness of
1 to: 5 do: [echo :x]
instead of the more verbose loop(1, 5, lambda x: echo x) # Python
(1..5).each do { |x| echo x } # Ruby
(1..5).each do |x| # Ruby again
echo x
end
But all those : are annoying: they increase the noise/signal ratio. I'd even do without the | | in the multi line Ruby version. I wonder if the compiler could add the : automatically by matching what it sees with the signatures of the defined function. 1 to 5 do [echo :x]
Then, why you need :x and couldn't use x without the : ?
Furthermore, how do I know how the name of the block argument if I didn't write the function. Isn't that an unnecessary coupling between the name chosen by the developer of the library and my code? I probably didn't understand everything is going on here. Edit: it has been explained in another comment in the parent's thread.And there are so many commonly used languages that use { } to define code blocks and [ ] for arrays. I'd stick with the majority for an easier onboarding of developers.
The possibility of defining pseudo keywords thanks to the infix/suffix arguments is great. That's probably anathema in the Python world (only one way of doing things) and also in Go's. It should be acceptable in Ruby's.
I'd prefer something like this
func (n)to(m)do(blk) {
x = n
...
do blk x
...
}
The order of arguments and function names is clear because you read them from left to right without going through two different lists.Is anybody using Spry for real world programs?
func (n)to(m)do(blk) {
x = n
...
do blk x
...
}
This looks ambiguous.
Your function does not have a name, how do you do if another library wants to do something different with the same keywords?
And how do you know when arguments should be evaluated? In your case, "blk" seems to be a set of statements to be executed when "do" is applied, is it right? shall we scan the body to detect if we use "do" on our arguments or does "do" in the signature have a special meaning?Let's see if we can make it work.
func (n)to(m)do(blk) could be syntactic sugar for to:do: funci (n, m, blk). I saw funci in the examples, I didn't investigate if there are other type of function definitions. However, if the definition starts with (arg) it should be easy to map it into a funci. This either solves the problem of name clashes with other libraries, or the problem is unsolved right now.
The block passing is more serious. Maybe we could mark blk in such a way we know it's a block. Ruby uses & as in
func (n)to(m)do(&blk)
Maybe Spry uses & in an incompatible way and I don't like it much anyway. It's developers bending to the compiler, but let's be realistic: we don't want slow compilers.What Ruby also does is having a yield keyword that calls an anonymous block passed at the invocation point of the function (a method in Ruby's world). The block is not declared as argument of the function/method. Maybe:
func (n)to(m)do() { # an empty arg is a block
x = n
...
do x
...
}
1 to 5 do { echo x }
But I think this is getting far away from the way of Spry. {1 to 5 (echo x)}
... which would read into: (loop for x from 1 upto 5 do (echo x))
Note that binding `x` implicitly is bad style, as well as defining terse syntax for every construct.So it's a kind of quoting. I haven't pushed these things further yet, and frankly I am not that heavily into macros unless they are really needed. But obviously AST manipulation is easy in Spry.
_to_do_
n to m do f =
x := n
...What you describe (interesting syntax) is a way to declare argument names and Spry doesn't declare them. That's a discussion in itself of course, but right now it doesn't.
array at: 1 put: 2 ==> array at:put: 1 2
Thus a keyword call is purely syntactic sugar.
I.e. this
is pseudopython's which have comparable punctuation, mostly trading "," for ":" .Being smalltalkish, you also get extra characters when a block is used for control structures, but that saves on the need to have two different syntaxes for single and multi-line/expression lambdas or N syntaxes for blocks and control structures.
How do you see that handled in your ideal language?