help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [External] : Closures - do you understand them well?


From: Drew Adams
Subject: RE: [External] : Closures - do you understand them well?
Date: Thu, 8 Dec 2022 19:35:39 +0000

> When the reader encounters "()" I expect it to construct an empty list.
> That's what I want, so I quote it to get exactly that when that
> expression is evaluated.
> 
> If we do not limit ourselves to Emacs Lisp, the (not trivial) question
> would else be: what is the return value when evaluating an empty list?
> Not trivial because there can be Lisps where an empty list and a boolean
> "false" are different (AFAIR such Lisps exist).

Scheme.

As CLTL2 says at the outset:

https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node9.html#SECTION00522000000000000000

 In Common Lisp, as in most Lisp dialects, the symbol
                 ^^^^^^^^^^^^^^^^^^^^^^^^
 nil is used to represent both the empty list and the
 ``false'' value for Boolean tests.  An empty list may,
 of course, also be written (); this normally denotes
 the same object as nil.... These two notations may be
 used interchangeably as far as the Lisp system is
 concerned.  However, as a matter of style, this book
 uses the notation () when it is desirable to emphasize
 the use of an empty list, and uses the notation nil
 when it is desirable to emphasize the use of the
 Boolean ``false''.  The notation 'nil (note the
 explicit quotation mark) is used to emphasize the use
 of a symbol.  For example:

 (defun three () 3)      ;Emphasize empty parameter list 

 (append '() '()) => ()  ;Emphasize use of empty lists 

 (not nil) => t          ;Emphasize use as Boolean ``false'' 

 (get 'nil 'color)       ;Emphasize use as a symbol

 Any data object other than nil is construed to be Boolean
 ``not false'', that is, ``true''.  The symbol t is
 conventionally used to mean ``true'' when no other value
 is more appropriate.  When a function is said to ``return
 false'' or to ``be false'' in some circumstance, this
 means that it returns nil.  However, when a function is
 said to ``return true'' or to ``be true'' in some
 circumstance, this means that it returns some value other
 than nil, but not necessarily t.

(Note that the second example does what you do.
(Of course at this point in the book there's
been no mention of t and nil/() being
self-evaluating.)

https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node57.html#SECTION00911000000000000000

> Because I don't want to tangent this question I prefer
> to quote the empty list.  What are your reasons to
> prefer to evaluate it and use the result?

No reason not to do that, i.e., no reason to quote it.  

Why not emphasize and take advantage of the fact that 
(always) '() = ()?  No more reason to quote it than
there is (in Elisp, unlike in Common Lisp) to quote a
lambda expression (not speaking about #' "quoting" here).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]