In article <·············@WINTERMUTE.eagle> SDS
<···········@cctrading.com> writes:
[...]
operates on the global definition of zz. The question remains: is there
a way to flet a local function conditionally?
What I will be doing for now is:
(let ((zz (if whatever #'(lambda (xx) (1- xx)) #'(lambda (xx) (1+ xx)))))
(funcall zz xx))
I am pretty sure it will work, although it does look kind of ugly.
[...]
You can also use the conditional LET from On_Lisp. The example above would
become
(condlet ((whatever? (zz #'1-))
(t (zz #'1+)))
(funcall zz xx))
If there are several conditional branches, the CONDLET macro looks probably
better than `(let ((zz (cond ...'. The definition follows in the PS.
No hope, though, to build a COND-FLET in a similar way, since the
macro definition relies on the fact that the locals are usual
lexical variables `(lambda (zz) ...'
rthappe
PS: excerpt from onlisp.lisp, available online.
; This code is copyright 1993 by Paul Graham, but anyone who wants
; to use the code in any nonprofit activity, or distribute free
; verbatim copies (including this notice), is encouraged to do so.
(defun mappend (fn &rest lsts)
(apply #'append (apply #'mapcar fn lsts)))
(defmacro condlet (clauses &body body)
(let ((bodfn (gensym))
(vars (mapcar #'(lambda (v) (cons v (gensym)))
(remove-duplicates
(mapcar #'car
(mappend #'cdr clauses))))))
`(labels ((,bodfn ,(mapcar #'car vars)
,@body))
(cond ,@(mapcar #'(lambda (cl)
(condlet-clause vars cl bodfn))
clauses)))))
(defun condlet-clause (vars cl bodfn)
`(,(car cl) (let ,(mapcar #'cdr vars)
(let ,(condlet-binds vars cl)
(,bodfn ,@(mapcar #'cdr vars))))))
(defun condlet-binds (vars cl)
(mapcar #'(lambda (bindform)
(if (consp bindform)
(cons (cdr (assoc (car bindform) vars))
(cdr bindform))))
(cdr cl)))
--
Getretener Quark wird weich und breit. (Tucholsky)