Skip to content

Instantly share code, notes, and snippets.

@6cdh
Last active June 6, 2022 02:38
Show Gist options
  • Save 6cdh/65619e761753eb4166d15185a6236040 to your computer and use it in GitHub Desktop.
Save 6cdh/65619e761753eb4166d15185a6236040 to your computer and use it in GitHub Desktop.
Generate Racket builtin variable list
#lang racket
; some code copied from https://github.com/greghendershott/racket-mode/blob/master/racket/keywords.rkt
(define (exports mod #:only-stx? [only-stx? #f])
(define (ids phases)
(for*/list ([phase phases]
[item (cdr phase)])
(car item)))
(define-values (vars stxs) (module->exports mod))
(remove-duplicates (append (ids stxs)
(if only-stx? '() (ids vars)))
eq?))
(define (subtract xs ys)
(set->list
(set-subtract (list->set xs)
(list->set ys))))
(define (union xs ys)
(set->list
(set-union (list->set xs)
(list->set ys))))
(define (pp xs)
(println (sort (map symbol->string xs) string<=?)))
; used in tree-sitter `#match?` predicate
(define (symlist->regex-match lst)
(string-append
"^("
(regexp-replace* #rx"([*+?^$.])"
(string-join (map symbol->string lst) "|")
"\\\\\\1")
")$"))
(parameterize ([current-namespace (make-base-empty-namespace)])
(namespace-require 'racket)
(define all (exports 'racket))
(define stx (exports 'racket #:only-stx? #t))
(define builtin-procedures
(filter (λ (sym)
(with-handlers ([exn:fail? (const #f)])
(procedure? (eval sym))))
all))
(define builtin-keywords (subtract stx builtin-procedures))
(define builtin-values (subtract (subtract all stx) builtin-procedures))
(pp builtin-procedures))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment