Positional Partial application for Clojure

Discussion of other Lisp dialects (Arc, Clojure, AutoLisp, XLISP, etc.)

Positional Partial application for Clojure

Postby 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.
VincentToups
 
Posts: 9
Joined: Tue Jul 01, 2008 1:15 pm

Re: Positional Partial application for Clojure

Postby 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))
Unne
 
Posts: 32
Joined: Sat Jun 28, 2008 6:10 pm
Location: Oregon

Re: Positional Partial application for Clojure

Postby 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.
VincentToups
 
Posts: 9
Joined: Tue Jul 01, 2008 1:15 pm

Re: Positional Partial application for Clojure

Postby 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?
Unne
 
Posts: 32
Joined: Sat Jun 28, 2008 6:10 pm
Location: Oregon

Re: Positional Partial application for Clojure

Postby 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.
VincentToups
 
Posts: 9
Joined: Tue Jul 01, 2008 1:15 pm


Return to Other Dialects

Who is online

Users browsing this forum: No registered users and 0 guests

cron