2 Reflection
To support the addition of new user-defined language features, cur provides access to various parts of the language implementation as Racket forms at phase 1. The reflection features are unstable and may change without warning.
The reflection API enforces type safety; all terms are first expanded, then
type checked, then reduced; individual API function may not complete this
route—
Because these functions must be used during the dynamic extent of a syntax transformer application by the expander (see local-expand), the examples in this file do not currently run in the REPL, so these examples may contain typos.
Changed in version 0.20 of package cur-lib: Removed declare-data!, call-local-data-scope, local-data-scope—
procedure
(cur-type-infer syn [#:local-env env]) → (or/c syntax? #f)
syn : syntax? env : (listof (cons/c syntax? syntax?)) = '()
If #:local-env is specified, infers types under an extended lexical environment via with-env.
> (cur-type-infer #'(λ (x : Type) x)) > (cur-type-infer #'Type) #'(Type 1)
> (cur-type-infer #'X #:local-env '((#'X . #'(Type 0)))) #'(Type 0)
> (define-syntax-rule (cur-type-infer& t) (cur-type-infer t)) > #`(λ (X : (Type 0)) (cur-type-infer& X))
NOTE: This #:local-env keyword argument is deprecated; use a macro to delay the function call until the binder is expanded. See cur-type-infer for an example., instead.
procedure
(cur-type-check? term type [#:local-env env]) → boolean?
term : syntax? type : syntax? env : (listof (cons/c syntax? syntax?)) = '()
If #:local-env is specified, checks the type under an extended lexical environment via with-env.
> (cur-type-check? #'(λ (x : Type) x) #'(Π (x : (Type 1)) Type)) #t
> (cur-type-check? #'Type #'(Type 1)) #t
> (cur-type-check? #'x #'Nat) #f
> (cur-type-check? #'x #'Nat #:local-env `((#'x . #'Nat))) #t
NOTE: This #:local-env keyword argument is deprecated; use a macro to delay the function call until the binder is expanded. See cur-type-infer for an example., instead.
procedure
(cur-reflect-id id) → identifier?
id : identifier?
Added in version 0.20 of package cur-lib.
procedure
(cur-rename new old term) → syntax?
new : identifier? old : identifier? term : syntax?
> (cur-rename #'Y #'X #'((λ (X : (Type 0)) X) X)) #<syntax:eval:1:0 ((λ (X : (Type 0)) X) Y)>
Added in version 0.20 of package cur-lib.
procedure
(cur-normalize syn [#:local-env env]) → syntax?
syn : syntax? env : (listof (cons/c syntax? syntax?)) = '()
If #:local-env is specified, runs under an extended lexical environment via with-env.
NOTE: This #:local-env keyword argument is deprecated; use a macro to delay the function call until the binder is expanded. See cur-type-infer for an example., instead.
procedure
(cur-step syn [#:local-env env]) → syntax?
syn : syntax? env : (listof (cons/c syntax? syntax?)) = '()
If #:local-env is specified, runs under an extended lexical environment via with-env.
> (cur-step #'((λ (x : Type) x) Bool)) #'Bool
> (cur-step #'(sub1 (s (s z)))) #'(elim Nat (λ (x2 : Nat) Nat) (z (λ (x2 : Nat) (λ (ih-n2 : Nat) x2))) (s (s z)))
NOTE: This #:local-env keyword argument is deprecated; use a macro to delay the function call until the binder is expanded. See cur-type-infer for an example., instead.
procedure
(cur-equal? e1 e2 [#:local-env env]) → boolean?
e1 : syntax? e2 : syntax? env : (listof (cons/c syntax? syntax?)) = '()
NOTE: This #:local-env keyword argument is deprecated; use a macro to delay the function call until the binder is expanded. See cur-type-infer for an example., instead.
procedure
(cur->datum s [#:local-env env]) → (or/c symbol? list?)
s : syntax? env : (listof (cons/c syntax? syntax?)) = '()
> (cur->datum #'(λ (a : (Type 0)) a)) '(λ (a : (Type 0)) a)
NOTE: This #:local-env keyword argument is deprecated; use a macro to delay the function call until the binder is expanded. See cur-type-infer for an example., instead.
procedure
(cur-constructors-for D) → (listof identifier?)
D : identifier?
> (cur-constructors-for #'Nat) '(#'z #'s)
procedure
D : identifier?
> (cur-data-parameters #'Nat) 0
> (cur-data-parameters #'List) 1
procedure
c : identifier?
> (cur-constructor-telescope-length #'z) 0
> (cur-constructor-telescope-length #'s) 1
> (cur-constructor-telescope-length #'cons) 3
procedure
→ (listof natural-number/c) c : identifier?
> (cur-constructor-recursive-index-ls #'z) '()
> (cur-constructor-recursive-index-ls #'s) '(0)
> (cur-constructor-recursive-index-ls #'cons) '(2)