Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Lisp Syntax #| ???

11 views
Skip to first unread message

Jim Cheng

unread,
Aug 2, 2000, 3:00:00 AM8/2/00
to
Hi,
I am a new comer to lisp.
Is #| ... #1 used for annotation in Lisp?

for example, the contents between #| and #| are just annotations ?

#|(defstruct node
(x0) ;; after rotation
(y0)
(x1)
(y1)
(line)
) #|

Thanks!

Jim


Barry Margolin

unread,
Aug 2, 2000, 3:00:00 AM8/2/00
to
In article <3988AB66...@yahoo.com>, Jim Cheng <jim...@yahoo.com> wrote:
>Is #| ... #1 used for annotation in Lisp?
>
>for example, the contents between #| and #| are just annotations ?

Yes. The term most computer programmers use (at least in the US) is
"comments".

However, the end is marked with |#, not #|. This is similar to many other
languages that have paired-up comment markers, e.g. /* ... */ in PL/I and
C.

--
Barry Margolin, bar...@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

Christophe Rhodes

unread,
Aug 3, 2000, 3:00:00 AM8/3/00
to
Barry Margolin <bar...@genuity.net> writes:

> In article <3988AB66...@yahoo.com>, Jim Cheng <jim...@yahoo.com> wrote:
> >Is #| ... #1 used for annotation in Lisp?
> >
> >for example, the contents between #| and #| are just annotations ?
>
> Yes. The term most computer programmers use (at least in the US) is
> "comments".
>
> However, the end is marked with |#, not #|. This is similar to many
> other languages that have paired-up comment markers, e.g. /* ... */
> in PL/I and C.

Although the lisp ones (#| ... |#) have the advantage that they nest
properly -- cf. /* /* ... */ */, which is a great advantage when
commenting out large chunks of code -- you don't need to worry about
whether you've got embedded comments.

Christophe

Robert Monfera

unread,
Aug 3, 2000, 3:00:00 AM8/3/00
to
Jim Cheng wrote:

> for example, the contents between #| and #| are just annotations ?

This is how to remember #| ... |# :

# is the strong wall structure that stops the heap of comments from
breaking out of its barriers
| is the inner waterproofing

Robert

Martin Cracauer

unread,
Aug 8, 2000, 3:00:00 AM8/8/00
to
Jim Cheng <jim...@yahoo.com> writes:

>Hi,
> I am a new comer to lisp.

>Is #| ... #1 used for annotation in Lisp?

>for example, the contents between #| and #| are just annotations ?

The real comments in Lisp are to-end-of-liners with ';'

#|...|# is an example of a reader macro in action, using it to
implement multiline comments.

>#|(defstruct node
> (x0) ;; after rotation
> (y0)
> (x1)
> (y1)
> (line)
> ) #|

Temporarily disabling code like this is usually done with a different
reader macro instead:

#+nil
(defstruct
...
(line))

This is usually preferrable to #|...|# since the editor's indentiation
support still knows how to format the disabled code.

Martin
--
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Martin Cracauer <crac...@bik-gmbh.de> http://www.bik-gmbh.de/~cracauer/
FreeBSD - where you want to go. Today. http://www.freebsd.org/

Erik Naggum

unread,
Aug 9, 2000, 3:00:00 AM8/9/00
to
* Martin Cracauer

| The real comments in Lisp are to-end-of-liners with ';'
|
| #|...|# is an example of a reader macro in action, using it to
| implement multiline comments.

You may be surprised, but ; is just a reader macro, too. I fail to
see how you can support "real" in any way. What's unreal about #||#?

| Temporarily disabling code like this is usually done with a
| different reader macro instead:

Some prefer it this way, but I haven't found any statistics that
support the "usually". Where did you find yours?

| This is usually preferrable to #|...|# since the editor's
| indentiation support still knows how to format the disabled code.

See above for "usually". _Your_ preferences are noted, but some
indentation support packages will indent commented code correctly,
in the understanding that you don't comment out text with #| ... |#.
For those cases, use several ;'s at the beginning of the line.

#:Erik
--
If this is not what you expected, please alter your expectations.

Kent M Pitman

unread,
Aug 9, 2000, 3:00:00 AM8/9/00
to
Erik Naggum <er...@naggum.net> writes:

> * Martin Cracauer
> | The real comments in Lisp are to-end-of-liners with ';'
> |
> | #|...|# is an example of a reader macro in action, using it to
> | implement multiline comments.
>
> You may be surprised, but ; is just a reader macro, too. I fail to
> see how you can support "real" in any way. What's unreal about #||#?

I didn't see the original context, but maybe this was partly about the use
of comments to annotate code vs to turn off code. I bet the statistical
norm is to use ";" more for the former and "#|...|#" more for the latter,
though I have no data. Personally, I use ";" for annotation and
"#||...||#" for commenting out code, mostly because double vertical bars
makes Emacs motion commands happier.

> | Temporarily disabling code like this is usually done with a
> | different reader macro instead:
>
> Some prefer it this way, but I haven't found any statistics that
> support the "usually". Where did you find yours?

We could take an informal poll here. I certainly never use #|...|# for
running comments, nor does anyone whose code I've ever read other than
in the occasional isolated situation where they are trying to quickly
annex a .text file until they've had time to process it.

And, of course, the ANSI spec contains non-normative advice that encourages
at least the semicolon comment behavior. The advice about #|...|# is less
direct, but does note the option to nest such comments, hence at least a
possible bias in usage toward using this for code. (Though one could always
use the feature to nest textual comments instead. ;-)

> | This is usually preferrable to #|...|# since the editor's
> | indentiation support still knows how to format the disabled code.
>
> See above for "usually". _Your_ preferences are noted, but some
> indentation support packages will indent commented code correctly,
> in the understanding that you don't comment out text with #| ... |#.
> For those cases, use several ;'s at the beginning of the line.

I find that in general the editor has poor support for formatting #|...|#
owing to numerous editors thinking that # is just an adornment and |...|
is a "stringer" (i.e., syntax like |foo| or "foo") that cannot be nested.
That's why I use #||...||#, so that it will think there are two "stringers",
each ||, and that the code between is not "strung".

Robert Monfera

unread,
Aug 10, 2000, 3:00:00 AM8/10/00
to
Kent M Pitman wrote:

> We could take an informal poll here. I certainly never use #|...|# for
> running comments, nor does anyone whose code I've ever read other than
> in the occasional isolated situation where they are trying to quickly
> annex a .text file until they've had time to process it.

Sometimes it's useful to embed short, tokenized comment this way:

(defmethod foo ((x bar) (y baz))
...)

(defmethod foo #|speed|# ((x specialized-bar) (y baz))
{faster, specialized functions while logic is the same})

(defmethod foo :around #|validation|# (x y)
(assert ...)
...)

(defmethod zot #|interface|# (x &optional y)
(foo x y))

(OK, these should eventually be GF and method attributes implemented
with MOP)

Robert

Martin Cracauer

unread,
Aug 10, 2000, 3:00:00 AM8/10/00
to
Erik Naggum <er...@naggum.net> writes:

>* Martin Cracauer
>| The real comments in Lisp are to-end-of-liners with ';'
>|
>| #|...|# is an example of a reader macro in action, using it to
>| implement multiline comments.

> You may be surprised, but ; is just a reader macro, too. I fail to
> see how you can support "real" in any way. What's unreal about #||#?

We're arguing words here, my intention was to point out that Common
Lisp as a language is powerful enough to even implement multiline
comments, without cluttering up the lowest level of syntax.

>| Temporarily disabling code like this is usually done with a
>| different reader macro instead:

> Some prefer it this way, but I haven't found any statistics that
> support the "usually". Where did you find yours?

No idea. I don't comment my code and don't need comments to
understand other people's code :-)

Seriously, I could review the sources I read in the past, but I think
it's better to agree with you that this is my preference and not
neccecarily everybody else'.

>| This is usually preferrable to #|...|# since the editor's
>| indentiation support still knows how to format the disabled code.

> See above for "usually". _Your_ preferences are noted, but some
> indentation support packages will indent commented code correctly,
> in the understanding that you don't comment out text with #| ... |#.
> For those cases, use several ;'s at the beginning of the line.

Sure. The problem here is that the editor's indentation may only
support you when you decide to use #|...|# either for disabling code
*or* for free-text comments, but not both (of course, you may stiil
use the other one after committing to one, but then you'll have to
indent on your own).

Since there is a seperate item #-... that I can use for code, I
reserve #|...|# for text.

The whole thing is a little nitpicky. ;;;... looks much nicer for
text comments, so I usually just use that.

0 new messages