Skip to main content
added 62 characters in body
Source Link
Drew
  • 79.1k
  • 10
  • 123
  • 257

+1 for teaching Lisp to 5th graders. And have fun! Lisp, like Logo, is good for kids.


Your question is a bit rambling. (Emacs.SE is not a place for tutorials or discussions - it's really for specific Q & A.)

I recommend that you take a look at the manual An Introduction to Programming in Emacs LispAn Introduction to Programming in Emacs Lisp, by using C-h i and choosing Emacs Lisp Intro. Work your way through it. (Then maybe do likewise with your 5th graders.) You won't regret it.


This is false: "any list must have a function in the first element position".

If you evaluate a list that doesn't have a function as its car then an error is raised. But lists that do not have a function as their car certainly exist. (3) is one such example.


Anyway, the answer to your question is that function list conses up its arguments, with nil as the last cdr. So yes, (list (+ 1 2)) is equivalent to (cons (+ 1 2) ()). It's generally more convenient to write (list a b c) than to write (cons a (cons b (cons c nil))).

It's not about being syntactic sugar. Both list and cons are full-fledged Lisp functions. It's not important how they might be implemented (e.g. in C code).

Your question is a bit rambling. (Emacs.SE is not a place for tutorials or discussions - it's really for specific Q & A.)

I recommend that you take a look at the manual An Introduction to Programming in Emacs Lisp, by using C-h i and choosing Emacs Lisp Intro. Work your way through it. (Then maybe do likewise with your 5th graders.) You won't regret it.


This is false: "any list must have a function in the first element position".

If you evaluate a list that doesn't have a function as its car then an error is raised. But lists that do not have a function as their car certainly exist. (3) is one such example.


Anyway, the answer to your question is that function list conses up its arguments, with nil as the last cdr. So yes, (list (+ 1 2)) is equivalent to (cons (+ 1 2) ()).

It's not about being syntactic sugar. Both list and cons are full-fledged Lisp functions. It's not important how they might be implemented (e.g. in C code).

+1 for teaching Lisp to 5th graders. And have fun! Lisp, like Logo, is good for kids.


Your question is a bit rambling. (Emacs.SE is not a place for tutorials or discussions - it's really for specific Q & A.)

I recommend that you take a look at the manual An Introduction to Programming in Emacs Lisp, by using C-h i and choosing Emacs Lisp Intro. Work your way through it. (Then maybe do likewise with your 5th graders.) You won't regret it.


This is false: "any list must have a function in the first element position".

If you evaluate a list that doesn't have a function as its car then an error is raised. But lists that do not have a function as their car certainly exist. (3) is one such example.


Anyway, the answer to your question is that function list conses up its arguments, with nil as the last cdr. So yes, (list (+ 1 2)) is equivalent to (cons (+ 1 2) ()). It's generally more convenient to write (list a b c) than to write (cons a (cons b (cons c nil))).

It's not about being syntactic sugar. Both list and cons are full-fledged Lisp functions. It's not important how they might be implemented (e.g. in C code).

Source Link
Drew
  • 79.1k
  • 10
  • 123
  • 257

Your question is a bit rambling. (Emacs.SE is not a place for tutorials or discussions - it's really for specific Q & A.)

I recommend that you take a look at the manual An Introduction to Programming in Emacs Lisp, by using C-h i and choosing Emacs Lisp Intro. Work your way through it. (Then maybe do likewise with your 5th graders.) You won't regret it.


This is false: "any list must have a function in the first element position".

If you evaluate a list that doesn't have a function as its car then an error is raised. But lists that do not have a function as their car certainly exist. (3) is one such example.


Anyway, the answer to your question is that function list conses up its arguments, with nil as the last cdr. So yes, (list (+ 1 2)) is equivalent to (cons (+ 1 2) ()).

It's not about being syntactic sugar. Both list and cons are full-fledged Lisp functions. It's not important how they might be implemented (e.g. in C code).