Skip to content

Instantly share code, notes, and snippets.

@niyarin
Created March 19, 2019 17:58
Show Gist options
  • Save niyarin/565a8ec6564e59ffe65114604d01e99a to your computer and use it in GitHub Desktop.
Save niyarin/565a8ec6564e59ffe65114604d01e99a to your computer and use it in GitHub Desktop.
condp syntax for Scheme.
(define-library (niyarin condp)
(import (scheme base))
(export condp condp-right)
(begin
(define-syntax condp-aux
(syntax-rules (else left right)
((_ _ test (used ... ) (else expression ...) clauses ...)
(cond used ... (else expression ...)))
((_ _ test (used ...))
(cond used ...))
((_ left (test1 test2 ...) (used ... ) (test-target expression ... ) clause2 ... )
(condp-aux left (test1 test2 ...) (used ... ((test1 test-target test2 ... ) expression ... )) clause2 ... ))
((_ right (test ...) (used ... ) (test-target expression ... ) clause2 ... )
(condp-aux right (test ...) (used ... ((test ... test-target) expression ... )) clause2 ...))))
(define-syntax condp
(syntax-rules (else)
((_ test cond-clause ... )
(condp-aux left test () cond-clause ... ))))
(define-syntax condp-right
(syntax-rules (else)
((_ test cond-clause ...)
(condp-aux right test () cond-clause ... ))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment