Skip to content

Instantly share code, notes, and snippets.

@shhyou
Created February 6, 2021 14:42
Show Gist options
  • Save shhyou/d761013ee0d1ae2cc3d42d5d4750ea4c to your computer and use it in GitHub Desktop.
Save shhyou/d761013ee0d1ae2cc3d42d5d4750ea4c to your computer and use it in GitHub Desktop.
#lang racket/base
(require (for-syntax racket/base
racket/sequence
racket/provide-transform))
(provide (except-out (all-defined-out)
(all-in-private-list)))
(define-for-syntax private-list '())
(define-syntax (declare-as-private stx)
(syntax-case stx ()
[(_ id ...)
(let ()
(for ([an-id (in-syntax #'(id ...))])
(set! private-list (cons an-id private-list)))
(syntax/loc stx (begin)))]))
(define-syntax all-in-private-list
(make-provide-transformer
(λ (stx modes)
(expand-export #`(combine-out . #,private-list) modes))))
(define (fib n)
(do-fib 0 1 n))
(declare-as-private do-fib)
(define (do-fib a b n)
(cond [(zero? n) a]
[else (do-fib b (+ a b) (sub1 n))]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment