Immanuel Litzroth wrote:
>
> I seem to be unable to find the logic behind
That's your problem right there. Why are you expecting this to be
logical? :-)
>
> (setq x '(1 2))
> (nconc x '(3 4))
> x evaluates to (1 2 3 4)
>
> BUT
>
> (setq x nil)
> (nconc x '(3 4)) -> evaluates to (3 4)
> x evaluates to nil
>
> I wouldn't mind some enlightenment
nconc potentially does two things: it returns a value, and it *maybe*
has a side affect. The side affect only occurs if you are operating on
a cons cell. Nil is not a cons cell.
i.e. (consp nil) -> NIL
so no side affect occurs in doing (setq x nil) (nconc x '(1 2)) because
the value of x is not a cons cell. Simple huh?
Note that this is similar to rplacd. (rplacd x '(1 2)) when x is NIL is
an error.