Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

so you don't like parenthesis

Name: Anonymous 2007-08-01 23:41 ID:Y7H5mdu/


(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)))

fairly unimpressive, I know.

(defmacro p/1 (f &rest body)
    (let ((args (gensym)))
        `(lambda (&rest ,args)
            ,(append `(apply (function ,f)) body (list args)))))

(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: Anonymous 2007-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.

Name: Anonymous 2007-08-02 1:45 ID:Heaven

stop using lisp

Name: Anonymous 2007-08-02 2:15 ID:cmoXvRuV

>>3
stop being a fag

Name: Anonymous 2007-08-02 3:12 ID:QD0Y8JvU

I see lisp fags are finally coming to terms with the fact that Haskell > LISP

Name: Anonymous 2007-08-02 3:14 ID:Heaven

>>5
i guess pretty soon the haskell fags will start coming to terms with the fact that factor > haskell.

Name: Anonymous 2007-08-02 3:49 ID:QD0Y8JvU

CENSORED@paris:~/code$ darcs get http://factorcode.org/repos/
Copying patch 183 of 4050...

wow this is only going to take a day

Name: Anonymous 2007-08-02 4:22 ID:7BjIkM+B

>>1,2
Get rid of all the parentheses and I will take a look.  Macrofags say they can implement C-syntax in Lisp in 2 lines of code.

Name: Anonymous 2007-08-02 11:25 ID:Vb0Oztyn

>>8
hahaha macrofags

Name: Anonymous 2007-08-02 17:41 ID:bkWGkMo6

>>7
How do I used --partial

Name: Anonymous 2007-08-02 21:05 ID:hMvLi/m9

>>7
Is that supposed to be a jab at Haskell or Factor?

(for retard's information: darcs is written in haskell)

Name: Anonymous 2007-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: Anonymous 2009-03-06 13:04

Dsplit.

Name: Anonymous 2013-01-18 22:29

/prog/ will be spammed continuously until further notice. we apologize for any inconvenience this may cause.

Don't change these.
Name: Email:
Entire Thread Thread List