From: Peter Keller on
Hello,

I'm reading Let over Lambda by Doug Hoyte and I have some general questions
about library APIs with respect to his book.

1. He defines a macro called defmacro/g! which picks through the symbols in the
supplied body and for those named g!<extra_characters> he creates a lexical
context ala with-gensyms. So a macro looks like this:

(defmacro/g! square (x)
`(let ((,g!val ,x))
(* ,g!val ,g!val)))

And it expands to something there g!val is defined in a with-gensym style
environment.

2. In another chapter, he talks about implementing read macros to make it
easier to read perl-like regular expressions, the read macro would parse a form
like #~s/foo/bar into a function which could be applied to arguments like and
whose return value is the substituted result:

* (#~s/foo/bar "fooit")

"barit"

So, my question is: How do lisp programmers feel about this type of thing
for the purposes of using a library?

If I told you that in order to use my library, you had to prefix symbols with
feh/ or %stuff- when utilizing certain macros, and additionally there are a
pile of read macros--and I hope you didn't use any in your codes, what would
you say?

For things like symbol names, these are held in packages and exported. But for
things like read-macros and encoding out of band data in symbol names or other
structures, what happens? How is this "namespace collision" handled? Do people
just do it anyway and some how it manages to get along?

Thank you.

-pete
From: Scott L. Burson on
On May 17, 5:21 pm, Peter Keller <psil...(a)cs.wisc.edu> wrote:
> Hello,
>
> I'm reading Let over Lambda by Doug Hoyte and I have some general questions
> about library APIs with respect to his book.
>
> 1. He defines a macro called defmacro/g! which picks through the symbols in the
> supplied body and for those named g!<extra_characters> he creates a lexical
> context ala with-gensyms. So a macro looks like this:
>
> (defmacro/g! square (x)
> `(let ((,g!val ,x))
>         (* ,g!val ,g!val)))
>
> And it expands to something there g!val is defined in a with-gensym style
> environment.
>
> 2. In another chapter, he talks about implementing read macros to make it
> easier to read perl-like regular expressions, the read macro would parse a form
> like #~s/foo/bar into a function which could be applied to arguments like and
> whose return value is the substituted result:
>
> * (#~s/foo/bar "fooit")
>
> "barit"
>
> So, my question is: How do lisp programmers feel about this type of thing
> for the purposes of using a library?
>
> If I told you that in order to use my library, you had to prefix symbols with
> feh/ or %stuff- when utilizing certain macros, and additionally there are a
> pile of read macros--and I hope you didn't use any in your codes, what would
> you say?
>
> For things like symbol names, these are held in packages and exported.  But for
> things like read-macros and encoding out of band data in symbol names or other
> structures, what happens? How is this "namespace collision" handled? Do people
> just do it anyway and some how it manages to get along?

Item 1 is no big deal because I don't have to use your macro if I
don't want to, but read macro collisions are potentially a big problem
which, alas, CL provides no machinery at all to help with. I don't
really know why the standard doesn't include a way of assigning global
names to readtables and an IN-READTABLE macro. That would have been a
crude partial solution, but it would have been something... right now
we have nothing.

-- Scott

From: Tamas K Papp on
On Tue, 18 May 2010 00:21:13 +0000, Peter Keller wrote:

> Hello,
>
> I'm reading Let over Lambda by Doug Hoyte and I have some general
> questions about library APIs with respect to his book.
>
> [...]
>
> If I told you that in order to use my library, you had to prefix symbols
> with feh/ or %stuff- when utilizing certain macros, and additionally
> there are a pile of read macros--and I hope you didn't use any in your
> codes, what would you say?
>
> For things like symbol names, these are held in packages and exported.
> But for things like read-macros and encoding out of band data in symbol
> names or other structures, what happens? How is this "namespace
> collision" handled? Do people just do it anyway and some how it manages
> to get along?

I don't see why I should care about the extensions you use to _define_
your macros, when I am just _using_ those macros. So I see no problem
with the ! stuff (though personally I don't see the great
advantages, I am fine with existing facilities like with-unique-names
and once-only).

Regarding read macros: check out the named-readtables library, it
brings some sanity into the management of readtables/readmacros.

Best,

Tamas
From: Pascal J. Bourguignon on
"Scott L. Burson" <gyro(a)zeta-soft.com> writes:

> On May 17, 5:21�pm, Peter Keller <psil...(a)cs.wisc.edu> wrote:
>> Hello,
>>
>> I'm reading Let over Lambda by Doug Hoyte and I have some general questions
>> about library APIs with respect to his book.
>>
>> 1. He defines a macro called defmacro/g! which picks through the symbols in the
>> supplied body and for those named g!<extra_characters> he creates a lexical
>> context ala with-gensyms. So a macro looks like this:
>>
>> (defmacro/g! square (x)
>> `(let ((,g!val ,x))
>> � � � � (* ,g!val ,g!val)))
>>
>> And it expands to something there g!val is defined in a with-gensym style
>> environment.
>>
>> 2. In another chapter, he talks about implementing read macros to make it
>> easier to read perl-like regular expressions, the read macro would parse a form
>> like #~s/foo/bar into a function which could be applied to arguments like and
>> whose return value is the substituted result:
>>
>> * (#~s/foo/bar "fooit")
>>
>> "barit"
>>
>> So, my question is: How do lisp programmers feel about this type of thing
>> for the purposes of using a library?
>>
>> If I told you that in order to use my library, you had to prefix symbols with
>> feh/ or %stuff- when utilizing certain macros, and additionally there are a
>> pile of read macros--and I hope you didn't use any in your codes, what would
>> you say?
>>
>> For things like symbol names, these are held in packages and exported. �But for
>> things like read-macros and encoding out of band data in symbol names or other
>> structures, what happens? How is this "namespace collision" handled? Do people
>> just do it anyway and some how it manages to get along?
>
> Item 1 is no big deal because I don't have to use your macro if I
> don't want to, but read macro collisions are potentially a big problem
> which, alas, CL provides no machinery at all to help with. I don't
> really know why the standard doesn't include a way of assigning global
> names to readtables and an IN-READTABLE macro. That would have been a
> crude partial solution, but it would have been something... right now
> we have nothing.

This is not exactly right, it provides the *READTABLE* special variable:

(let ((*read-table* *C-read-table*))
(read-from-string "int f(int x){ return((x==0)?1:x*f(x-1)); }"))
--> (define-c-function f ((x int)) int (return (if (== 0 x) 1 (* x (f (- x 1))))))


(defun reset-readtable () (setf *read-table* (copy-readtable nil)))
(setf *read-table* *C-read-table*)

int f(int x){ return((x==0)?1:x*f(x-1)); }
--> F

reset_readtable();
--> #<READTABLE #x7FA408958CC8>

(+ 1 2)
--> 3


Now, of course, if you want to mix reader macros, you have to build
your own readtable. But given that's to define character level
syntaxis, I don't see that it be a problem.

--
__Pascal Bourguignon__ http://www.informatimago.com/
From: Peter Keller on
Tamas K Papp <tkpapp(a)gmail.com> wrote:
> On Tue, 18 May 2010 00:21:13 +0000, Peter Keller wrote:
> I don't see why I should care about the extensions you use to _define_
> your macros, when I am just _using_ those macros. So I see no problem
> with the ! stuff (though personally I don't see the great
> advantages, I am fine with existing facilities like with-unique-names
> and once-only).

I see, so in general noone would care that a macro might encode a DSL in its
API. People would read the directions, and hopefully get it right.
I can live with that.

> Regarding read macros: check out the named-readtables library, it
> brings some sanity into the management of readtables/readmacros.

Interesting.

Are there any really good tutorials out there for how to use readtables
to make things like Pascal suggessted (with the C syntax to lisp syntax
translator)?

Thank you.

-pete