|
From: | Sebastian Tennant |
Subject: | Re: A macro and an unwanted containing list in the resulting form |
Date: | Thu, 24 May 2007 00:45:54 +0300 |
User-agent: | Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.95 (gnu/linux) |
Quoth Pascal Bourguignon <pjb@informatimago.com>: > Sebastian Tennant <sebyte@smolny.plus.com> writes: >>> Is there any reason to make the argument of build-cond an alist? You >>>could try >>> >>> (defmacro build-cond (&rest conds) >>> (append '(cond) >>> (mapcar '(lambda (each) >>> (cons (list 'equal 'my-var (car each)) (list (cdr >>> each)))) >>> conds))) >>> >>> and then use >>> >>> (build-cond ("hello" . (message "hi")) >>> ("goodbye" . (message "bye")) >> >> The reason for the alist is the clauses are being passed as one of a >> number of arguments to a function call. > > If you get the a-list as argument to a function, then you don't need a > macro to process it! Just write a loop! > > (require 'cl) > > (defun my-function (string clauses) > (loop > for clause in clauses > until (string= string (car clause)) > finally (eval (cdr clause)))) > > (my-function "goodbye" '(("hello" . (message "hi")) > ("goodbye" . (message "bye")))) > Whoa! This isn't LISP! At least it doesn't look like it to me. Where are the parentheses? I suppose I haven't got the first idea how the Common Lisp 'loop' function works...??? Sebastian
[Prev in Thread] | Current Thread | [Next in Thread] |