From: Coby
Subject: setf-ing symbols extracted from a list
Date: 
Message-ID: <7t3hc5$p58$1@nnrp1.deja.com>
I am trying to use a loop to bind a list of values to a list of
variable names,
but doing the following:

(defparameter var '(a b c))
(defparameter alias '(eh bee see))
(dotimes (i (length var) i)
   (setf (nth i alias) (nth i var)))

results in alias->(a b c) rather than eh->a, bee->b and see->c the
desired result.

How can i extract the symbols from a list in a way that is setfable?

This is intended to end up in a macro in the spirit of:

(defmacro bind-let-list (let-list global)
   `(dotimes (i (length ,global) i)
       (setf ,(car (nth i let-list)) (nth i ,global))))

to be used as follows:
(defvar *trap* '(a b c))
(bind-let-list ((eh arg1)
                (bee arg2)
                (see arg3)) *trap*)

Thanks for any attention...

Coby

PS Below are extra details and background not essential to
understanding the basic problem:
This is a continuation of my previous problem
(see thread "unbound variables in macro").  I am having success
using the code Rob helped me write:

;;;=====================================================================
;;;  MACRO:          trap-let-list
;;;
;;;  ARGUMENTS:      let-list - list of local variables and
;;;                             initializations
;;;                  global - a global variable to store the values
;;;
;;;  DESCRIPTION:    useful for debugging.  Call this macro at the
;;;                  beginning of a function to extract useful
;;;                  debugging info
;;;
;;;  SIDE EFFECTS:   clobbers the previous value of your global
;;;
;;;  NOTES:          This macro is intended as a temporary insertion
;;;                  into a function one may wish to debug.  By
;;;                  inserting into the beginning of a function,
;;;                  copying and pasting the let list and redefining
;;;                  the function, the code can be run and the local
;;;                  variable values inspected.
;;;
;;;  AUTHOR:         Coby Beck - Sept 29, 1999 with comp.lang.lisp
;;;                  newsgroup help from Rob Warnock.
;;;
;;;
====================================================================

(defmacro trap-let-list (let-list global)
   `(setf ,global (list ,@(mapcar #'car let-list))))


;;example usage:
(defvar *trap*)

(defun foo(arg1 arg2 arg3)
   (let ((eh arg1)
         (bee arg2)
         (see arg3))
      (trap-LET-LIST ((eh arg1)
                      (bee arg2)
                      (see arg3)) *trap*)))

(foo 'a 'b 'c)
==> (a b c)

*trap*
==> (a b c)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

i would now find it useful to have a macro
to setf all of the trapped values to their appropriate local names
so i can do some line by line debugging.  I am having problems
getting something setf-able out of the backquote (though i don't
get that error message)

(bind-let-list ((eh arg1)
                (bee arg2)
                (see arg3)) *trap*)
desired: eh ==> a
         bee==> b
         see==> c

(unlike the simple illustration, there is more to examine than just what
 was passed to the function....)


Sent via Deja.com http://www.deja.com/
Before you buy.

From: H. Tunc Simsek
Subject: Re: setf-ing symbols extracted from a list
Date: 
Message-ID: <37F5A584.B264AEDB@EECS.Berkeley.Edu>
I think you could use SYMBOL-VALUE or just SET:

(set (nth i alias) (nth i var))

should do it.

Coby wrote:
> 
> I am trying to use a loop to bind a list of values to a list of
> variable names,
> but doing the following:
> 
> (defparameter var '(a b c))
> (defparameter alias '(eh bee see))
> (dotimes (i (length var) i)
>    (setf (nth i alias) (nth i var)))
> 
> results in alias->(a b c) rather than eh->a, bee->b and see->c the
> desired result.
> 
> How can i extract the symbols from a list in a way that is setfable?
From: Samir Barjoud
Subject: Re: setf-ing symbols extracted from a list
Date: 
Message-ID: <wkr9jemkd6.fsf@mindspring.com>
Coby <····@my-deja.com> writes:
> [...]
> i would now find it useful to have a macro
> to setf all of the trapped values to their appropriate local names
> so i can do some line by line debugging.  
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> [...]

Learn to use your LISP implementation's debugger.  Then see if you
still have a need for this macro.

Also, the dynamic quality of LISP lets you modify what your code does
without modifying the source code.  A language like C cannot.  That
is, if a running program is seen as an IC (integrated circuit), C only
lets you modify the input voltage, while LISP lets you modify that
along with the circuit itself.  

So whenever you can, don't modify the source code for temporary
debugging, modify the running image.  TRACE, UNTRACE, STEP, BREAK, and
friends exist for that purpose.  For your situation (needing to see
the values after the execution of the bindings of a LET form), you
could slip a BREAK after the bindings.

e.g.

(let ((a 1)
      (b 2))
  (break)
  ...)      


Exercise for the readers: Do the above (break on entry to the body of
a let form) without modifying any source code.

-- 
Samir Barjoud
·····@mindspring.com
From: Coby
Subject: Re: setf-ing symbols extracted from a list
Date: 
Message-ID: <7t6jgj$m3r$1@nnrp1.deja.com>
In article <··············@mindspring.com>,
  Samir Barjoud <·····@mindspring.com> wrote:
> Coby <····@my-deja.com> writes:
> > [...]
> > i would now find it useful to have a macro
> > to setf all of the trapped values to their appropriate local names
> > so i can do some line by line debugging.
>   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > [...]
>
> Learn to use your LISP implementation's debugger.  Then see if you
> still have a need for this macro.
>

not an unreasonable suggestion...

but having run into this here, i don't like not knowing how to do what
seems a fundamental thing and just the kind of thing lisp is great for
(see subject).

but i see the simple answer 'symbol-value' in another reply...


Sent via Deja.com http://www.deja.com/
Before you buy.
From: Shin
Subject: Re: setf-ing symbols extracted from a list
Date: 
Message-ID: <37f5fe83.9853883@news.iddeo.es>
On Fri, 01 Oct 1999 23:50:33 GMT, Coby <····@my-deja.com> wrote:

: I am trying to use a loop to bind a list of values to a list of
: variable names,
: but doing the following:
: 
: (defparameter var '(a b c))
: (defparameter alias '(eh bee see))
: (dotimes (i (length var) i)
:    (setf (nth i alias) (nth i var)))
: 
: results in alias->(a b c) rather than eh->a, bee->b and see->c the
: desired result.
: 
: How can i extract the symbols from a list in a way that is setfable?

SYMBOL-VALUE could be helpful:

  (defparameter var '(a b c))
  (defparameter alias '(eh bee see))
  (dotimes (i (length var) i)
     (setf (symbol-value (nth i alias)) (nth i var)))

Here is how it works:

  Corman Lisp 1.3  Copyright (c) 1999 Roger Corman. All rights reserved.
  * (defparameter var '(a b c))
  VAR
  * (defparameter alias '(eh bee see))
  ALIAS
  * (dotimes (i (length var) i) (setf (symbol-value (nth i alias)) (nth i var)))
  3
  * var
  (A B C)
  * alias
  (EH BEE SEE)
  * eh 
  A
  * bee
  B
  * see
  C
  *

Hope this helps,

-- Shin
From: David D. Smith
Subject: Re: setf-ing symbols extracted from a list
Date: 
Message-ID: <dds-0410991530060001@p088.bit-net.com>
In article <············@nnrp1.deja.com>, Coby <····@my-deja.com> wrote:

> I am trying to use a loop to bind a list of values to a list of
> variable names,
> but doing the following:
...
> How can i extract the symbols from a list in a way that is setfable?
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> 
> i would now find it useful to have a macro
> to setf all of the trapped values to their appropriate local names
> so i can do some line by line debugging.  I am having problems
> getting something setf-able out of the backquote (though i don't
> get that error message)
> 
> (bind-let-list ((eh arg1)
>                 (bee arg2)
>                 (see arg3)) *trap*)
> desired: eh ==> a
>          bee==> b
>          see==> c

(defmacro let-with-capture (bindings capture-place &body body)
  `(let ,bindings
     (setf ,capture-place
           (list ,@(mapcar #'(lambda (binding)
                               `(list ',(car binding) ,(car binding)))
                           bindings)))
     . ,body))

(macroexpand '
(let-with-capture ((a 1)
                   (b 2)
                   (c 3))
                  (car z)
  (frob a b c))
) =>

(LET ((A 1) (B 2) (C 3))
  (SETF (CAR Z)
        (LIST (LIST 'A A) (LIST 'B B) (LIST 'C C)))
  (FROB A B C))

(let ((z (list nil)))
  (flet ((frob (x y z)))
    (let-with-capture ((a 1)
                       (b 2)
                       (c 3))
                      (car z)
      (frob a b c)))
  (car z))
=> ((A 1) (B 2) (C 3))