UP | HOME

NOTE: ee-lib

1. Introduction

ee-lib is an amazing library made by Michael Ballantyne, it provides a convenience local context let user can record meta information for a macro, but there have some behaviors I want to record for future development.

2. Note

2.1. Binding will disappear when add-scope on the syntax

(define-syntax-parser mydef
  [(_ n:id e:expr)
   (with-scope sc
     (with-syntax ([new-n (add-scope #'n sc)])
       #'(define new-n e)))])

(mydef a 1)
a

Error: a: unbound identifier in: a

You can print #'new-n to check this fact. Hence, if you want to generate an identifier for a definition, ensure that identifier isn't get from add-scope.

2.2. You cannot bind identifier out of scope

(define-syntax-parser mydef
  [(_ n:id e:expr)
   (bind! #'n #'1)
   (with-scope sc
     #'(define n e))])

Error: bind!: cannot bind outside of dynamic extent of with-scope

This makes sense, because you might not like to affect others context, this example tells the purpose of the library.

3. Example

In the end, here is a small normal usage of the library.

(define-syntax-parser mydef
  [(_ n:id e:expr)
   (with-scope sc
     (bind! #'n #'(* 10 e))
     (with-syntax ([e (lookup #'n)])
       #'(define n e)))])

(mydef a 1)
a

Result: 10

Date: 2022-08-28 Sun 00:00
Author: Lîm Tsú-thuàn