Positional Partial application for Clojure

Discussion of other Lisp dialects (Arc, Clojure, AutoLisp, XLISP, etc.)
Post Reply
VincentToups
Posts: 9
Joined: Tue Jul 01, 2008 1:15 pm

Positional Partial application for Clojure

Post by VincentToups » Fri Oct 31, 2008 7:19 am

Here is a quick little utility for positional-partial application in clojure, similar to cut from srfi 26 for Scheme, but a function, rather than syntax.

Code: Select all

(map (plx cons 'head :_) '((1 2) (3 4) (5 6)))
;;=> ((head 1 2) (head 3 4) (head 5 6))
(map (plx list 'head :_ 'end) '( middle mean meat )) 
;;=> ((head middle end) (head mean end) (head meat end))
If for some reason you need to pass a :_ keyword to a function you can specify another "leave open" sigil of any value by adding it to the function call.

Code: Select all

((plx :pass + :pass 1) 4)
;;=> 5
This code is available from my mercurial repository hosted at freeHg. Just:

Code: Select all

hg clone http://freehg.org/u/VincentToups/clojure-libs/ 
And add that to your classpath. Then you can use it by

Code: Select all

(clojure/ns my-code (:use toups.functional))
;;; Clojure Code
Maybe someone besides me will find it useful.

Unne
Posts: 32
Joined: Sat Jun 28, 2008 6:10 pm
Location: Oregon
Contact:

Re: Positional Partial application for Clojure

Post by Unne » Fri Oct 31, 2008 11:47 am

Aside from being able to specify your own symbol for the magic argument, how does this differ from the built-in:

Code: Select all

(map #(cons 'head %) '((1 2) (3 4) (5 6)))
(map #(list 'head % 'end) '(middle mean meat))

VincentToups
Posts: 9
Joined: Tue Jul 01, 2008 1:15 pm

Re: Positional Partial application for Clojure

Post by VincentToups » Fri Oct 31, 2008 11:54 am

Well, it is a function.

Now that the # syntax is brought to my attention, this is sort of silly.

Unne
Posts: 32
Joined: Sat Jun 28, 2008 6:10 pm
Location: Oregon
Contact:

Re: Positional Partial application for Clojure

Post by Unne » Fri Oct 31, 2008 12:43 pm

No big deal, clearly someone else already thought it was a good idea. Some of the other libraries on your site look interesting. Have you considered contributing some to clojure-contrib?

VincentToups
Posts: 9
Joined: Tue Jul 01, 2008 1:15 pm

Re: Positional Partial application for Clojure

Post by VincentToups » Sat Nov 01, 2008 6:22 pm

There really isn't that much I have to contribute but I have a large set of libraries in Scheme which would be nice to port.

Things like polynomial algebra and curve-fitting and so forth.

Post Reply