I read a snippet about why CAR & CDR were named, and then shortly after, they tried to rename them more sensibly, but it was too late; people had adopted them too deeply. My reasoning is, if the people in charge of LISP made such GLARINGLY poor naming decisions, what else did they screw up -
Common Lisp supports first and rest as alternate names for car and cdr, respectively.
One of the beautiful aspects of lisp is it's usually easy to inspect the environment. The first function in SBCL is defined in list.lisp (as describe will tell you). That source is:
(defun first (list)
"Return the 1st object in a list or NIL if the list is empty."
(car list))
I think car and cdr "won" because of their composability. Want to get the car of the cdr? There's a function for that: cadr. Want to get the car of the cdr of the cdr? caddr. That's a lot nicer than writing (first (rest (rest foo))). The choices of a language community often reflect the experience of the experienced practitioners over the experience of the students of the language. Arguably, the ternary operator in C is difficult to understand (and several modern languages omit it, including golang). Yet, it's incredibly useful for C programmers.
"NIL" and "T" - REALLY? What's that about? "T" and "F" make more sense, surely?
I find it more helpful to think of False and True being: nil and "everything, except nil"
Here again, I'm not trying to apologize for the lisp language designers (I just think they got it right from the worldview of LISt Processing).
It's common to loop over a list until you get to the end of the list. What's another way to talk about the part of the list you haven't processed? rest (or cdr). When do you have no more items in the list? When the rest of the list is empty. If we call that empty list nil and treat it as the only false-y value, the language feels slightly more comfortable and elegant [rather than having to write (not (eq foo '())), we can just write foo].
I can program arduinos, I can do BASH in my sleep, I can do Python (stil learning) but LISP... I see no defined purpose for, apart from "just because", and I am unsure if it's worth a time investment.
It's probably not monetarily useful. It's probably not going to let you solve a programming problem that you couldn't otherwise solve. I found it immensely pleasurable to climb the learning curve, and I believe it's made me a better programmer overall, though I've never shipped a single line of common lisp any farther than my own machines.
(setq 'mary-had-a-little-lamb-p))))
Ummm ... it's really not that hard! Kids these days seem to learn JavaScript in their sleep, and that's basically identical to Lisp.
A few things wrong with your code:
- unbalanced parens, obviously. wtf?
- set and setq need two arguments, not one. What are you trying to set the variable to? mary-had-a-little-lamb-p = ?? The fact you ended the name with -p suggests that it should be true or false, i.e. t or nil.
- you need either (setq the-answer 42) or (set `the-answer 42). If you use "set quote" then you don't quote the name yourself!
Why quote?
Because:
(set `foo `bar)
(set foo 42)
If you now print (or insert into your document, or show a dialog) bar then you'll get 42. Or if you print foo then you'll get "bar".
(setq 'mary-had-a-little-lamb-p))))
Ummm ... it's really not that hard! Kids these days seem to learn JavaScript in their sleep, and that's basically identical to Lisp.
A few things wrong with your code:
- unbalanced parens, obviously. wtf?
- set and setq need two arguments, not one. What are you trying to set the variable to? mary-had-a-little-lamb-p = ?? The fact you ended the name with -p suggests that it should be true or false, i.e. t or nil.
- you need either (setq the-answer 42) or (set `the-answer 42). If you use "set quote" then you don't quote the name yourself!
Why quote?
Because:
(set `foo `bar)
(set foo 42)
If you now print (or insert into your document, or show a dialog) bar then you'll get 42. Or if you print foo then you'll get "bar".
My “code”, lol, was a parody of my knowing almost nothing about lisp. 😁
You mention unbalanced parentheses, but you must understand that is how an unseasoned newcomer sees lisp, and also what it is famed for.
I greatly appreciate your help, once my TV program has finished I’ll give that a go. God bless you