From: ·······@LoyalistC.ON.CA
Subject: A definition for 'foreach'
Date: 
Message-ID: <se382868.001@LoyalistC.ON.CA>
Item Type:  Note


  I've just implemented a 'foreach' function in the lisp
interpreter I'm writing.  It is a function in AutoLISP that
I used to use a lot ( I once taught AutoCAD to design
subdivisions ) But there is no reference to a 'foreach'
function in the XLISP manual.  Is this a common lisp
function?

        ( foreach <name> <list> <expr> ... )

  i.e. given the following expressions....
        ( setq y 0.0 )
        ( foreach x ( list 1 2 3 ) ( + y x ) ( / y x ) )

        I've implemented it so that it evaluates expressions
  left to right for all members of the list...
        ( setq x 1 ) ( + y x )
        ( setq x 2 ) ( + y x )
        ( setq x 3 ) ( + y x )
        ( setq x 1 ) ( / y x )
        ( setq x 2 ) ( / y x )
        ( setq x 3 ) ( / y x )

  however it could also be iterated thusly...
        ( setq x 1 ) ( + y x )
        ( setq x 1 ) ( / y x )
        ( setq x 2 ) ( + y x )
        ( setq x 2 ) ( / y x )
        ( setq x 3 ) ( + y x )
        ( setq x 3 ) ( / y x )

  I think this is unlikely, but it's possible...
        ( setq x 1 ) ( + y x ) ( / y x )
        ( setq x 2 ) ( + y x ) ( / y x )
        ( setq x 3 ) ( + y x ) ( / y x )

  either way ( / y x ) is the last evaluation, but the order
is different.

  Can anyone help me here?  I'd like to know if there is
a definition for this somewhere, but I'm also like to hear
any logical arguments for one way of the other.  It seems
to me that consistency is the only criteria, but I'd hate
to discover later on that I've overlooked something.

                                Rick
Rick Graham                                the Binary Workshop
·······@loyalistc.on.ca  Data:(613)476-4898  Fax:(613)476-1516