PasteRack.org
Paste # 95324
2020-09-16 18:59:19

Fork as a new paste.

Paste viewed 538 times.


Embed:

cond macro

  1. #lang racket
  2.  
  3. (begin-for-syntax
  4.   (require syntax/parse))
  5.  
  6. (define-syntax (cond stx)
  7.   (syntax-parse stx
  8.     [(cond) #'(void)]
  9.     [(cond [else consequent])
  10.      #'consequent]
  11.     [(cond [condition consequent])
  12.      #'(if condition consequent
  13.            (cond))]
  14.     [(cond [condition consequent]
  15.            remaining-clauses ...+)
  16.      #'(if condition consequent
  17.            (cond remaining-clauses ...))]))
  18.  
  19. (cond [(< 2 1) 'hi]
  20.       [(> 2 2) 'bye]
  21.       [(> 3 3) 'later]
  22.       [else 'cya])

=>

'cya