Re: What is the difference between set and setq?

2016-12-30 Thread Bruno Franco
> This might be a nice thing to add to the documentation too,
> since the function definitions don't mention it.

Sorry, I was completely wrong. The definition of set and setq Do mention
whether the first argument is evaluated or not. I just didn't notice the
quote in the form of the general function.

On Wed, Dec 28, 2016 at 4:35 PM, Bruno Franco 
wrote:

> >The same meaning of "eq" (or "quick") have functions like 'delete' /
> 'delq',
> >'assoc' / 'asoq', 'case' / 'casq' or 'push1' / 'push1q'.
>
> Thank you Alex, that was exactly my next question.
>
> On Tue, Dec 27, 2016 at 9:20 AM, Erik Gustafson <
> erik.d.gustaf...@gmail.com> wrote:
>
>> It is the *function* call overhead, which is relatively expensive. [..]
>>
>>
>> Thanks Alex, this is great. I'll add to the wiki article later today.
>>
>>
>


Re: What is the difference between set and setq?

2016-12-28 Thread Bruno Franco
>The same meaning of "eq" (or "quick") have functions like 'delete' /
'delq',
>'assoc' / 'asoq', 'case' / 'casq' or 'push1' / 'push1q'.

Thank you Alex, that was exactly my next question.

On Tue, Dec 27, 2016 at 9:20 AM, Erik Gustafson 
wrote:

> It is the *function* call overhead, which is relatively expensive. [..]
>
>
> Thanks Alex, this is great. I'll add to the wiki article later today.
>
>


Re: What is the difference between set and setq?

2016-12-27 Thread Erik Gustafson
It is the *function* call overhead, which is relatively expensive. [...]


Thanks Alex, this is great. I'll add to the wiki article later today.


Re: What is the difference between set and setq?

2016-12-27 Thread Alexander Burger
On Tue, Dec 27, 2016 at 08:49:10AM +0100, Alexander Burger wrote:
> > > On Mon, Dec 26, 2016 at 10:25 PM, Erik Gustafson <
> Thanks Erik for the great explanation and the article!

I feel I should also mention that the purpose of

   (setq A 'value)

versus

   (set 'A 'value)

is not at all to avoid some typing. In fact, the overall numbers of characters
is the same ;)


It is the *function* call overhead, which is relatively expensive. As you know,
the quote character is a read macro, so that

   (set 'A 'value)

expands to

   (set (quote . A) (quote . value))

immediately when the expression is read. The evaluation of the arguments to
'set' thus triggers the analysis of the expression (quote . A) followed by the
'quote' call.

- Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: What is the difference between set and setq?

2016-12-26 Thread Alexander Burger
> > On Mon, Dec 26, 2016 at 10:25 PM, Erik Gustafson <
Thanks Erik for the great explanation and the article!

On Mon, Dec 26, 2016 at 11:37:36PM -0500, Bruno Franco wrote:
> This might be a nice thing to add to the documentation too, since the
> function definitions don't mention it.
> difference with set is that setq does

'setq' is one of the prehistoric rocks of the Lisp language (like 'car' and
'cdr'). As you both said, it means "set quoted" or so.

Unfortunately, these old names are often not very consistent.

Consider 'member' versus 'memq'. Despite I got used to spell 'memq' as "mem
quick" in my head, the "q" in fact stems from the 'eq' function in other Lisps
(which is in turn '==' in PicoLisp). As you should know, 'member' uses 'equal'
for comparison (which is '=' in PicoLisp, i.e. a full, deep structure
comparison), while 'memq' uses pointer comparison and is thus considerably
faster.

The same meaning of "eq" (or "quick") have functions like 'delete' / 'delq',
'assoc' / 'asoq', 'case' / 'casq' or 'push1' / 'push1q'.

Keep in mind that speed of execution is only one aspect of pointer equality
operations. The other one is to distinguish between different physical objects,
like 'a' and "a", e.g. to achieve guaranteed locality.

- Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: What is the difference between set and setq?

2016-12-26 Thread Bruno Franco
This might be a nice thing to add to the documentation too, since the
function definitions don't mention it. Maybe something like: "Its only
difference with set is that setq does not evaluate its first argument"

On Mon, Dec 26, 2016 at 11:26 PM, Bruno Franco  wrote:

> Thank you so much Erik! I especially like that you said WHY setq is named
> like that. Its been bugging me for weeks!
>
> On Mon, Dec 26, 2016 at 10:25 PM, Erik Gustafson <
> erik.d.gustaf...@gmail.com> wrote:
>
>> Hahaha I read your post quickly and then wrote a possibly overkill answer.
>>
>> I deduce that setq doesn't evaluate its first argument, while set does.
>>> Why is that?
>>>
>>
>> You've totally got it! So the short answer is flexibility vs convience,
>> nothing deeper than that ;)
>>
>> Cheers!
>>
>>
>>
>


Re: What is the difference between set and setq?

2016-12-26 Thread Bruno Franco
Thank you so much Erik! I especially like that you said WHY setq is named
like that. Its been bugging me for weeks!

On Mon, Dec 26, 2016 at 10:25 PM, Erik Gustafson  wrote:

> Hahaha I read your post quickly and then wrote a possibly overkill answer.
>
> I deduce that setq doesn't evaluate its first argument, while set does.
>> Why is that?
>>
>
> You've totally got it! So the short answer is flexibility vs convience,
> nothing deeper than that ;)
>
> Cheers!
>
>
>


Re: What is the difference between set and setq?

2016-12-26 Thread Erik Gustafson
Hahaha I read your post quickly and then wrote a possibly overkill answer.

I deduce that setq doesn't evaluate its first argument, while set does. Why
> is that?
>

You've totally got it! So the short answer is flexibility vs convience,
nothing deeper than that ;)

Cheers!


Re: What is the difference between set and setq?

2016-12-26 Thread Erik Gustafson
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" 
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.
>