Questions about macros

28 views
Skip to first unread message

Joel Shellman

unread,
May 12, 2012, 7:39:27 PM5/12/12
to qil...@googlegroups.com
All I've found so far about macros is

http://www.shenlanguage.org/Documentation/shendoc.htm#Reader Macros
http://www.shenlanguage.org/learn-shen/macros.html

Is there more information anywhere?

For example:

1) How would one put [ and ] (list shorthand?) inside a macro
definition since it appears they are converted to parens?
2) Is there a shorthand for having a single macro expand out to
multiple top level expressions? I suppose I could use some form of
map/fold or something but, just wondering if there was something
simpler
3) with (tc +) I get my-macro "lacks a proper signature" error or a
type error. What should the signature be? For example, I tried this:
(defmacro testm {number --> number} [add2 N] -> [+ 2 N])

Also, I don't see datatype listed in system functions or primitives. I
grepped the shen source and found it in macros.shen. But it doesn't
have a type signature specified for it. What would it be?

Mark Tarver

unread,
May 13, 2012, 12:29:10 PM5/13/12
to Qilang


On May 13, 12:39 am, Joel Shellman <j...@mentics.com> wrote:
> All I've found so far about macros is
>
> http://www.shenlanguage.org/Documentation/shendoc.htm#ReaderMacroshttp://www.shenlanguage.org/learn-shen/macros.html
>
> Is there more information anywhere?

As yet no.

>
> For example:
>
> 1) How would one put [ and ] (list shorthand?) inside a macro
> definition since it appears they are converted to parens?

You would have to use cons-form or else define your own list as a
macro. but do not use 'list' because this is a type operator.

> 2) Is there a shorthand for having a single macro expand out to
> multiple top level expressions? I suppose I could use some form of
> map/fold or something but, just wondering if there was something
> simpler

Yes; you can parcel up multiple expressions into the null package.
http://www.shenlanguage.org/Documentation/shendoc.htm#Packages

> 3) with (tc +) I get my-macro "lacks a proper signature" error or a
> type error. What should the signature be? For example, I tried this:
>        (defmacro testm {number --> number} [add2 N] -> [+ 2 N])

Macros do not accept signatures because they just produce s-exprs.
>
> Also, I don't see datatype listed in system functions or primitives. I
> grepped the shen source and found it in macros.shen. But it doesn't
> have a type signature specified for it. What would it be?

It has none; it is not a function.

Mark

Dmitry Cherkassov

unread,
May 13, 2012, 2:29:40 PM5/13/12
to Qil...@googlegroups.com
Joel Shellman <jo...@mentics.com> writes:

> 3) with (tc +) I get my-macro "lacks a proper signature" error or a
> type error. What should the signature be? For example, I tried this:
> (defmacro testm {number --> number} [add2 N] -> [+ 2 N])

As a general rule you should put your macroses in separate file(s) and
disable typechecking for it(them).

--
With best regards,
Dmitry

Reply all
Reply to author
Forward
0 new messages