AndreVanDelft / scala

The SubScript extension to the Scala programming language
http://www.subscript-lang.org/
12 stars 1 forks source link

Thoughts on script parameter notations #77

Open AndreVanDelft opened 9 years ago

AndreVanDelft commented 9 years ago

Currently script parameters may be enclosed in parentheses, but a notation with just comma's is also supported:

println("hello")
println, "hello"

the second notation would be useful in case of an implicit conversion with more than 1 parameter (to be implemented using an implicit conversion with a tuple), e.g.,

"(", nws

In a syntax definition could be implicit for parse("(", nws) with nws a switch for "no white space" (before the symbol).

IMO the comma notation would only be good for such implicit script calls. For other purposes, with an explicit name of the called script, it would be clearer to use a Smalltalk-like colon notation:

println: "hello"

If there are multiple parameters, these would be separated by comma's. E.g. a poisson process spawner would be in the old syntax

spawnEvery( 5*minute, [ aScript] )

In the new syntax:

every: 5*minute, spawn: [ aScript ]

or even with a closing tag:

every: 5*minute, spawn: [ aScript ] :end

Such a script could be defined as:

every:spawn:end[T](duration: double, process: Script[T]) = ...

Note that in the definition we would not write the extra colon for the trailing tag, and in case there is only one parameter we would not write a colon at all.

Could the colon notation also support variable argument lists? Probably, but then for the group of arguments the tag would not be repeated. E.g.,

myPrint: "a", "b", "c"

would call

myPrint( args:String* )
AndreVanDelft commented 9 years ago

I am in doubt about

every: 5*minute, spawn: [ aScript ]

I now tend to think the multiplicative expression should be enclosed in parentheses, as in:

every: (5*minute), spawn: [ aScript ]

The reason is that if it were the last parameter, symbols like + would be ambiguous.