Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save LeifAndersen/0c5eff4a84cb56a2e78b2ca64cdf75e5 to your computer and use it in GitHub Desktop.
Save LeifAndersen/0c5eff4a84cb56a2e78b2ca64cdf75e5 to your computer and use it in GitHub Desktop.
#lang scratch
(require compiler/zo-structs
(for-syntax compiler/zo-structs
racket/struct-info))
(begin-for-syntax
(define-values (exports expsyn)
(module->exports 'compiler/zo-structs))
(define struct-types
(parameterize ([current-namespace (make-base-namespace)])
(namespace-require 'compiler/zo-structs)
(let* ([_ (dict-ref exports 0)]
[_ (map first _)]
[_ (map eval _)]
[_ (filter struct-type? _)])
_)))
(define accessors-table
(for/list ([i (in-list struct-types)])
(match-define-values (name _ _ _ _ _ _ _)
(struct-type-info i))
(cons name
(let* ([_ (datum->syntax #'#f name)]
[_ (syntax-local-value _)]
[_ (extract-struct-info _)]
[_ (fourth _)]
[_ (reverse _)])
_)))))
(define-syntax-parser mk-lookup-proc
[(_)
#`(λ (type stru)
(match type
#,@(for/list ([si (in-list accessors-table)])
#`('#,(car si)
(list '#,(car si)
#,@(for/list ([i (in-list (cdr si))])
#`(list '#,i (#,i stru))))))))])
(define lookup-fields (mk-lookup-proc))
(define (digest-form f)
(let ()
(match-define-values (type _) (struct-info f))
(match-define-values (name _ _ _ _ _ _ _)
(struct-type-info type))
(lookup-fields name f)))
(define defvalform
(def-values '(hello) '()))
(digest-form defvalform)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment