Thursday, 12 September 2013

define-syntax vs. defining functions

define-syntax vs. defining functions

In Racket, you can define syntax in this way:
(define-syntax foo
(syntax-rules ()
((_ "abc") 'xyz)))
By running
(foo "abc")
It returns 'xyz. Implementing this using define:
(define (foo x)
(match "abc" ["abc" 'xyz]))
This time,
(foo "abc")
still returns 'xyz. What is the difference between using these different
forms?

No comments:

Post a Comment