Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!mcvax!ukc!warwick!csuwn From: csuwn@cu.warwick.ac.uk (Max) Newsgroups: comp.emacs Subject: apply, mapcar, lack of setenv Keywords: Emacs-lisp, hacking, environment Message-ID: Date: 2 Jun 89 03:14:13 GMT Sender: csuwn@warwick.ac.uk Distribution: comp Organization: Computing Services, Warwick University, UK Lines: 83 I have just started working with emacs-lisp having some exprience with Franz Lisp. Without the manuals finding out about functions and variables is a long boring process of searching the respective entire completions, or other standard libries. So far all has gone well, I found out how to create processes, and set sentinels to watch over them. However in some cases some things seem not to work as expected - or infact are not included in emacs. 1: Apply, and mapcar I frequently want to do the following; (apply 'or (mapcar 'function list)) where function returns t or nil. Problem: Apply dosent know about the function or. Solution: (cond ((<= 1 (apply '+ (mapcar 'nfunction list))) t) (t nil)) Where nfunction returns 1 or 0 instead of t or nil respectively. Is there a more elegant solution, or am I perhaps missing something. Also why no lambda function in emacs (is it that hard to implement), as its use with mapcar makes life so much easier. (I know e-lisp is not supposed to be like lisp - but old habits die hard.) 2: setenv I was writing some code - and I needed to change the environment of emacs just before starting a new sub-process. I found the function getenv - but the partner setenv just did not seem to exist!! A quick perusal of the variables gave me process-environment - a list of environment strings which will be used by subprocesses. It seemed silly not to have a setenv so I wrote one myself. Notice how the apply/mapcar/or/lambda function makes life so much harder! I would appreciate knowledgable insights into modifications to make the code more elegant. ;;------ Cut here 8< -------------------------------------------------- (defun setenv (name new) (cond ((<= 1 (apply '+ (mapcar 'env-entry process-environment))) ;;The process-environment list contains the name - therefore ;;change it to the new value (setq proccess-environment (mapcar 'change-env process-environment))) (t ;;Otherwise just append the new setting to the front of the list. (setq process-environment (append (list (format "%s=%s" name new)) process-environment))))) (defun change-env (str) ;;Return the new setting of the environment if str contains the ;;old setting, otherwise just returning str. (cond ((= 1 (env-entry str)) (format "%s=%s" name new)) (t str))) (defun env-entry (entry) ;;Does entry contain the environment variable name? ;;Return 1 if it does - 0 otherwise (let ((match (string-match (format "%s=" name) entry))) (cond ((null match) 0) ((= match 0) 1) (t 0)))) ;;---------------------------------------------------------------------- Thanks for your time, -- NAME : H J "Max" Thompson - So called for I Max And Xian. SNAIL: Department Of Computer Science, Warwick University, CV4 7AL, ENGLAND. JANET: max@cs.warwick.ac.uk UUCP: {uunet,mcvax}!ukc!warwick!max JOKE : "Waiter there's a fly in my soup!" "Sir, Its a feature not a bug!"