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
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
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
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
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
> (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
> 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
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))]
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
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)] (*
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
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
12 matches
Mail list logo