Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!bbn!jr@bbn.com From: jr@bbn.com (John Robinson) Newsgroups: comp.emacs Subject: Re: apply, mapcar, lack of setenv Summary: try eval, not funcall Keywords: Emacs-lisp, hacking, environment Message-ID: <40844@bbn.COM> Date: 2 Jun 89 17:04:01 GMT References: <62353@yale-celray.yale.UUCP> Sender: news@bbn.COM Reply-To: jr@bbn.com (John Robinson) Distribution: comp Organization: BBN Systems and Technologies Corporation, Cambridge MA Lines: 35 In-reply-to: Duchier-Denys@cs.yale.edu (Denys Duchier) In article <62353@yale-celray.yale.UUCP>, Duchier-Denys@cs (Denys Duchier) writes: >(defun reduce (fun val lst) > (while lst (setq val (funcall fun cal (car lst)) lst (cdr lst))) > val) > >(reduce (function (lambda (x y) (or x y))) (mapcar )) > >(reduce '* 1 '(1 2 3 4 5)) => 120 ;(i.e. 5!) Unfortunately, funcall also works only with functions, not subr's: (reduce 'or nil '(nil t nil)) => error "Invalid function #" Eval, on the other hand, is happy with subrs. Hence, (defun reduce (fun val lst) (while lst (setq val (eval (list fun val (car lst))) lst (cdr lst))) val) then, (reduce 'or nil '(nil t nil)) => t and, to make some examples from the original query, (apply (function (lambda (lst) (eval (cons 'or lst)))) (list (mapcar (function (lambda (elem) (string-match "^TERM=" elem))) process-environment))) => 0 (if TERM is in process-environment), else nil. Now, some might complain that eval is too messy... -- /jr, nee John Robinson What a waste it is to lose one's mind--or not jr@bbn.com or bbn!jr to have a mind. How true that is. -Dan Quayle