Skip to content

Instantly share code, notes, and snippets.

@buzztaiki
Created June 2, 2013 03:19
Show Gist options
  • Select an option

  • Save buzztaiki/5692510 to your computer and use it in GitHub Desktop.

Select an option

Save buzztaiki/5692510 to your computer and use it in GitHub Desktop.
Emacs24.1から入ったpcaseが案外パターンマッチできてる。
(defun test-pcase (x)
(pcase x
(1 'one)
((pred numberp) (list 'number x))
(`(,a ,b . ,_) (list 'list a b))
(else (list 'else else))))
@buzztaiki
Copy link
Copy Markdown
Author

結果はこんな感じ

(test-pcase 1)
=> one
(test-pcase 10)
=> (number 10)
(test-pcase '(1 2 3 4))
=> (list 1 2)
(test-pcase '(1))
=> (else (1))
(test-pcase "a")
=> (else "a")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment