PasteRack.org
Paste # 13481
2020-02-07 15:01:19

Forked from paste # 74811.

Fork as a new paste.

Paste viewed 340 times.


Embed:

  1. #lang racket/base
  2.  
  3. (require racket/match)
  4.  
  5. #;
  6. (define (first-item xs)
  7.   (match xs
  8.     [(list)           "oh no empty"]
  9.     [(cons this more) this]))
  10.  
  11. ;; Using quasiquote patterns
  12. (define (first-item xs)
  13.   (match xs
  14.     [`()              "oh no empty"]
  15.     [`(,this . ,more) this]))
  16.  
  17. (first-item (list))
  18. (first-item (list 1))
  19. (first-item (list 1 2))

=>

"oh no empty"

1

1