Hydrocat
Hydrocat

Reputation: 105

Reader macro vs a normal parser

I am in the process of implementing a program that applies some transformations to SQL code. When it comes to parsing said code, I thought about two approaches.

  1. Implementing a "standard" parser using ordinary functions
  2. Implementing a Reader macro that does such interpretation at read-time.

I'd like to know if implementing a reader macro is valid for this case or I'm better off writing it with usual functions and avoid killing a insect with a bazooka.

Upvotes: 1

Views: 139

Answers (1)

Spenser Truex
Spenser Truex

Reputation: 973

You can use a reader macro as a way to inline SQL code if you want, like

#[SQL code here]

having that call a function like (sql "SQL code here"), but you won't be able to do something as complex as writing a full SQL interpreter with reader macros. Besides, how could you access the database at runtime (when you will probably need it) if you did all that at read time?

Another approach is to create a lispy SQL DSL, where you could use regular functions and macros.

Upvotes: 2

Related Questions