From: Gavin E. Gleason
Subject: Side effects in functions
Date: 
Message-ID: <5vhu9p$j36$1@lynx.unm.edu>
I just started working with LISP about 2 days ago when I decided to
write aprogram that analyses catagorical syllogisms.  I figured that
LISP (from what little I know of it) would be the best man for the job. 
The input is of the type '(all a is b) or '(no a is not b) etc.  The
problem is that I don't know how to make a function alter the external
occurence of a list. eg.

(defun evaluate (input a b not-a not-b)
  (cond ((equal (car input) 'all)
         (cond ((equal (logic-cadddr input) 'not)
                (setq not-a (adjoin 'b not-a ))
                (setq not-b (adjoin 'a not-b )))
               (t
                (setq b (adjoin 'a b)))))
        ((equal (car input) 'no)
         (cond ((equal (logic-caddddr input) 'not)
                (setq b (adjoin 'a b)))
               (t
                (setq not-a (adjoin 'a not-b))
                (setq not-b (adjoin 'b not-a)))))))

I want my operations on the lists a, b, not-a, not-b to effect the
external variable that I'm passing to the function evaluate.  That way I
can evaluate the conclusion later using another function by just looking
at the state of the lists that were passed to the function evaluate.    
        Any help is appreciated.  Thanks.
        
                        Gavin E. Gleason 

-- 
_________________________________________________
Gavin E. Gleason | "If you ain't busy bein' born,
········@swcp.com| You's busy dien'." -somebody
_________________________________________________
From: Barry Margolin
Subject: Re: Side effects in functions
Date: 
Message-ID: <5vi0fr$rfr@pasilla.bbnplanet.com>
In article <············@lynx.unm.edu>,
Gavin E. Gleason <·········@··········@NOSPAM.com> wrote:
>I want my operations on the lists a, b, not-a, not-b to effect the
>external variable that I'm passing to the function evaluate.  That way I

Two suggestions:

1) Wrap your values into structures or class instances, and pass these.
The function can then modify the structure or instance.

2) The function should return the updated values; the caller can then
assign these to the variables if it wants.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
Support the anti-spam movement; see <http://www.cauce.org/>
Please don't send technical questions directly to me, post them to newsgroups.