Created
February 6, 2021 14:42
-
-
Save shhyou/d761013ee0d1ae2cc3d42d5d4750ea4c to your computer and use it in GitHub Desktop.
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 characters
#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