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

S-expression comments

139 views
Skip to first unread message

hans

unread,
Apr 4, 2012, 3:25:03 PM4/4/12
to
I would like to create a reader macro like the scheme #; to comment
out a form.

So far my function does only read the form, but not ignore it as I
would.

(set-dispatch-macro-character
#\# #\;
(lambda (stream c n)
(declare (ignore c n))
(read stream)))

(+ 1 #;(* 2 3) 4) -reads-> (+ 1 4) -evals-> 5
;from http://srfi.schemers.org/srfi-62/srfi-62.html

thanks for helping

Barry Margolin

unread,
Apr 4, 2012, 4:42:36 PM4/4/12
to
In article
<f762a9d3-c881-4585...@do4g2000vbb.googlegroups.com>,
A macro character expands into whatever the function returns. If you
want it to be ignored, it should return 0 values, i.e. it should end
with (values).

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Ralph Schleicher

unread,
Apr 6, 2012, 12:50:44 AM4/6/12
to
hans <schatze...@gmail.com> writes:

> I would like to create a reader macro like the scheme #; to comment
> out a form.

Have you ever considered using '#-(and)' or '#+(or)'?

(+ 1 #-(and)(* 2 3) 4)
==> 5
(+ 1 #+(or)(* 2 3) 4)
==> 5

--
Ralph

Elias Mårtenson

unread,
Apr 6, 2012, 1:56:06 AM4/6/12
to
In case you don't like the extra parentheses, I prefer using:

#+nil(form to ignore)

instead.

Mirko Vukovic

unread,
Apr 6, 2012, 10:47:56 AM4/6/12
to
e

On Friday, April 6, 2012 1:56:06 AM UTC-4, Elias Mårtenson wrote:
> On Friday, 6 April 2012 12:50:44 UTC+8, Ralph Schleicher wrote:
> > hans <email> writes:
> >
> > > I would like to create a reader macro like the scheme #; to comment
> > > out a form.
> >
> > Have you ever considered using '#-(and)' or '#+(or)'?
> >
> > (+ 1 #-(and)(* 2 3) 4)
> > ==> 5
> > (+ 1 #+(or)(* 2 3) 4)
> > ==> 5
>
> In case you don't like the extra parentheses, I prefer using:
>
> #+nil(form to ignore)
>
> instead.

Neat!

Thanks,

Mirko

Pascal Costanza

unread,
Apr 6, 2012, 2:44:00 PM4/6/12
to
#-(and) and #+(or) are unintuitive, IMHO.


Pascal


--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
The views expressed are my own, and not those of my employer.

Pascal Costanza

unread,
Apr 6, 2012, 2:44:40 PM4/6/12
to
Theoretically, NIL can be on *features*, so this is actually not a good
idea.

Frode V. Fjeld

unread,
Apr 6, 2012, 3:15:16 PM4/6/12
to
Pascal Costanza <p...@p-cos.net> writes:

> Theoretically, NIL can be on *features*, so this is actually not a
> good idea.

I tend to use #+ignore, which also could theoretically be on
*features*. But if I ever find it there, I'll find a way to deal with
it.

--
Frode V. Fjeld

Pascal J. Bourguignon

unread,
Apr 6, 2012, 3:23:23 PM4/6/12
to
In your private code you do as you wish, but in a published library, it
would be better to use #+(and) and #+nil or #+ignore. Quicklisp should
have a function to report the feature expressions used in a given
library.


--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.

Frode V. Fjeld

unread,
Apr 6, 2012, 3:39:16 PM4/6/12
to
"Pascal J. Bourguignon" <p...@informatimago.com> writes:

> In your private code you do as you wish, but in a published library, it
> would be better to use #+(and) [than] #+nil or #+ignore.

I agree, but I don't think there's often use for sexpr comments in
published code.

--
Frode V. Fjeld

Kaz Kylheku

unread,
Apr 6, 2012, 6:13:59 PM4/6/12
to
On 2012-04-06, Pascal Costanza <p...@p-cos.net> wrote:
> On 06/04/2012 07:56, Elias Mårtenson wrote:
>> In case you don't like the extra parentheses, I prefer using:
>>
>> #+nil(form to ignore)
>>
>> instead.
>
> Theoretically, NIL can be on *features*, so this is actually not a good
> idea.

Did New Implementation of Lisp have *features* and these reader macros, and if
so, did it nave nil in *features*?

Barry Margolin

unread,
Apr 6, 2012, 7:53:04 PM4/6/12
to
In article <201204061...@kylheku.com>,
I think the answer was yes to both -- NIL was the early testbed of most
of the ideas in CL.

Note that #+nil actually tests whether :NIL is in *features*. You could
use #+cl:nil(form to ignore) to test for NIL, which is unlikely to be on
*features*.

Robert Uhl

unread,
Apr 6, 2012, 8:16:21 PM4/6/12
to
Is this a learning exercise or for use? Because if all you want to do
is _use_ such a macro, you could just use #|:

cl-user> (+ 1 #|(* 2 3)|# 4)
5

--
Robert A. Uhl

Mirko Vukovic

unread,
Apr 6, 2012, 11:29:41 PM4/6/12
to
I would find something like #+nil easier.

Even though with matching parenthesis navigation #| ... |# is not too hard either.

Mirko

Elias Mårtenson

unread,
Apr 7, 2012, 12:14:49 PM4/7/12
to
On Saturday, 7 April 2012 02:44:40 UTC+8, Pascal Costanza wrote:
> On 06/04/2012 07:56, Elias Mårtenson wrote:
> > On Friday, 6 April 2012 12:50:44 UTC+8, Ralph Schleicher wrote:
> >> hans<schatze...@gmail.com> writes:
> >>
> >>> I would like to create a reader macro like the scheme #; to comment
> >>> out a form.
> >>
> >> Have you ever considered using '#-(and)' or '#+(or)'?
> >>
> >> (+ 1 #-(and)(* 2 3) 4)
> >> ==> 5
> >> (+ 1 #+(or)(* 2 3) 4)
> >> ==> 5
> >
> > In case you don't like the extra parentheses, I prefer using:
> >
> > #+nil(form to ignore)
> >
> > instead.
>
> Theoretically, NIL can be on *features*, so this is actually not a good
> idea.

I think I'm willing to take that risk. :-)

ajventi

unread,
Apr 7, 2012, 10:17:08 PM4/7/12
to
Hash pipe #|(...)|# is the proper inline comment. For the sake of other people possibly reading your code you save them the effort of figuring out some other tomfoolery.

Though I'd say the *feature* suggestion would be best to push your own symbol onto *features* and use it.

(pushnew *features* :mypkg-ignore)

Then use #+mypkg-ignore(...)

Barry Margolin

unread,
Apr 7, 2012, 10:44:39 PM4/7/12
to
In article
<12909572.2760.1333851428199.JavaMail.geo-discussion-forums@vbsf4>,
That should be #-mypkg-ignore, of course.

Tim Bradshaw

unread,
Apr 8, 2012, 9:07:18 AM4/8/12
to
"Frode V. Fjeld" <fro...@gmail.com> wrote:


> I tend to use #+ignore, which also could theoretically be on
> *features*. But if I ever find it there, I'll find a way to deal with
> it.

I used to use #+never, but in any case it ought to be easy to agree that
some set of things would never be in the list. Given NIL presumably does
not run on anything that exists or is emulated even #+nil should be ok.

Relatedly, does anyone know of any tool which lets you publicly annotate
web pages? there must be such, and there were, but they seem not to exist
now? I have greasemonkey things which I use to keep glosses on things like
the hyperspec but obviously that is only useful for me.

Zach Beane

unread,
Apr 8, 2012, 9:09:51 AM4/8/12
to
Tim Bradshaw <t...@tfeb.org> writes:

> Relatedly, does anyone know of any tool which lets you publicly annotate
> web pages? there must be such, and there were, but they seem not to exist
> now? I have greasemonkey things which I use to keep glosses on things like
> the hyperspec but obviously that is only useful for me.

The original Mosaic had website annotation as a basic feature, it was
pretty handy.

http://stix.to/ used to do that and it is (was?) a Lisp-powered startup,
but I can't tell from the front page if that's what it still does.

Zach

ajventi

unread,
Apr 8, 2012, 9:46:02 AM4/8/12
to

> >
> > (pushnew *features* :mypkg-ignore)
> >
> > Then use #+mypkg-ignore(...)
>
> That should be #-mypkg-ignore, of course.
>
> --
> Barry Margolin, bar...@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***



Doh! Thanks.

Tim Bradshaw

unread,
Apr 8, 2012, 11:07:09 AM4/8/12
to
On 2012-04-08 14:09:51 +0100, Zach Beane said:

> http://stix.to/ used to do that and it is (was?) a Lisp-powered startup,
> but I can't tell from the front page if that's what it still does.

Neither could I. I'd be hesitant to rely on something like that though
because either it will suddenly all vanish or you'll find everything
you've ever written owned by google or facebook or someone. I realise
most people worry about that less than me ("here, google, have all my
mail, my address book and diary entries because I really want you to
data mine me" - and people said *Unix* was "a moment of convenience, a
lifetime of regret").

Pascal J. Bourguignon

unread,
Apr 8, 2012, 4:43:09 PM4/8/12
to
Of course.

You can always write it yourself and run it on your own computers.

Pascal J. Bourguignon

unread,
Apr 8, 2012, 4:47:58 PM4/8/12
to
"Pascal J. Bourguignon" <p...@informatimago.com> writes:

> Tim Bradshaw <t...@tfeb.org> writes:
>
>> On 2012-04-08 14:09:51 +0100, Zach Beane said:
>>
>>> http://stix.to/ used to do that and it is (was?) a Lisp-powered startup,
>>> but I can't tell from the front page if that's what it still does.
>>
>> Neither could I. I'd be hesitant to rely on something like that
>> though because either it will suddenly all vanish or you'll find
>> everything you've ever written owned by google or facebook or someone.
>> I realise most people worry about that less than me ("here, google,
>> have all my mail, my address book and diary entries because I really
>> want you to data mine me" - and people said *Unix* was "a moment of
>> convenience, a lifetime of regret").
>
> Of course.
>
> You can always write it yourself and run it on your own computers.

For example last night I wrote in CL a little daemon that accepts
incoming connections from my computer behind a dynamically allocated IP
address and calls nsupdate on my DNS server, to replace the service that
DynDNS used to offer gratis, but that they decided a few months ago to
limit to 14 days.


Of course, my granma couldn't have written it, so she would have forked
the money for DynDNS if she knew what it was… She'd also use gmail and
facebook.

Marco Antoniotti

unread,
Apr 9, 2012, 8:01:07 AM4/9/12
to
Not only it seems easier. It is also properly nesting.

MA

Kaz Kylheku

unread,
Apr 9, 2012, 3:03:40 PM4/9/12
to
#+ properly nests. When material is excluded by this #+ or #- notation, it
must be scanned for balancing parentheses. (That's a simplification; the real
rule is in the CLHS, of course. Possibly, the stuff being skipped could contain
read syntax which is so implementation-specific that it confuses this
algorithm. But then a spurious occurence |# will also confuse the #| ... |#
comments.

tar...@google.com

unread,
Apr 9, 2012, 8:46:53 PM4/9/12
to
On Sunday, April 8, 2012 6:07:18 AM UTC-7, Tim Bradshaw wrote:
> Given NIL presumably does
> not run on anything that exists or is emulated even #+nil should be ok.

Except that there once was a New Implementation of Lisp for the VAX, which went by the acronym NIL. So in that implementation, there was, IIRC NIL (or maybe :NIL) on the *features* list.

Kaz Kylheku

unread,
Apr 9, 2012, 9:28:31 PM4/9/12
to
That's what's being discussed! (what Tim means NIL in the above quote). :)

Tim's argument is that there are no installations of New Implementation of Lisp
that anyone cares about, emulated or real.

kod...@eurogaran.com

unread,
Apr 10, 2012, 6:37:25 AM4/10/12
to
El sábado, 7 de abril de 2012 00:13:59 UTC+2, Kaz Kylheku escribió:
> > Theoretically, NIL can be on *features*, so this is actually not a good
> > idea.
>
> Did New Implementation of Lisp have *features* and these reader macros, and if
> so, did it nave nil in *features*?
LoL.
You are devilishly clever.

kod...@eurogaran.com

unread,
Apr 10, 2012, 6:34:14 AM4/10/12
to
El lunes, 9 de abril de 2012 14:01:07 UTC+2, Marco Antoniotti escribió:
> > Even though with matching parenthesis navigation #| ... |# is not too hard either.
> >
> > Mirko
>
> Not only it seems easier. It is also properly nesting.
>
> MA

Speaking about nesting, it would be trivial to write a macro (comment ...)

Tim Bradshaw

unread,
Apr 10, 2012, 7:00:48 AM4/10/12
to
<kod...@eurogaran.com> wrote:

> Speaking about nesting, it would be trivial to write a macro (comment ...)

There were Lisps that did pretty much that: Interlisp I think used (*
"comment text") but could allso say, I think (COMMENT ...).

This does not work in CL however because macros return a form which is
evaluated: you can't have macros which return (for instance) a list of
forms which are spliced in to their context. So something like:

(if x (comment "this doesn't work) y z)

doesn't work in CL.

kodifik

unread,
Apr 10, 2012, 8:18:45 AM4/10/12
to
I was wrong. It should be a reader macro.

Antony

unread,
Apr 30, 2012, 9:02:32 AM4/30/12
to
On 4/6/2012 11:44 AM, Pascal Costanza wrote:
> On 06/04/2012 07:56, Elias Mårtenson wrote:
>> On Friday, 6 April 2012 12:50:44 UTC+8, Ralph Schleicher wrote:
>>> hans<schatze...@gmail.com> writes:
>>>
>>>> I would like to create a reader macro like the scheme #; to comment
>>>> out a form.
>>>
>>> Have you ever considered using '#-(and)' or '#+(or)'?
>>>
>>> (+ 1 #-(and)(* 2 3) 4)
>>> ==> 5
>>> (+ 1 #+(or)(* 2 3) 4)
>>> ==> 5
>>
>> In case you don't like the extra parentheses, I prefer using:
>>
>> #+nil(form to ignore)
>>
>> instead.
>
> Theoretically, NIL can be on *features*, so this is actually not a good
> idea.
>
I really liked the idea except for the wee bit of discomfort caused by
comment above.

So now I have
#+nil(error "nil is in *features* s-exp comments broken")
in my start up file.
I realize this may not work great for library authors, but works for me
(compared to what I used to do for commenting out sections of code),
especially combined with the syntax coloring by slime/emacs

-Antony

0 new messages