-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Along those lines, why is the apply necessary?

More clearly, and I encountered this with a different block of code
earlier today, repeat returns a lazy sequence.  Str does nothing to
evaluate that sequences, so (str (repeat ...)) returns a lazy sequence.

Why does (apply str (repeat ...)) evaluate the sequence?  The
documentation for apply does not mention that it will do so.

Generally I am having a lot of trouble with sequences because I am never
clear on when a lazy sequence will be evaluated strictly.

- --
Savanni


On 06/28/2010 01:14 PM, Nurullah Akkaya wrote:
> Hi José,
> 
> user=> (apply str (repeat 3 "code"))
> "codecodecode"
> 
> will give you what you want,
> if we break it down,
> 
> user=> (repeat 3 "code")
> ("code" "code" "code")
> 
> repeat will give you a sequence of xs,
> since you don't know the length of the
> sequence at compile time we apply str
> to the sequence
> 
> (apply str '("code" "code" "code"))
> 
> which basically expands to,
> 
> (str "code" "code" "code")
> 
> then you get,
> 
> "codecodecode"
> 
> 
> --
> Nurullah Akkaya
> http://nakkaya.com
> 
> 
> 
> 2010/6/27 José Luis Romero <tangu...@gmail.com>:
>> Hi! I am learning the core of clojure, and so far, I am loving it. But
>> I am not a lisp programmer (python, java, among others), but never
>> functional programming. I am practicing with codingbat.com, coding the
>> exercises on clojure. I am stuck with loops. I want to concatenate n
>> times a string. For example, given the parameters 3 and "code" the
>> output will be "codecodecode". How can I do a loop in order to get
>> this output.
>>
>> I know that this is a very newb question, any help will be
>> appreciated.
>>
>> --
>> 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
>>
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkwo6pEACgkQZIuDAZ4avD+JiQCgkiZg4ADytAL7ujIjq3S/73Up
msoAn0Z28vIwjTUXZb9bAN5o8LyDBUja
=I0Ni
-----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

Reply via email to