Created
March 25, 2015 10:51
-
-
Save kobapan/6aedfd77257e5bc21024 to your computer and use it in GitHub Desktop.
elisp betweenマクロ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro between (var start end &optional $=) | |
`(cond ((null ,var) nil) | |
((numberp ,var) | |
(let (($$ (if ,$= '<= '<))) | |
(and (funcall $$ ,start ,var) (funcall $$ ,var ,end)))) | |
((stringp ,var) | |
(if ,$= | |
(or (and (string< ,start ,var) (string< ,var ,end)) (string= ,start ,var) (string= ,var ,end)) | |
(and (string< ,start ,var) (string< ,var ,end)))) | |
(t (error "comparing neither numberp nor stringp")))) | |
; (let ((n "b")) | |
; (between n "a" "c")) | |
; =>t | |
; (let ((n "a")) | |
; (between n "a" "c")) | |
; =>nil | |
; (let ((n "a")) | |
; (between n "a" "c" t)) | |
; =>t | |
; (let ((n 3)) | |
; (between n 1 3)) | |
; =>nil | |
; (let ((n 3)) | |
; (between n 1 3 t)) | |
; =>t | |
; (let ((n "a")) | |
; (between n 1 3)) | |
; =>error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment