Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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")
like image 711
Mike Manilone Avatar asked Feb 26 '13 14:02

Mike Manilone


1 Answers

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")
like image 138
6502 Avatar answered Oct 14 '22 18:10

6502