Re: List comprehension and sets

2011-05-24 Thread Alan Malloy
On May 24, 10:36 am, Ambrose Bonnaire-Sergeant wrote: > On Wed, May 25, 2011 at 12:55 AM, Alex Robbins < > > alexander.j.robb...@gmail.com> wrote: > > What is the difference between > > (into #{} (for x..)) > > and > > (set (for x ..)) > > Is one preferred? > > I don't think one is preferr

Re: List comprehension and sets

2011-05-24 Thread Ambrose Bonnaire-Sergeant
On Wed, May 25, 2011 at 12:55 AM, Alex Robbins < alexander.j.robb...@gmail.com> wrote: > What is the difference between > (into #{} (for x..)) > and > (set (for x ..)) > Is one preferred? > > I don't think one is preferred over the other in general. Personally I prefer into, I find it gen

Re: List comprehension and sets

2011-05-24 Thread Ambrose Bonnaire-Sergeant
On Wed, May 25, 2011 at 12:20 AM, Mark Engelberg wrote: > Scala's approach to comprehensions is to automatically produce the > same type of collection that is used first in your comprehension. > Clojure's approach is to always produce a lazy sequence which can then > be "poured" into the collectio

Re: List comprehension and sets

2011-05-24 Thread Alex Robbins
What is the difference between (into #{} (for x..)) and (set (for x ..)) Is one preferred? Thanks! Alex On Tue, May 24, 2011 at 11:20 AM, Mark Engelberg wrote: > Scala's approach to comprehensions is to automatically produce the > same type of collection that is used first in your compre

Re: List comprehension and sets

2011-05-24 Thread Mark Engelberg
Scala's approach to comprehensions is to automatically produce the same type of collection that is used first in your comprehension. Clojure's approach is to always produce a lazy sequence which can then be "poured" into the collection of your choice using "into". Both approaches have their merits

Re: List comprehension and sets

2011-05-24 Thread MarisO
> (set (for [x (range 4)] (* 4 x))) > ;=> #{0 4 8 12} > > Does that help? yes, thank you. -- 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 members are moderated

Re: List comprehension and sets

2011-05-24 Thread MarisO
> Does this actually yield a set in Scala? yes, it does > What is p()? A set constructor? p(i) reads i-nth element from a vector def selectRow(p: Vector[Int], i: Int) = { for (i <- (i - i % 9 to i - i % 9 + 8).toSet[Int]) yield p(i) } -- You received this message because you are subscri

Re: List comprehension and sets

2011-05-24 Thread Andreas Kostler
Hi, try (set (for [x (range 4)] (* x 4))) Cheers Andreas On 24/05/2011, at 8:40 PM, MarisO wrote: > Is it possible to use list comprehension to generate a set ? > For example in scala I can do: > > for (i <- (2 to 8).toSet[Int]) yield p(i) > > In clojure this > > (for [ x (set (range 4))]

Re: List comprehension and sets

2011-05-24 Thread Ambrose Bonnaire-Sergeant
On Tue, May 24, 2011 at 6:40 PM, MarisO wrote: > Is it possible to use list comprehension to generate a set ? > For example in scala I can do: > > for (i <- (2 to 8).toSet[Int]) yield p(i) > > Does this actually yield a set in Scala? What is p()? A set constructor? Thanks, Ambrose -- You rece

Re: List comprehension and sets

2011-05-24 Thread Baishampayan Ghose
On Tue, May 24, 2011 at 4:10 PM, MarisO wrote: > Is it possible to use list comprehension to generate a set ? > For example in scala I can do: > > for (i <- (2 to 8).toSet[Int]) yield p(i) > > In clojure this > > (for [ x (set (range 4))] (* 4 x)) > >  generates a list. (set (for [x (range 4)] (*

Re: List comprehension and sets

2011-05-24 Thread Ambrose Bonnaire-Sergeant
Hi Maris, `into` is a useful function for this case. user>> (into #{} (for [ x (set (range 4))] (* 4 x))) #{0 4 8 12} You can use it for lists, maps, vectors. user>> (into {} '([:a "a"] [:b "b"])) {:a "a", :b "b"} user>> (into [] '([:a "a"] [:b "b"])) [[:a "a"] [:b "b"]] Thanks, Ambrose On Tu

List comprehension and sets

2011-05-24 Thread MarisO
Is it possible to use list comprehension to generate a set ? For example in scala I can do: for (i <- (2 to 8).toSet[Int]) yield p(i) In clojure this (for [ x (set (range 4))] (* 4 x)) generates a list. -- You received this message because you are subscribed to the Google Groups "Clojure" gr