Have a look at this article:

http://picolisp.com/wiki/?evalvsnoneval

Basically, the only difference is that 'set' evaluates its first argument,
while 'setq' does not. In your example,

   (set B 1)

'B' is evaluated (and returns NIL because the symbol 'B' has not yet been
given a value). 'set' than attempts to set NIL to 1, which is not permitted
and PicoLisp complains.

On the other hand, 'setq' does not evaluate its first argument. So PicoLisp
happily sets the value of the symbol 'B' to 1.

Btw, the name 'setq' comes from "set quote(ed value)" :)

As the article mentions, it's all about the trade off between flexibility
(with the evaluating function, eg. 'set') and the convience of not having
to quote your argument (with the unevaluating function, eg. 'setq').


Hope this helps,
Erik



On Dec 26, 2016 8:36 PM, "Bruno Franco" <brunofrancosala...@gmail.com>
wrote:

> I know that they're used to bind a variable to a value, and that they do
> behave differently, but I don't understand the principle behind their
> difference, and I can't predict how they will behave differently from each
> other.
>
> From this little piece:
> : (set B 1)
> !? (set B 1)
> NIL -- Protected symbol
> ?
> : (setq B 1)
> -> 1
>
> I deduce that setq doesn't evaluate its first argument, while set does.
> Why is that?
>
> Thank you for your time.
>

Reply via email to