0

Here's the situation:

CL-USER> [bookid]
#<CLSQL-SYS:SQL-IDENT-ATTRIBUTE BOOKID>
CL-USER> (sql-expression :attribute 'bookid)
#<CLSQL-SYS:SQL-IDENT-ATTRIBUTE BOOKID>
CL-USER> [books.bookid]
#<CLSQL-SYS:SQL-IDENT-ATTRIBUTE BOOKS.BOOKID>
CL-USER> (sql-expression :attribute 'books.bookid)
#<CLSQL-SYS:SQL-IDENT-ATTRIBUTE "books.bookid">

Clsql's [] reader macro behaves differently than sql-expression. I'd rather use sql-expression inside macros, because the reader macro can act oddly there. I tried macroexpand-1, but I'm guessing it doesn't catch the expansion early enough. How does one explore the workings of a reader macro?

Edit: Found a solution for my clsql issue:

(sql-expression :table 'books :attribute 'bookid)

I'd still like to know about the read macro thing.

Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
BnMcGn
  • 1,440
  • 8
  • 22

2 Answers2

1

Reader macros are handled at read-time, not macroexpansion-time, so yes: too late for what you are trying to do. But you can just quote the expression. For example, with a simple infix reader macro, since I don't have clsql installed:

FOO> [1 + 2]
3
FOO> '[1 + 2]
(+ 1 2)

I suppose this would yield the sql-expression invocation (or something similar) in your case.

See also: Quote a reader macro invocation.

Community
  • 1
  • 1
danlei
  • 14,121
  • 5
  • 58
  • 82
1

To see the expansion of a reader macro, you need to read something:

? (read-from-string "[books.bookid]")

Since the R in REPL stands for READ, the normal REPL (read eval print loop) already reads the input and thus does run the reader macros. To prevent the evaluation, you need to quote it:

? '[books.bookid]
Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346