;===============================================================
; Predicates =?, >? and friends
(dolist (predicate '(< > = <= >= !=))
(set 'left (sym (append (string predicate) "?")))
(set 'right (expand (lambda(x)
(expand (lambda(y)
(predicate y x))
'x))
'predicate))
(set left right))
(println (filter (<=? 3) '(1 2 3 4 5 1 2 3 4 5)))
(println (map (=? 4) '(1 2 3 4 5 1 2 3 4 5)))
(println (clean (>? 1) '(1 2 3 4 5 1 2 3 4 5)))
(exit)
RESULTS:
(1 2 3 1 2 3)
(nil nil nil true nil nil nil nil true nil)
(1 1)
The Predicates =?, >? and Friends.
Subscribe to:
Post Comments (Atom)
I like watching you program, Kasimir! creative, like a musician...
ReplyDeletea less creative way:
(find-all 3 '(1 2 3 4 5 1 2 3 4 5) $0 >=)
;-> (1 2 3 1 2 3)
(find-all 1 '(1 2 3 4 5 1 2 3 4 5) $0 >=)
;-> (1 1)
You have a crazy beard, and Lisp derivatives breed like rabbits.
ReplyDeleteBuilt-in curry is much faster then handmade one:
ReplyDelete(map (curry = 3) '(1 2 3 4 5 6))
But I like this technique of generating the "postfixed" versions of existing functions, too! My favorite is here (the surronding text is in Russian, bud you don't need to read it: newlisp itself is enough! ;-)
Yes, your right that curry is faster than =?. At least their results (=? 3) and (curry = 3) are about equally fast!
ReplyDeleteGood code that one with not& etc. I didn't know it is so simple.