Skip to content

Instantly share code, notes, and snippets.

@SaitoAtsushi
Last active December 11, 2015 16:58
Show Gist options
  • Save SaitoAtsushi/4630851 to your computer and use it in GitHub Desktop.
Save SaitoAtsushi/4630851 to your computer and use it in GitHub Desktop.
#!r6rs
(library (bound helper)
(export make-definition)
(import (rnrs))
(define-syntax make-definition
(lambda(stx2)
(syntax-case stx2 ()
((_ if-bound bound?)
#'(begin
(define-syntax if-bound
(lambda(stx)
(syntax-case stx ()
((_ id consequent)
#'(if-bound id consequent #f))
((_ id consequent alternate)
(not
(free-identifier=?
(datum->syntax #'if-bound (syntax->datum #'id))
#'id))
#'consequent)
((_ id consequent alternate)
#'alternate))))
(define-syntax bound?
(syntax-rules ()
((_ id)
(if-bound id #t #f)))))))))
)
(library (bound)
(export bound? if-bound)
(import (bound helper))
(make-definition if-bound bound?)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment