5

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")
Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
Mike Manilone
  • 582
  • 4
  • 17

1 Answers1

5

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")
6502
  • 112,025
  • 15
  • 165
  • 265