I am trying to make a small shell for doing sql-like queries on csv files (out of curiosity and as an attempt to learn Racket). For this I wanted to implement a select macro with this rough structure (where I planned to have x be the columns of the db but just passed a single row for now):
(define-syntax select
(syntax-rules (* from where)
((_ col1 ... from db where condition)
(filter (lambda (x) condition) <minutiae>))))
(Where minutiae is file IO and pipe code)
The scope for x is not what I thought it to be:
x: undefined;
cannot reference an identifier before its definition
I found this example of a let-like macro:
(define-syntax my-let*
(syntax-rules ()
((_ ((binding expression) ...) body ...)
(let ()
(define binding expression) ...
body ...))))
And then I proceeded to try to just produce the lambda like so:
(define-syntax my-lambda
(syntax-rules ()
((_ body)
(lambda (x)
body))))
And then trying to mimic the structure of the let example:
(define-syntax my-lambda
(syntax-rules ()
((_ body)
(lambda (x_)
(let ()
(define x x_)
body)))))
Both of these gave me the same error upon invocation ((my-lambda (+ x 1)) 0)
:
x: undefined;
cannot reference an identifier before its definition
According to my reading this is due to hygiene, but I can't seem to grasp it well enough to solve this on my own. What am I doing wrong and how would one define these kinds of macros? Why is the let example working but not the lambda one?