greghendershott/fear-of-macros

[question][3.1]having difficult time understanding define-syntax?

jsomedon opened this issue · 0 comments

First of all, thanks for making this! :-)

So on 3.1 where it talks about define-syntax with example:

(define-syntax foo
    (lambda (stx)
        (syntax "I am foo")))

it explains that:

When we use define-syntax, we’re making a transformer binding. This tells the Racket compiler, "Whenever you encounter a chunk of syntax starting with foo, please give it to my transformer function, and replace it with the syntax I give back to you." So Racket will give anything that looks like (foo ...) to our function, and we can return new syntax to use instead. Much like a search-and-replace.

My questions:

What does it mean that "a syntax starting with foo"? What is a syntax? Do you mean the syntax object that is introduced on section 3.2, that's something with lexical environment and code location and s-expression etc? Or is that some other conceptual thing or is that a specific language construct? If the syntax mentioned here here is the syntax object that's mentioned in 3.2, then what could a chunk of syntax mean here? It reads more like a piece of textual code then a set of language constructs(which is syntax object).. So I am not really sure what exactly the syntax mean here.

I am not sure what makes define-syntax different here either? But I guess once I get what syntax mean here then define-syntax makes some sense too?