Re: Use repeat with a function argument

2012-12-25 Thread Stuart Sierra
`repeat` takes a value and returns a sequence of that value.

There's another function, `repeatedly`, which takes a function and returns 
a sequence of values returned by calling that function.

-S

-- 
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 - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Use repeat with a function argument

2012-12-24 Thread Marko Topolnik
I deleted my answer minutes after posting. The phrase "function argument" 
is ambiguous ("argument to function", "argument which is a function") and I 
jumped to the wrong conclusion.

On Monday, December 24, 2012 7:00:48 PM UTC+1, Sean Corfield wrote:
>
> He's repeating a function argument, not a function.
>
> Meikel is correct that the second expression causes (some #{0} ...) to 
> return nil when number is not a multiple of 3 or 5, and then zero? fails. 
> As he suggests...
>
> (reduce + (filter (fn [number] (some zero? (map mod (take 2 (repeat 
> number)) [3 5]))) (range 1 1000)))
>
> ...works (and returns 233168)
>
> Sean
>
> On Sun, Dec 23, 2012 at 11:56 PM, Marko Topolnik 
> 
> > wrote:
>
>> *repeat* is not supposed to work with functions, but there's *repeatedly.
>> *
>>
>>
>> On Monday, December 24, 2012 4:20:23 AM UTC+1, Andrew Care wrote:
>>>
>>> I'm trying to use repeat with a function argument. This works:
>>>
>>> (reduce + (filter (fn [number] (zero? (some #{0} (map mod (take 2 
>>> (repeat 9)) [3 5] (range 1 1000)))
>>>
>>> This doesn't:
>>>
>>> (reduce + (filter (fn [number] (zero? (some #{0} (map mod (take 2 
>>> (repeat number)) [3 5] (range 1 1000)))
>>>
>>> Why can I use (repeat 9) and not (repeat number)?
>>>
>>
>>

-- 
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 - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Use repeat with a function argument

2012-12-24 Thread Sean Corfield
He's repeating a function argument, not a function.

Meikel is correct that the second expression causes (some #{0} ...) to
return nil when number is not a multiple of 3 or 5, and then zero? fails.
As he suggests...

(reduce + (filter (fn [number] (some zero? (map mod (take 2 (repeat
number)) [3 5]))) (range 1 1000)))

...works (and returns 233168)

Sean

On Sun, Dec 23, 2012 at 11:56 PM, Marko Topolnik
wrote:

> *repeat* is not supposed to work with functions, but there's *repeatedly.*
>
>
> On Monday, December 24, 2012 4:20:23 AM UTC+1, Andrew Care wrote:
>>
>> I'm trying to use repeat with a function argument. This works:
>>
>> (reduce + (filter (fn [number] (zero? (some #{0} (map mod (take 2 (repeat
>> 9)) [3 5] (range 1 1000)))
>>
>> This doesn't:
>>
>> (reduce + (filter (fn [number] (zero? (some #{0} (map mod (take 2 (repeat
>> number)) [3 5] (range 1 1000)))
>>
>> Why can I use (repeat 9) and not (repeat number)?
>>
>
>

-- 
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 - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Use repeat with a function argument

2012-12-24 Thread Ben Wolfson
of course repeat works with functions:

user=> (take 4 (map #(% 4) (repeat inc)))
(5 5 5 5)

On Sun, Dec 23, 2012 at 11:56 PM, Marko Topolnik
 wrote:
> repeat is not supposed to work with functions, but there's repeatedly.
>
>
> On Monday, December 24, 2012 4:20:23 AM UTC+1, Andrew Care wrote:
>>
>> I'm trying to use repeat with a function argument. This works:
>>
>> (reduce + (filter (fn [number] (zero? (some #{0} (map mod (take 2 (repeat
>> 9)) [3 5] (range 1 1000)))
>>
>> This doesn't:
>>
>> (reduce + (filter (fn [number] (zero? (some #{0} (map mod (take 2 (repeat
>> number)) [3 5] (range 1 1000)))
>>
>> Why can I use (repeat 9) and not (repeat number)?
>
> --
> 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 - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en



-- 
Ben Wolfson
"Human kind has used its intelligence to vary the flavour of drinks,
which may be sweet, aromatic, fermented or spirit-based. ... Family
and social life also offer numerous other occasions to consume drinks
for pleasure." [Larousse, "Drink" entry]

-- 
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 - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Use repeat with a function argument

2012-12-23 Thread Marko Topolnik
*repeat* is not supposed to work with functions, but there's *repeatedly.*

On Monday, December 24, 2012 4:20:23 AM UTC+1, Andrew Care wrote:
>
> I'm trying to use repeat with a function argument. This works:
>
> (reduce + (filter (fn [number] (zero? (some #{0} (map mod (take 2 (repeat 
> 9)) [3 5] (range 1 1000)))
>
> This doesn't:
>
> (reduce + (filter (fn [number] (zero? (some #{0} (map mod (take 2 (repeat 
> number)) [3 5] (range 1 1000)))
>
> Why can I use (repeat 9) and not (repeat number)?
>

-- 
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 - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Use repeat with a function argument

2012-12-23 Thread Meikel Brandmeyer
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi,

Am 24.12.12 04:20, schrieb Andrew Care:

> Why can I use (repeat 9) and not (repeat number)?

Because you call zero? on nil, which doesn't work. Instead of (zero?
(some #{0} ...)) use (some zero? ...).

Kind regards
Meikel


-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.18 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with undefined - http://www.enigmail.net/

iQIcBAEBAgAGBQJQ2Ao1AAoJEM2sO9pIirXjqVEP/34UYmSbw3P0M22KmCCXR+pZ
XKoFOJ3pFbTseBekFPrAIoHwIPARuUxoQTCheBuszU2o8j2bXku2sRr614KR8XE0
2CzNGVswd7dN7X4IeuXoe5O9aknYpSFNmCI38eBDc07PUR8i6m4e0/Y/95/pckTO
1W6jnSf6pOYbUjDKp7U//dfMrfvAZKvOJ5eo40I+mq3qKB4OV4FjWv5m4D/L+rZt
fu/5RId+VWukbnxNTWUBInTZ/Z4rlbgPDLZ3EcqJNHQzetRjZlRH+/X6zlmFnF/7
Vffduzf374KdzVPOIWabEzGLE/yi/MFAyo/WCzk4n4qLoFS0Dnhi9lG6QExcwd1S
VhOY4ZAc3MbDdBea6tiBUJeLCTG4A9k/48/RGlrtM9UjqkkHiXzQk2d7pK7jfYkh
cmLPA4oKDkmccZAqd99J9A0/LS1wpnGXh95POlKrgs3n9PcSEAlyU+OA5UU/KiKD
wciXvMwfjllw0SmoFHNvNJZL4rjmAce2vWf88RyitquxF468KUiZtjDy+tLauFH+
QS8mw+P1vAzZ1O3ul3W/YJt3ypi4h7paHllDrhRS4TiPYF7zUSfmj1f5gSCTf8d+
5EJ9bsMIJINRZ8ByhJzNojVjWBq/t8WdpMbAavObfAZ2hoT8zqFBk2uewPKpM2ve
mRVtJejqeU2+Y2y8IPEc
=Mqq2
-END PGP SIGNATURE-

-- 
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 - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Use repeat with a function argument

2012-12-23 Thread Andrew Care
I'm trying to use repeat with a function argument. This works:

(reduce + (filter (fn [number] (zero? (some #{0} (map mod (take 2 (repeat 
9)) [3 5] (range 1 1000)))

This doesn't:

(reduce + (filter (fn [number] (zero? (some #{0} (map mod (take 2 (repeat 
number)) [3 5] (range 1 1000)))

Why can I use (repeat 9) and not (repeat number)?

-- 
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 - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en