[nem-en] Macro proposal

Kamil Skalski kamil.skalski at gmail.com
Tue Jun 19 10:50:26 CEST 2007


2007/6/19, Elifant <elifantu at mail.ru>:
> Hello all.
>
> I just started to learn Nemerle. Thank you for this language, It is
> fantastic :)
> I love indented syntax, but there are many functions which expect
> callbacks. So I need
> to return to syntax with braces:
>
> 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
)

>
> 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)) ]>
         ...
}

>
> Macro name isn't very good but I can't find any good one. :)

Yeah, I would also like to use some better name / operator...

> I propose this macro (or something similar) for adding to Nemerle
> library. Comments are welcome.

I guess it gives similar functionality to Ruby's blocks:

foo (a) {
  xx
}

is passed to function
foo (a, block) { }

as

foo (a, {xx})


-- 
Kamil Skalski
http://nazgul.omega.pl



More information about the devel-en mailing list