[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Difference between cons and dot
From: |
Arsen Arsenović |
Subject: |
Re: Difference between cons and dot |
Date: |
Sat, 20 Apr 2024 15:35:37 +0200 |
Hi,
Heime <heimeborgia@protonmail.com> writes:
> Am adding an elemnt to an alist using either the cons or dot method.
> Have noticed that with cons I do not need to call list
>
> Thusly
>
> (push (cons kfrz lnum) tema-lugar)
>
> rather than
>
> (push '(cons kfrz lnum) tema-lugar)
>
> But with the dot method I have to use
>
> (push '(kfrz . lnum) tema-lugar)
>
> and not
>
> (push (kfrz . lnum) tema-lugar)
>
> What is the reason for this difference ?
'cons' is a primitive function. (cons a b) produces a cons cell "(a
. b)". "(a . b)" is a value. Hence, 'cons' has to be called. As (a
. b) can't be called, it should be quoted, hence '(a . b).
This is actually not a divergence, really; it's consistent with the rest
of the language.
[NOTE: not sure if I got the nomenclature right.. but the reasoning is
correct: cons has to be called, (a . b) does not.]
Have a lovely day!
--
Arsen Arsenović
signature.asc
Description: PGP signature