- Racket. , , :
(* 3 4)
, . , , :
(define example-program
(open-input-string
"
#lang racket/base
(* 3 4)
"))
(read-accept-reader
(define thingy (read-syntax 'the-test-program example-program))
(print thingy) (newline)
(syntax? thingy)
, * thingy. * in thingy , : . * * of #lang racket/base.
, . (. eval, , .)
, , :
(require (for-syntax racket/base))
;; This macro is only meant to let us see what the compiler is dealing with
;; at compile time.
(define-syntax (at-compile-time stx)
(syntax-case stx ()
[(_ expr)
(let ()
(define the-expr
(printf "I see the expression is: ~s\n" the-expr)
;; Ultimately, as a macro, we must return back a rewrite of
;; the input. Let just return the expr:
the-expr)]))
(at-compile-time (* 3 4))
at-compile-time, . DrRacket, , DrRacket , . , at-compile-time, .
, - :
I see the expression is: #<syntax:20:17 (* 3 4)>
, identifier-binding:
(require (for-syntax racket/base))
(define-syntax (at-compile-time stx)
(syntax-case stx ()
[(_ expr)
(let ()
(define the-expr
(printf "I see the expression is: ~s\n" the-expr)
(when (identifier? the-expr)
(printf "The identifier binding is: ~s\n" (identifier-binding the-expr)))
the-expr)]))
((at-compile-time *) 3 4)
(let ([* +])
((at-compile-time *) 3 4))
DrRacket, :
I see the expression is: #<syntax:21:18 *>
The identifier binding is: (#<module-path-index> * #<module-path-index> * 0 0 0)
I see the expression is: #<syntax:24:20 *>
The identifier binding is: lexical
12
7
(: at-compile-time ? ! -, raco make, , .)
, at-compile-time, , . identifier-binding , , ( #lang racket/base, module-path-index). , : (let ([* +]) ...), , * , let.
Racket , , .
eval : , , ! , .
, , s- :
(module mod1 racket/base
(provide x)
(define x
(module mod2 racket/base
(define * +) ;; Override!
(provide x)
(define x
;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require (prefix-in m1: (submod "." mod1))
(prefix-in m2: (submod "." mod2)))
(displayln m1:x)
(displayln (syntax->datum m1:x))
(eval m1:x)
(displayln m2:x)
(displayln (syntax->datum m2:x))
(eval m2:x)
, , , eval. ,
(module broken-mod2 racket/base
(provide x)
(define x
(let ([* +])
, eval x, broken-mod2, , eval. eval - .