[nem-en] Re: Macro proposal
Elifant
elifantu at mail.ru
Tue Jun 19 11:06:55 CEST 2007
Kamil Skalski пишет:
>> my_func1(arg, another, fun () {
>> my_func2(arg, fun () {
>> ...
>> })
>> })
> You could also use short C#3-like lambdas:
> my_func1(arg, another, x =>
> x + 1
> )
But there is still line with ')'. It isn't that bad, but indentation
syntax is all about replacing
braces by indentation, I think.
>> macro @~~ (call, params ext_args: array[PExpr])
>> match (call)
>> | <[ $name (.. $args) ]> => <[ $name (.. $(args +
>> List.FromArray(ext_args))) ]>
>> | _ => Message.FatalError("There must be function call to the
>> left of ~~ macro")
>
> A little bit shorter:
> macro @~~ (call, params ext_args: list[PExpr]) {
> match (call)
> | <[ $name (.. $args) ]> => <[ $name (.. $(args + ext_args)) ]>
> ...
> }
I tried this, but Nemerle fails to compile 'params' of type 'list'. Maybe my
compiler is too old (I use one from Debian Etch).
> I guess it gives similar functionality to Ruby's blocks:
> foo (a) {
> xx
> }
>
> is passed to function
> foo (a, block) { }
>
> as
>
> foo (a, {xx})
I know and like Ruby. In fact I want this macro in Nemerle because I'm
used to such syntax in Ruby. But Ruby blocks
are more than lambdas with special syntax. For example, 'return'
statement returns from enclosing function, not from
block. I think it is possible to implement blocks in Nemerle but their
behaviour will be too suprising for anyone besides Rubyists :)
More information about the devel-en
mailing list