[racket users] Macro literal "|"

33 views
Skip to first unread message

Kevin Forchione

unread,
Feb 3, 2020, 6:27:06 PM2/3/20
to Racket-Users List
Hi guys,
I’ve been trying to figure out how to use “|” in a macro. I’ve got syntax like this in mind:

(foo A | B)

Not sure if I can do this because the reader expects a pair. If “|” isn’t a convenient literal to work with is there an alternative others have used that represents more or less the idea of “or” or “alternate”?

Thanks!

Kevin

Philip McGrath

unread,
Feb 3, 2020, 7:03:32 PM2/3/20
to Kevin Forchione, Racket-Users List
You're right that `|` isn't a valid terminal with the normal reader, but, as it happens, the zero-length identifier can be written as `||`. (I don't think the concept of a zero-length identifier is common in other languages: it corresponds to the empty string.)

-Philip


--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/447100AA-DB45-46C3-A7DC-2705A1668302%40gmail.com.

Stephen Chang

unread,
Feb 3, 2020, 9:42:12 PM2/3/20
to Kevin Forchione, Racket-Users List
As mentioned, to get your macro to work, you have to change how the
reader behaves on "|".

You might be interested in the (implementation of) no-vert-bar reader lang:

https://docs.racket-lang.org/no-vert-bar-lang/index.html

On Mon, Feb 3, 2020 at 6:27 PM Kevin Forchione <lys...@gmail.com> wrote:
>
Reply all
Reply to author
Forward
0 new messages