[Audacity-nyquist] Initializing lists and commenting
A free multi-track audio editor and recorder
Brought to you by:
aosiniao
|
From: Roger B. D. <rb...@cs...> - 2004-12-13 14:44:22
|
David,
Local variables are initialized to NIL, which is the an empty list.
You can assign an empty list to a variable with (setf variable nil). Note
that this does not actually change the list, e.g.:
(setf a '(1 2 3 4)) ; assign the list (1 2 3 4) to variable a
(setf b a) ; assign the same list to variable b
(setf b nil) ; now b has value nil, and a still has the value (1
2 3 4)
As for comments, making semicolon a function would be an incompatible
change, but if you want to comment out a block of code, there are a few
options. My favorite is simply insert a single quote, as in the example of
'(1 2 3 4). A quoted expression returns the expression as is without
evaluation. E.g., without the quote, the expression (1 2 3 4) would try to
evaluate 1 as a function, but with the quote, we just get the list (1 2 3
4). The following shows how to use quoted expressions to avoid evaluation:
'(play (everything)) ;; this is just a list, PLAY is not called as a
function
(play (everything)) ;; this calls PLAY
Note that a quoted expression is not a true comment -- it is a list
expression.
You can also sometimes use double quotes to surround an arbitrary amount of
lisp, turning the whole thing into a multi-line string. This is a bad idea
if the whole thing has embedded strings because you cannot nest quoted
strings, but sometimes it's useful.
-Roger
|