Mike Manilone
Mike Manilone

Reputation: 590

Define my own read macro

There are some read macros in Common Lisp such as ' #' #P, but how can I write a read macro?

Like this:

#T"hello world"
====================>
(gettext "hello world")

Upvotes: 5

Views: 194

Answers (1)

6502
6502

Reputation: 114481

You can use set-macro-character and set-dispatch-macro-character, for example after:

(set-dispatch-macro-character #\# #\T
  (lambda (s c n)
    `(gettext ,(read s t nil t))))
==> T

you can use the installed read syntax

(read-from-string "#T\"this is a test\"")
==> (GETTEXT "this is a test")

Upvotes: 5

Related Questions