Skip to content

Instantly share code, notes, and snippets.

@kobapan
Created March 25, 2015 10:51
Show Gist options
  • Save kobapan/6aedfd77257e5bc21024 to your computer and use it in GitHub Desktop.
Save kobapan/6aedfd77257e5bc21024 to your computer and use it in GitHub Desktop.
elisp betweenマクロ
(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