Permalink
Browse files

New exported function: KIND.

  • Loading branch information...
1 parent 422946f commit 601925575c66ca3f550152a04ca950ab751a2315 @Hexstream committed Oct 25, 2012
Showing with 26 additions and 1 deletion.
  1. +24 −0 main.lisp
  2. +2 −1 package.lisp
View
@@ -181,3 +181,27 @@
(list to-keyword to))
(when (and by (/= by 1))
(list :by by)))))
+
+;; Stupid repetition, but I've had enough.
+(defun kind (keyword &key (errorp t))
+ '(values kind new-direction new-limit-kind)
+ (case keyword
+ ((:from :downfrom :upfrom)
+ (multiple-value-call #'values
+ :from
+ (ecase keyword
+ (:from (values nil nil))
+ (:downfrom (values '- nil))
+ (:upfrom (values '+ nil)))))
+ ((:to :upto :downto :below :above)
+ (multiple-value-call #'values
+ :to
+ (ecase keyword
+ (:to (values nil :inclusive))
+ (:downto (values '- :inclusive))
+ (:upto (values '+ :inclusive))
+ (:below (values '+ :exclusive))
+ (:above (values '- :exclusive)))))
+ (:by (values :by nil nil))
+ (t (when errorp
+ (error "~S is not a for-as-arithmetic keyword." keyword)))))
View
@@ -1,4 +1,5 @@
(cl:defpackage #:parse-number-range
(:use #:cl)
(:export #:parse
- #:unparse))
+ #:unparse
+ #:kind))

0 comments on commit 6019255

Please sign in to comment.