|
|
|
|
|
by rauhl
2282 days ago
|
|
> Ada is pretty much still the only language that has this. Common Lisp does too: (deftype quantity () '(integer 0 240))
(defun foo (x)
(declare (type quantity x))
(1+ x))
(foo 1) → 2
(foo -1) → ERROR
(defun valid-username-p (string)
(and (< 8 (length string) 24)
(every (lambda (char)
(find char "abcdefghijklmnopqrstuvwxyz0123456789-_=./" :test #'char=))
string)))
(typep "foo" 'username) → NIL
(typep "foobarbaz" 'username) → T
(typep "foobar-baz" 'username) → T
(typep "foobar-baz " 'username) → NIL
Common Lisp is pretty awesome. |
|