[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
m4_curry [was: naming m4_transform]
From: |
Eric Blake |
Subject: |
m4_curry [was: naming m4_transform] |
Date: |
Tue, 14 Oct 2008 23:04:57 -0600 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.17) Gecko/20080914 Thunderbird/2.0.0.17 Mnenhy/0.7.5.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Eric Blake on 10/14/2008 5:31 PM:
> But m4 doesn't make it easy to write anonymous functions. By making
> m4_map_args supply the ( and ) around a single argument, I no longer have a
> way
> to inject $2 and $3 into the mapping function, at least, not without some
> inefficiencies. I've thought about something like this (untested, and I'm
> not
> even sure I'm using the best naming convention):
I double checked wikipedia, and this is the right name:
http://en.wikipedia.org/wiki/Currying
>
> # m4_curry(MACRO, ARG...)
> # -----------------------
> # Can be used as a currying macro - the expansion of this macro expects
> # to be expanded as another macro that takes one argument, which is then
> # appended to the list of ARGs and passed to the invocation of MACRO.
> # For example,
> # m4_curry([m4_do], [1], [2])([3])
> # is identical to
> # m4_do([1], [2], [3])
> m4_define([m4_curry], [$1(m4_shift($@), _$0])
> m4_define([_m4_curry], [[$1])])
and I got it right - subsequent testing confirmed that what I doodled in
the email is the right implementation!
m4_curry([m4_curry], [m4_reverse], [1])([2])([3])
=> 3, 2, 1
so I'll be adding m4_curry to m4sugar, whether or not it ends up making a
more efficient alternative to autoconf's use of m4_foreach_w. I just have
to finish the testsuite addition and post the patch for review first.
- --
Don't work too hard, make some time for fun as well!
Eric Blake address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkj1efkACgkQ84KuGfSFAYDlgACePnWmmjOeGjioV5BrX6OBl/N7
qxYAmwbE4YZ+TeLyRV6n3kP6hrTG1+tW
=9H9v
-----END PGP SIGNATURE-----