m4-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: functional programming


From: tuna
Subject: Re: functional programming
Date: Sat, 17 Jan 2009 17:47:12 PST

divert(`-1')dnl there is no chance for escape
changequote(`[',`]')
define([BEGIN],[dnl])
define([END],[dnl])
BEGIN. calc(X)(y)=>`X(...y)'
define([calc],[$1(pushdef([$1],[_$1])define([_$1],[$@,)])])_$1([$@)])
dnl            X( - - - - - - - - - - - - - - - - - - - - - - - - ->\
dnl            -->\                                                 |
dnl               |pushdef(X,_X)                                    |
dnl               +-----------------+                               |
dnl                                 |define(_X),`$@,)'              |
dnl                                 +---------------------+         |
dnl                                                       |_X(...y) |
dnl                                                       +-------->)
END.
divert[]dnl
calc(eval)(1+1)
Define a macro that returns by invoking its anonymous arg$1 expecting the result of collecting arguments
during its redefinition when it would be invoked.
This is currying over arguments on a built-in macro-that accepts-numeric-input. Thus calc() has a type by
means of the operations restricted to it by -jection; invoking it with the resulting collected list as arguments.
Cheers



reply via email to

[Prev in Thread] Current Thread [Next in Thread]