Re: misunderstanding collection

2010-08-28 Thread Michał Marczyk
On 29 August 2010 00:11, John Newman wrote: > I am going to see if I can write a function that does: > > => (destructure [[][2]] signal) > (5 6 7 8) Note that the name is already taken by clojure.core/destructure, which is the engine behind all destructuring done by Clojure macros: user> (let [[

Re: misunderstanding collection

2010-08-28 Thread Mike Meyer
On Sat, 28 Aug 2010 18:11:41 -0400 John Newman wrote: > > #%3 %2 %1][%4 %5 %6]]] signal] -> [c b a d e f] > > Right, the names are superfluous. So are the extra set of brackets I > guess. Perhaps even better would be: > > (#[[_ _ _][_ _ _]] signal) > > Or if you wanted just the third ite

Re: misunderstanding collection

2010-08-28 Thread John Newman
> #%3 %2 %1][%4 %5 %6]]] signal] -> [c b a d e f] Right, the names are superfluous. So are the extra set of brackets I guess. Perhaps even better would be: (#[[_ _ _][_ _ _]] signal) Or if you wanted just the third item of the second collection: (#[[][2]] signal) Also, I took the signal

Re: misunderstanding collection

2010-08-28 Thread Mike Meyer
On Sat, 28 Aug 2010 12:23:04 -0400 John Newman wrote: > A reader macro for destructuring might be nifty, like #[...]. I don't think so. But first, we already have an "on-demand" destructuring facility: let. > So you could do things like: > > (#(map (partial reduce +) #a b c][d e f]]] %])

Re: misunderstanding collection

2010-08-28 Thread John Newman
A reader macro for destructuring might be nifty, like #[...]. So you could do things like: (#(map (partial reduce +) #a b c][d e f]]] %]) signal) Not sure if that'd be the right syntax, but you get the point. On Sat, Aug 28, 2010 at 12:08 PM, John Newman wrote: > Don't forget destructuring

Re: misunderstanding collection

2010-08-28 Thread John Newman
Don't forget destructuring: (for [[a b c] signal] (map (partial reduce +) [a b c])) and, ((fn [[[a b c][d e f]]] (map (partial reduce +) [a b c d e f])) signal) While messing around with that, I was wondering if there were some function that allowed you to destructure on-demand. Like, =>

Re: misunderstanding collection

2010-08-25 Thread gary ng
On Wed, Aug 25, 2010 at 7:06 AM, Glen Rubin wrote: > After toying around at the REPL I realize that I have been working > with a heretofore invalid understanding of collections.  For example, > working with the following collection(s): > > signal: > (((1 2 3 4) (2 3 4 5) (3 4 5 6)) ((3 4 5 6) (4 5

Re: misunderstanding collection

2010-08-25 Thread Meikel Brandmeyer
I vote for James'. On 25 Aug., 16:42, nickikt wrote: > To bad we don't have a voting system like on stackoverflow would be > nice to see witch answer got the most points. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send em

Re: misunderstanding collection

2010-08-25 Thread nickikt
To bad we don't have a voting system like on stackoverflow would be nice to see witch answer got the most points. -- 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 me

Re: misunderstanding collection

2010-08-25 Thread David Sletten
Hi Glen, You have two separate problems here. The question of understanding collections isn't really that tricky. Your variable 'signals' is simply a 2-element list. Conceptually it's no different than: (a b). But in your case each element is itself a 3-element list. An equivalent would be: ((a

Re: misunderstanding collection

2010-08-25 Thread James Reeves
I think you're getting confused. (map reduce + %) won't work, because the signature of the map function is (map func & colls). In other words, the second argument is expected to be a collection, but you've put in +, which is a function. When dealing with nested collections, you may want to work f

Re: misunderstanding collection

2010-08-25 Thread Meikel Brandmeyer
Hi, and again the for solution if nested anonymous functions are too hard to read. (for [signals signals-list] (map #(reduce + %) signals)) Sincerely Meikel -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to cloj

Re: misunderstanding collection

2010-08-25 Thread David Jagoe
Ahoy, On 25 August 2010 16:06, Glen Rubin wrote: > After toying around at the REPL I realize that I have been working > with a heretofore invalid understanding of collections.  For example, > working with the following collection(s): > > signal: > (((1 2 3 4) (2 3 4 5) (3 4 5 6)) ((3 4 5 6) (4 5

Re: misunderstanding collection

2010-08-25 Thread Luka Stojanovic
On Wed, 25 Aug 2010 16:06:15 +0200, Glen Rubin wrote: After toying around at the REPL I realize that I have been working with a heretofore invalid understanding of collections. For example, working with the following collection(s): signal: (((1 2 3 4) (2 3 4 5) (3 4 5 6)) ((3 4 5 6) (4 5 6 7)

Re: misunderstanding collection

2010-08-25 Thread Joost
On Aug 25, 4:06 pm, Glen Rubin wrote: > After toying around at the REPL I realize that I have been working > with a heretofore invalid understanding of collections.  For example, > working with the following collection(s): > > signal: > (((1 2 3 4) (2 3 4 5) (3 4 5 6)) ((3 4 5 6) (4 5 6 7) (5 6 7

Re: misunderstanding collection

2010-08-25 Thread Meikel Brandmeyer
Hi, On 25 Aug., 16:06, Glen Rubin wrote: > (map #(map reduce + %) signal) The error you got here is probably related to the inner map. It should probably read (map #(map (partial reduce +) %) signal) or (map (partial map #(reduce + %)) signal) Sincerely Meikel -- You received this message be

Re: misunderstanding collection

2010-08-25 Thread nickikt
"clojure sees 'signal' as 2 collections" thats wrong signals is one collection with two items. These happen to be collection but only the function that gets called by map carres what it gets. How can this (map #(map reduce + %) signal) work? (map ) does take 1 function and some collections

misunderstanding collection

2010-08-25 Thread Glen Rubin
After toying around at the REPL I realize that I have been working with a heretofore invalid understanding of collections. For example, working with the following collection(s): signal: (((1 2 3 4) (2 3 4 5) (3 4 5 6)) ((3 4 5 6) (4 5 6 7) (5 6 7 8))) I wanted to sum each individual list: e.g. (