-
-
Save dannypsnl/3ae083d3d59e23280bd41a47fbd7e0f4 to your computer and use it in GitHub Desktop.
Revisions
-
shhyou revised this gist
Feb 18, 2021 . 2 changed files with 30 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ #lang racket/base (require (for-syntax racket/base)) (begin-for-syntax (struct extrainfo (target data) #:property prop:rename-transformer (struct-field-index target)) (provide extrainfo-data)) (provide (rename-out [my-extra-surface my-extra])) (define-syntax my-extra-surface (extrainfo (syntax-property #'my-extra 'not-free-identifier=? #t) "mul.rkt: my-extra info")) (define (my-extra a b) (+ a b)) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ #lang racket/base (require "a-extra.rkt") my-extra (my-extra 2 3) (require (for-syntax racket/base syntax/parse)) (define-syntax (expand-to-extra-info stx) (syntax-parse stx [(_ id) (define-values (info target) (syntax-local-value/immediate #'id)) #`(quote #,(extrainfo-data info))])) (expand-to-extra-info my-extra) -
shhyou revised this gist
Feb 17, 2021 . 1 changed file with 13 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,19 +1,31 @@ ;; Exporting free identifier table operations that close over a global map #lang racket/base (require racket/list syntax/id-table) (provide env-ref env-has-id? env-add!) (define id-table (make-free-id-table)) (define (env-ref id) (debug-print-binding-info 'env-ref id) (free-id-table-ref id-table id)) (define (env-has-id? id) (debug-print-binding-info 'env-has-id? id) (with-handlers ([exn:fail? (λ (e) #f)]) (free-id-table-ref id-table id) #t)) (define (env-add! id value) (debug-print-binding-info 'env-add! id) (free-id-table-set! id-table id value)) (define (debug-print-binding-info who id) (define binding (identifier-binding id)) (printf "env.rkt: ~a:\n id: ~s\n binding: ~s\n" who id (and (list? binding) (take binding 2)))) -
shhyou revised this gist
Feb 17, 2021 . 1 changed file with 11 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,12 +6,19 @@ (require (for-syntax racket/base "0-env.rkt") "2-mul.rkt") (begin-for-syntax (printf "use.rkt: my-fun = ~s\n" (env-ref #'my-fun)) (printf "use.rkt: has-key?(your-fun) = ~s\n" (env-has-id? #'your-fun)) ) (my-fun 8 3) #; (begin (require (only-in "1-add.rkt" [my-fun add:my-fun])) (begin-for-syntax (printf "use.rkt: add:my-fun = ~s\n" (env-ref #'add:my-fun)) ) (add:my-fun 7 (my-fun 8 3)) ) -
shhyou revised this gist
Feb 17, 2021 . 6 changed files with 39 additions and 41 deletions.There are no files selected for viewing
File renamed without changes.This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ #lang racket/base (require (for-syntax racket/base "0-env.rkt")) (provide my-fun your-fun) (begin-for-syntax (env-add! #'my-fun "my-fun from add.rkt")) (define (my-fun a b) (+ a b)) (begin-for-syntax (env-add! #'your-fun "your-fun from add.rkt")) (define (your-fun c) (- c)) ;; See https://docs.racket-lang.org/syntax/syntax-helpers.html#%28part._.Dictionaries_for_free-identifier~3d_%29 ;; for the caveat of macro-generated definitions This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ #lang racket/base (require (for-syntax racket/base "0-env.rkt") "1-add.rkt") (provide my-fun) (begin-for-syntax (env-add! #'my-fun "my-fun from mul.rkt") (printf "mul.rkt: your-fun is: ~s\n" (env-ref #'your-fun))) (define (my-fun a b) (* a (your-fun b))) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,12 +5,13 @@ #lang racket/base (require (for-syntax racket/base "0-env.rkt") (only-in "1-add.rkt" my-fun) (rename-in "2-mul.rkt" [my-fun mul:my-fun])) (begin-for-syntax (printf "use.rkt: my-fun = ~s\n" (env-ref #'my-fun)) (printf "use.rkt: has-key?(your-fun) = ~s\n" (env-has-id? #'your-fun)) (printf "use.rkt: mul:my-fun = ~s\n" (env-ref #'mul:my-fun)) ) (my-fun 7 (mul:my-fun 8 3)) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,19 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,18 +0,0 @@ -
shhyou created this gist
Feb 17, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ #lang racket/base (require (for-syntax racket/base "env.rkt")) (provide my-fun your-fun) (define (my-fun a b) (+ a b)) (define (your-fun c) (- c)) ;; https://docs.racket-lang.org/syntax/syntax-helpers.html#%28part._.Dictionaries_for_free-identifier~3d_%29 ;; Must be placed after the definition of my-fun (begin-for-syntax (env-add! #'my-fun "my-fun from add.rkt") (env-add! #'your-fun "your-fun from add.rkt")) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ ;; Exporting free identifier table operations that close over a global map #lang racket/base (require syntax/id-table) (provide env-ref env-has-id? env-add!) (define id-table (make-free-id-table)) (define (env-ref id) (free-id-table-ref id-table id)) (define (env-has-id? id) (with-handlers ([exn:fail? (λ (e) #f)]) (free-id-table-ref id-table id) #t)) (define (env-add! id value) (free-id-table-set! id-table id value)) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ #lang racket/base (require (for-syntax racket/base "env.rkt") "add.rkt") (provide my-fun) (begin-for-syntax (printf "mul.rkt: your-fun is: ~s\n" (env-ref #'your-fun))) (define (my-fun a b) (* a (your-fun b))) ;; https://docs.racket-lang.org/syntax/syntax-helpers.html#%28part._.Dictionaries_for_free-identifier~3d_%29 ;; Must be placed after the definition of my-fun (begin-for-syntax (env-add! #'my-fun "my-fun from mul.rkt")) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ ;; Dependency: ;; add depends on {env} ;; mul depends on {add,env} ;; use depends on {mul,add,env} #lang racket/base (require (for-syntax racket/base "env.rkt") (only-in "add.rkt" my-fun) (rename-in "mul.rkt" [my-fun mul:my-fun])) (begin-for-syntax (printf "use.rkt: my-fun = ~s\n" (env-ref #'my-fun)) (printf "use.rkt: has-key?(your-fun) = ~s\n" (env-has-id? #'your-fun)) ;; => #f (printf "use.rkt: mul:my-fun = ~s\n" (env-ref #'mul:my-fun)) )