(defun split-on (symb list)
(with var pos = (position symb list)
var before = (take pos list)
var after = (rest (drop pos list))
do (values before after)))
(defun dsplit (symb list)
(if (member symb list)
(with
vars (before after) = (split-on symb list)
do (cons before (dsplit symb after)))
(list list)))
(defmacro $ (&rest list)
(with var split = (dsplit '$ list)
do (reduce (lambda (e tot) (append e (list tot))) split :from-end t)))
so now you can say stuff like
($ remove-if #'even? $ append a $ mapcar #f' list)
instead of
(remove-if #'even? (append a (mapcar #f' list)))
(defmacro p/ (&rest body)
(cons 'compose (mapcar (p/1 cons 'p/1) (dsplit '$ body))))
so now you can say
(/p + 1 $ * 2)
instead of
(lambda (x) (+ 1 (* 2 x)))
(notice this syntax looks a lot like haskell partial application + function composition: f x . g y . h z)
Ok, actually, I'm not sure if this highly unhigienic macro is a good idea, but whatever. looks fun enough.
Name:
Anonymous2007-08-02 0:04 ID:vo/LODUn
also, easy to use semi-currying, just in case you want it (I really don't know why though):
(defmacro defun-as (name fn)
`(setf (symbol-function ',name)
,fn))
(defun curry (f argsnum)
(lambda (&rest args)
(with var diff = (- argsnum (length args))
var appl = (lambda (&rest rest-args) (apply f (append args rest-args)))
do (if0 diff
(apply f args)
(curry appl diff)
))))
(defun-as +c (curry #'+ 2))
so
>(+c 1 2)
returns 3, as expected, and
>(funcall (+c 1) 2)
also returns 3.
Also I should check for negatives, but please forgive me, I need sleep.
>>7
Is that supposed to be a jab at Haskell or Factor?
(for retard's information: darcs is written in haskell)
Name:
Anonymous2007-08-02 21:21 ID:eRWtgBQ/
>>5
the point is, I can use a few things from haskell in lisp, just what I like. I'm not happy with pattern matching, it's cute for a few things but I feel it breaks abstraction on some cases. I also prefer dynamic over static.
Name:
Anonymous2009-03-06 13:04
Dsplit.
Name:
Anonymous2013-01-18 22:29
/prog/ will be spammed continuously until further notice. we apologize for any inconvenience this may cause.