PasteRack.org
Paste # 33808
2020-09-16 20:37:04

Forked from paste # 16893.

Fork as a new paste.

Paste viewed 560 times.


Embed:

cond macro (corrected)

  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 [(~literal else) consequent])
  10.      #'(cond [#t 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