Common Lisp Special Shortcut Characters
Asked Answered
M

2

8

In Common Lisp, there are obviously some special characters that act as shortcuts for certain forms. 'x means (quote x). #'f means (function f). I had thought those (as well as backtick) were the only ones, but then I learned about #(), which is apparently a vector, and just today someone mentioned #., which apparently does something with evaluation time.

Try as I might, I can't seem to find a comprehensive list of which prefix symbols mean something and what they do? Is this something that's left to the implementation to decide, or could someone point me to somewhere in the standard that lists these shortcuts comprehensively?

Mccully answered 15/1, 2015 at 21:23 Comment(4)
There's only a comprehensive list in the standard, but you can define new macro characters at any time.Betake
Well that's news to me. What's the name of the call I need to make to define my own?Mccully
I'm putting together an answer, but start by having a look at Chapter 17 Read Macros from On Lisp. You may also find my answer to How to define symbols that will work like ( and ) by symbol macro? helpful.Betake
Sidenote: #. works at reading time.Euthenics
B
8

The HyperSpec, in 2.4 Standard Macro Characters, enumerates "the macro characters defined initially in a conforming implementation". You can define your own using set-macro-character, which handles the types like ' which have no "prefix" to them, and set-dispatch-macro-character, which handles the type that are prefixed by a dispatch character (typically #).

In addition to the HyperSpec, you may find Chapter 17, Read Macros from Paul Graham's On Lisp helpful. It begins with an implementation of ', i.e., the macro character that expands to (quote ...). Answers to How to define symbols that will work like ( and ) by symbol macro? are also helpful, as there are some uses of set-macro-character.

Betake answered 15/1, 2015 at 21:47 Comment(0)
B
5

What you are looking for are Standard Macro Characters.

You can define your own using set-dispatch-macro-character and set-macro-character.

In fact, this is how I implemented XML Parsing.

Berkshire answered 15/1, 2015 at 21:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.