Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!cbosgd!gatech!seismo!utah-cs!hucka From: hucka@utah-cs.UUCP (Michael Hucka) Newsgroups: net.lang.lisp Subject: Re: programming trick Message-ID: <3699@utah-cs.UUCP> Date: Sat, 1-Mar-86 12:26:00 EST Article-I.D.: utah-cs.3699 Posted: Sat Mar 1 12:26:00 1986 Date-Received: Sun, 2-Mar-86 19:14:31 EST References: <136@cui.UUCP> Reply-To: hucka@utah-cs.UUCP (Michael Hucka) Organization: VCIS Research Group Lines: 29 In article <136@cui.UUCP> manuel@cui.UUCP (James Stewart) writes: > I've often run into the problem of wanting to apply a function to > every element of a list, but been stuck because the function takes > more than one argument. As a simple example: > > (defun F (x y) > (+ x y)) > > (setq L '(2 4 6 8)) > > How do we add 10 to each element of L? > > [examples and more discussion . . .] As an alternative, you could also do the following (assumine "L" and "F" are already defined): (let ((arg2 10)) (mapcar #'(lambda (arg1) (F arg1 arg2)) L)) Whether this works correctly may depend on the scoping aspects of the dialect of Lisp you are using. I believe this code is fairly transparent, though others may disagree with me . . . . Mike -- ........................................................................... :::::: Mike Hucka {ihnp4 decvax}!utah-cs!hucka, hucka@utah-cs.ARPA :::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::