[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [plt-scheme] embarrasing question

At 2:38 PM +1000 5/6/02, Chris Wright wrote:
>I have a list of symbols and functions that I want to populate into a
>hash-table. Some of them are "builtins" (+ - * ) etc etc, but other will be
>I'm trying to do this:
>(for-each (lambda (sym fn)
>                 (hash-table-put! *function-table* sym fn))
>     '(+ - blurp) '(+ - (lambda (x) (+ x 1))))
>with the idea being, obviously, storing the procedure + under the key +, and
>the proc to add one to a number under the key blurp.
>Equally obviously, it doesn't work. What gets stored under the key '+ is the
>symbol '+, not the (symbol->function '+)   .... that's probably a horrible
>lisp-scheme mean-nothing-at-all-hybrid expression! But you know what I mean.
>blurp and the function stored under blurp work fine.
>So, what's the best way to do this? I could store (lambda (lst) (apply +
>lst)) under '+, but I'd just like to be able to say + and get the same

You're having trouble with the meaning of quote.  Well, maybe.  When 
the quote appears before a symbol, it instructs scheme to produce the 
symbol, rather than the thing the symbol refers to.  So if I type "q" 
at the prompt, mzscheme might tell me that q is an unbound variable. 
However, if i type "'q" at the prompt, mzscheme happily produces the 
symbol q.

Well, that's all fine and well, but what if I want to create lists of 
symbols? I might get mighty tired of expressions like "(list 'a 'x 'e 
'f)", or whatever.  So, the designers of scheme opted to extend the 
functionality of quote to have a meaning when appearing before lists, 
as well as before symbols.

However, rather than getting into it, let me encourage you to try 
writing this program without using quote in any position other than 
directly before a symbol.  It's not hard, and I think you'll probably 
figure out what's going on faster than I can accurately explain it.

Hope this helps,