Re: #;
- From: Rainer Joswig <joswig@xxxxxxx>
- Date: Sun, 30 Dec 2007 15:28:04 +0100
In article <4777a7a3$0$507$5a6aecb4@xxxxxxxxxxxxxxxxx>,
verec <verec@xxxxxxx> wrote:
I just spotted the #; in R6RS and found it a great idea: being
able to specify that ";" should be reserved for actual comments
as opposed to "#;" meant to comment-out code while developing
it, meaning that if I ever forget to clean-up the code once it
works the way I want it to, at least "#;" will stay as a hint
that this is not an explanatory comment, but something I just
forgot to clean-up. Great!
I thought that it ought to be trivial to implement in CL ...
Lisp expressions are not based on lines.
(+ 1 2 #; 3 4
)
What should the result be?
3 or 7 ?
7 I'd say.
... 35 minutes later, I arrived at:
;;; stolen from CLHS:
http://www.lispworks.com/documentation/HyperSpec/Body/f_set__1.htm
(defun my-semicolon-reader (stream char n)
(declare (ignore char n))
;; First swallow the rest of the current input line.
;; End-of-file is acceptable for terminating the comment.
(do () ((char= (read-char stream nil #\Newline t) #\Newline)))
;; Return zero values.
(values))
#.(set-dispatch-macro-character #\# #\; #'my-semicolon-reader)
(defun test-fn ()
(format t "This is line 1 ~%")
(format t "This is line 2 ~%")
(format t "This is line 3 ~%"))
(defun test-fn-2 ()
(format t "This is line 1 ~%")
#; (format t "This is line 2 ~%")
(format t "This is line 3 ~%"))
CL-USER 1 > (test-fn)
This is line 1
This is line 2
This is line 3
nil
CL-USER 2 > (test-fn-2)
This is line 1
This is line 3
nil
So what did I "waste" 35 minutes on?
- got confused about the distinction between
set-macro-character
and set-dispatch-macro-character
- confused again by the difference bewteen
set-dispatch-macro-character
and make-dispatch-macro-character
- confused as to why
CL-USER 3 > (get-macro-character #\;)
system::read-comment
nil
would return a function that the compiler would then
choke on when installed as the function for #;
and found out that set-macro-character wants a function
of TWO arguments whereas set-dispatch-macro-character wants
just a function:
"function---a function designator or nil",
only to show in the example section that this function
ought to take a THIRD argument (called "n" !?!?!). Wandering
into 2.1.4.4 was NOT helpful in seeing this. Only the
example gave the clue away.
- confused as to why I should use #. to install
my code. I think I now guess the purpose of #. but
it is not clear why just issuing a
(set-dispatch-macro-character #\# #\; #'my-semicolon-reader)
without a leading #. would not work when I just *load*
the file
- beginning to get a feel for what this "eval-when" thingie
is meant to be a solution for
And then started to wish there was some tutorial somewhere
that started out by: here's the list of concepts that are
REALLY different in CL that you must positively master before
even thinking writing non toy examples...
On the bright side, having survived all those "put-off" shows
the "magnetic" appeal of CL, which, despites all those documentation
flows and historically preserved quirks still manages to force
me keeping trying :-)
--
JFB
--
http://lispm.dyndns.org/
.
- References:
- #;
- From: verec
- #;
- Prev by Date: Re: RFC: Extending method specializers
- Next by Date: Re: Curses alternative for Lisp?
- Previous by thread: #;
- Next by thread: Re: #;
- Index(es):