The OP posted this challenge:
Name this function:
(lambda (v) (eq 'list (type v)))
The OP said the answer was all about NIL so here is my investigation:
(lambda (v) is only an anonymous function so we can dismiss that
portion of the code. Let's move on to a quick look up of NIL in the
autolisp manual:
NIL
An AutoLISP variable that has not been assigned a value is said to be
nil. This is different from blank, which is considered a character
string, and different from 0, which is a number. So, in addition to
checking a variable for its current value, you can test to determine
if the variable has been assigned a value.
Each variable consumes a small amount of memory, so it is good
programming practice to reuse variable names or set variables to nil
when their values are no longer needed. Setting a variable to nil
releases the memory used to store that variable's value. If you no
longer need the val variable, you can release its value from memory
with the following expression:
command: (setq val nil)
nil
Now that we have at least something on what NIL is we can work our way
through the function (starting from the inside; the lisp interpreter
works from the inside out).
TYPE
http://theswamp.org/~john/avlisp/#typeItems that evaluate to nil (such as unassigned symbols) return nil.
This sentence stuck out at me when reading the help for the function.
Let's move on to EQ and see if my thought thread will pan out.
EQ
http://theswamp.org/~john/avlisp/#eqDetermines whether two expressions are identical
(eq expr1 expr2)
The eq function determines whether expr1 and expr2 are bound to the same object
(by setq, for example).
Arguments
expr1
The expression to be compared.
expr2
The expression to compare with expr1.
Return Values
T if the two expressions are identical, nil otherwise.
So far I am a little concerned as to what the interpreter considers an
`expression'. Let's move on to tackle that vague statement about `it
being all about nil'.
LISTP
http://theswamp.org/~john/avlisp/#listpis supposed to very that an item is a list so let's give it a whirl on
NIL once.
Command: (listp nil)
T
*red flag #1* I remember from way back when that nil was like an empty
list or something so let me try that.
Command: (listp '())
T
Okay, so we know that NIL is like a empty list. Let's see how TYPE
sees those:
Command: (type nil)
nil
Command: (type '())
nil
*gotcha!*
It appears that (type v) will sterilize the empty-list-nil-type
problem.
EDIT #1 (the OP posted a deeper explanation):
All right.
nil is a list and is an atom both.
vl-consp tests if argument is a _valid_ (not empty) list.
(type nil) -> nil
(listp nil) -> t
(vl-consp nil) - nil
EDIT #2:
> potato
If I didn't understand the challenge does that mean I can't? I mean I don't mind that I'm essentially a newbie again when it comes to lisp but...