·············@gmail.com (gewoon.iemand) wrote in message news:<···························@posting.google.com>...
> However, I'm running into a problem when I parse quoted lists. I could
> enter '(aVariable 1 2 3) or '(aFunction 1 2 3). When it gets parsed,
> the parser cannot know whether its a variable or a functor. I could
> also enter '(1 2 3 4), and the first element is neither.
'(1 2 3 4) is a short way of writing (quote (1 2 3 4)).
When you evaluate (quote (1 2 3 4)), the result is (1 2 3 4).
> Also, the setq function seems illogical. Suppose I make a function for
> setq. Then the elements get evaluated and they are fed to the setq
> function. But in the case of the example (setq a 1), a is evaluated
> and becomes a value (or throws an error if it's not bound). The setq
> function does not need a value, it needs the variable! I tought of
> making the parser translate setq into set ' , but that feels wrong.
>
> This leads me to the idea that evaluating before the function gets
> executed is wrong. My implementation does not have a problem with set.
> When (set 'a 1) gets evaluated, 'a evaluates into a, which is what the
> set function needs to know in order to do what it's supposed to do
> (namely binding "a" to the value 1). How do other implementations deal
> with this?
You've described correctly what setq and set do. I understand why you
feel the behavior is strange, but really it's as intended. setq
original meant "set-quote". People were tired of writing
(set 'a 1), so they thought of writing (set-quote a 1), and shortened
it to (setq a 1). [Someone else probably knows the precise history
here.]
Granted, there are some subtleties. For instance, the Hyperspec says
set can't change the value of a lexical variable.
By the way, have you thought of implementing Scheme instead of Lisp?
Scheme is designed so that some of these issues don't arise.