Re: Tranforming an ACL file: Comparing Clojure with Ruby

2011-03-04 Thread Stuart Halloway
On Thu, Mar 3, 2011 at 9:15 PM, Stefan Rohlfing stefan.rohlf...@gmail.com wrote: I personally find Stuart's suggestion to be the most readable. The use of the - macro makes the workflow quite easy to follow. Yes, both the - and - macros are useful. Unfortunately, about half of Clojure's

Re: Tranforming an ACL file: Comparing Clojure with Ruby

2011-03-04 Thread Mark Engelberg
On Fri, Mar 4, 2011 at 4:50 AM, Stuart Halloway stuart.hallo...@gmail.com wrote: This is hardly unfortunate! The API is carefully designed: object args come first, seq args come last. I didn't mean to imply that the first/last choice is random or arbitrary. I understand that the seq functions

Re: Tranforming an ACL file: Comparing Clojure with Ruby

2011-03-04 Thread Ken Wesson
On Fri, Mar 4, 2011 at 7:50 AM, Stuart Halloway stuart.hallo...@gmail.com wrote: This is hardly unfortunate! The API is carefully designed: object args come first, seq args come last. Eh, not always: conj, nth, and several others put seq args first, though cons can be used on seqs in place of

Re: Tranforming an ACL file: Comparing Clojure with Ruby

2011-03-04 Thread Ken Wesson
On Fri, Mar 4, 2011 at 12:34 PM, Stuart Halloway stuart.hallo...@gmail.com wrote: This is hardly unfortunate! The API is carefully designed: object args come first, seq args come last. Eh, not always: conj, nth, and several others put seq args first, though cons can be used on seqs in place

Re: Tranforming an ACL file: Comparing Clojure with Ruby

2011-03-04 Thread Stuart Halloway
This is hardly unfortunate! The API is carefully designed: object args come first, seq args come last. Eh, not always: conj, nth, and several others put seq args first, though cons can be used on seqs in place of conj and has the seq arg last. You may be right, but so far your chosen

Re: Tranforming an ACL file: Comparing Clojure with Ruby

2011-03-04 Thread Ken Wesson
On Fri, Mar 4, 2011 at 12:53 PM, Stuart Halloway stuart.hallo...@gmail.com wrote: In the context of chaining operators such as -, it is logical to consider both the input and output of the function. The functions listed under the Seq In, Seq Out section at http://clojure.org/sequences should

Tranforming an ACL file: Comparing Clojure with Ruby

2011-03-03 Thread Stefan Rohlfing
Dear Clojure Group, I am currently reading the online book Pro Githttps://docs.google.com/document/d/1pms_fnr0m2xlYH_4CB3pMeWBdIBlly4CQGMWuogOntg/edit?hl=en. In chapter 7.4 http://progit.org/book/ch7-4.html (section “Enforcing a User-Based ACL System”) there is a task of reading in an access

Tranforming an ACL file: Comparing Clojure with Ruby

2011-03-03 Thread Stefan Rohlfing
Dear Clojure Group, I am currently reading the online book Pro Git http://progit.org/book/. In chapter 7.4 http://progit.org/book/ch7-4.html (section “Enforcing a User-Based ACL System”) there is a task of reading in an access control list (ACL) file, such as the following # avail/unavail |

Re: Tranforming an ACL file: Comparing Clojure with Ruby

2011-03-03 Thread Stuart Halloway
Dear Clojure Group, I am currently reading the online book Pro Git. In chapter 7.4 (section “Enforcing a User-Based ACL System”) there is a task of reading in an access control list (ACL) file, such as the following # avail/unavail | users | path avail|nickh,pjhyett,defunkt,tpw

Re: Tranforming an ACL file: Comparing Clojure with Ruby

2011-03-03 Thread gaz jones
i was gonna suggest this: (let [users (- (split (slurp acl) #\n) (map #(split % #\|)) (map (fn [[a u p]] [a (split u #,) p])) (filter (fn [[a _ _]] (= avail a))) (mapcat (fn [[_ users path]] (map

Re: Tranforming an ACL file: Comparing Clojure with Ruby

2011-03-03 Thread Mark Engelberg
Don't be afraid to split your work across multiple functions. Not only is this clearer, but you can then test the functions independently. So something like this: (defn access-map-add-users [access-map users path] (apply merge-with into access-map (for [user users] {user [path]})))

Re: Tranforming an ACL file: Comparing Clojure with Ruby

2011-03-03 Thread Mark Engelberg
It's also worth noting that you can translate the Ruby code almost line for line if you make use of Clojure's atoms to adopt a more imperative approach. In general, it's more satisfying to find a pure functional way to solve a problem, but while you're transitioning from Ruby, it's not

Re: Tranforming an ACL file: Comparing Clojure with Ruby

2011-03-03 Thread Mark Engelberg
On Thu, Mar 3, 2011 at 7:35 PM, Mark Engelberg mark.engelb...@gmail.com wrote:        (when (not= avail avail) Whoops, should be: (when (= avail avail) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to

Re: Tranforming an ACL file: Comparing Clojure with Ruby

2011-03-03 Thread Stefan Rohlfing
Thank you all so much for helping me improve my code! I personally find Stuart's suggestion to be the most readable. The use of the - macro makes the workflow quite easy to follow. I hope that with some more experience I will be able to see these patterns myself and adapt my code accordingly.

Re: Tranforming an ACL file: Comparing Clojure with Ruby

2011-03-03 Thread Mark Engelberg
On Thu, Mar 3, 2011 at 9:15 PM, Stefan Rohlfing stefan.rohlf...@gmail.com wrote: I personally find Stuart's suggestion to be the most readable. The use of the - macro makes the workflow quite easy to follow. Yes, both the - and - macros are useful. Unfortunately, about half of Clojure's

Re: Tranforming an ACL file: Comparing Clojure with Ruby

2011-03-03 Thread Stefan Rohlfing
You are perfectly right. Organizing the code so that - or - an be applied is key here. Unfortunately, only if all functions to be composed follow the same pattern of either 'insert first' or 'insert last' can these macros be used. -- You received this message because you are subscribed to the

Re: Tranforming an ACL file: Comparing Clojure with Ruby

2011-03-03 Thread Justin Kramer
'for' can be handy when unpacking compound lines: (ns foobar (:require [clojure.java.io :as io])) (defn parse-acl [acl-file] (with-open [r (io/reader acl-file)] (apply merge-with into (for [[status users path] (map #(.split % \\|) (line-seq r)) :when (= avail status)

Re: Tranforming an ACL file: Comparing Clojure with Ruby

2011-03-03 Thread Stefan Rohlfing
Thanks for your suggestion. Using the 'for' macro here makes the main part of the parse function much clearer. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new