From: Andreas Yankopolus
Subject: Indirect access of values
Date: 
Message-ID: <m2k6zi5pay.fsf@stubb.local>
Suppose you type the following items into Lisp:
> (setf bar 10)
10
> (setf foo 'bar)
BAR

You can then use foo to display the value of bar:
> (eval foo)
10

Is there a setf-friendly way to access bar through foo? This is for a
shortcut in reading global values from a config file. If each line of
the config file contains:

symbol value

e.g.

*num-inputs* 10

I'm thinking one could load the values with something like:

(do ((line (read-line fp) (read-line fp nil 'eof)))
    ((eql line 'eof))
  (let ((vals (line-2-list line)))
    (setf ???(car vals)??? (cdr vals))))  

where line-2-list parses line and returns a list of the items. I
haven't a clue what should go in place of the question marks. The
global variables would all be initialized to some sane default values
at program startup.

The other options is of course a large case statement that matches
against (car line).

Thanks,

Andreas

From: David Sletten
Subject: Re: Indirect access of values
Date: 
Message-ID: <Fihoc.21074$EH6.19580@twister.socal.rr.com>
Andreas Yankopolus wrote:

> Suppose you type the following items into Lisp:
> 
>>(setf bar 10)
> 
> 10
> 
>>(setf foo 'bar)
> 
> BAR
> 
> You can then use foo to display the value of bar:
> 
>>(eval foo)
> 
> 10
> 
> Is there a setf-friendly way to access bar through foo? This is for a
> shortcut in reading global values from a config file. If each line of
> the config file contains:
> 
> symbol value
> 
> e.g.
> 
> *num-inputs* 10
> 
> I'm thinking one could load the values with something like:
> 
> (do ((line (read-line fp) (read-line fp nil 'eof)))
>     ((eql line 'eof))
>   (let ((vals (line-2-list line)))
>     (setf ???(car vals)??? (cdr vals))))  
> 
> where line-2-list parses line and returns a list of the items. I
> haven't a clue what should go in place of the question marks. The
> global variables would all be initialized to some sane default values
> at program startup.
> 
> The other options is of course a large case statement that matches
> against (car line).
> 
> Thanks,
> 
> Andreas

The old (deprecated) way to 'set' the value of the variable to which FOO 
is referring is SET:
(set foo 9)

bar => 9

This is in distinction to SETQ, which stands for 'SET using QUOTE' or 
something like that:
(set (quote bar) 7) == (setq bar 7)

bar => 7

The more current way to do this is via SYMBOL-VALUE using SETF:
(setf (symbol-value foo) 12)  ==  (setf (symbol-value 'bar) 12)

bar => 12

Notice that FOO is not quoted. (SYMBOL-VALUE FOO) is a reference to the 
'place' that is the value of the symbol (bar) which is stored in FOO.

David Sletten
From: Pascal Costanza
Subject: Re: Indirect access of values
Date: 
Message-ID: <c7sk26$pqn$1@newsreader2.netcologne.de>
Andreas Yankopolus wrote:
> Suppose you type the following items into Lisp:
> 
>>(setf bar 10)
> 
> 10
> 
>>(setf foo 'bar)
> 
> BAR
> 
> You can then use foo to display the value of bar:
> 
>>(eval foo)

(symbol-value foo) is better here. And you can also use this in 
conjunction with setf: (setf (symbol-value foo) 20)


Pascal

-- 
1st European Lisp and Scheme Workshop
June 13 - Oslo, Norway - co-located with ECOOP 2004
http://www.cs.uni-bonn.de/~costanza/lisp-ecoop/
From: Andreas Yankopolus
Subject: Re: Indirect access of values
Date: 
Message-ID: <m27jvh3dip.fsf@stubb.local>
Thanks for pointing out symbol-value. It accomplishes exactly what I
was trying to do.

Cheers,

Andreas