Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

TorgoX (1933)

TorgoX
  sburkeNO@SPAMcpan.org
http://search.cpan.org/~sburke/

"Il est beau comme la retractilité des serres des oiseaux rapaces [...] et surtout, comme la rencontre fortuite sur une table de dissection d'une machine à coudre et d'un parapluie !" -- Lautréamont

Journal of TorgoX (1933)

Wednesday July 05, 2006
04:27 AM

(defmacro f_x ...)

[ #30179 ]
Dear Log,

Today's inane new elisp macro of mine:

(defmacro f_x (&rest Body)
 "Make these expressions a function with 'x' holding its one parameter"
 (list 'function (cons 'lambda (cons (cons 'x nil) Body))))

So this:

(f_x (print "I like pie and %s" x) (* 3.14 x))

is a handy shorthand that expands to this:

(function (lambda (x) (print "I like pie and %s" x) (* 3.14 x)))

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • This just came to me; I stole the idea from the implicitly-declared parameters in Perl 6.

    (defmacro fn (&rest body)
      (let* ((env (make-hash-table :test 'eq))
             (new-body (fn-expand env `(progn ,@body)))
             (parameters '()))
        (maphash #'(lambda (key &optional value)
                     (setq parameters (cons key parameters)))
                 env)