Re: how to add a function to a collection ?

2014-05-22 Thread James Reeves
You have a couple of problems in your code. Let's take it a line at a time:

(defn f1 [msg] (fn [msg] (println (str "hello " msg

Here you have two "msg" arguments. The inner one will override the outer
one. If you want both, they need to be different names. For example:

(defn f1 [greet] (fn [name] (println greet name)))

The outer function sets the greeting, while the inner one sets the name:

((f1 "hello") "joe") => "hello joe"

You then define an empty collection:

(def collection '())

Which is fine, and the perform a cons:

(cons collection (seq (f1 "xxx")))

However, you have the arguments backward, and you've added in a "seq" that
will just cause an error. Functions cannot be transformed directly into
seqs.

Instead, try:

(cons (f1 "hello") collection)

This should work fine.

- James


On 22 May 2014 14:14, sorin cristea  wrote:

>
>  I see,
>  this is the problem even if I call correct the function, sorry for that
> missing function parameter, when it will try to add the result of 'f1 "xxx"
> to 'collection' it will try to   transform the result, fn..., to an type
> ISeq, this is what collection support, and there appear the problem
>
>
>
> *(defn f1 [msg] (fn[msg](println (str "hello " msg(def collection
> '())(cons  collection (seq (f1 "xxx")))*
>
> 'IllegalArgumentException Don't know how to create ISeq from:
> ro.srncristea.blogspot.clojure.concurrency$f1$fn__2158
> clojure.lang.RT.seqFrom (RT.java:505)'
>
> thanks,
> sorin.
>
>
> On Thursday, May 22, 2014 3:04:39 PM UTC+3, Di Xu wrote:
>>
>>(defn *f1* [msg] (*fn[msg](println (str "hello " msg))*))
>>>   (def collection '())
>>>   (cons (f1) collection)
>>>
>>
>> ​change ​ (cons (f1) collection) into  (cons (f1 "xxx") collection)
>>
>  --
> 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
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to add a function to a collection ?

2014-05-22 Thread sorin cristea

 I see, 
 this is the problem even if I call correct the function, sorry for that 
missing function parameter, when it will try to add the result of 'f1 "xxx" 
to 'collection' it will try to   transform the result, fn..., to an type 
ISeq, this is what collection support, and there appear the problem



*(defn f1 [msg] (fn[msg](println (str "hello " msg(def collection 
'())(cons  collection (seq (f1 "xxx")))*

'IllegalArgumentException Don't know how to create ISeq from: 
ro.srncristea.blogspot.clojure.concurrency$f1$fn__2158  
clojure.lang.RT.seqFrom (RT.java:505)'

thanks,
sorin.

On Thursday, May 22, 2014 3:04:39 PM UTC+3, Di Xu wrote:
>
>   (defn *f1* [msg] (*fn[msg](println (str "hello " msg))*))
>>   (def collection '())
>>   (cons (f1) collection)
>>
>
> ​change ​ (cons (f1) collection) into  (cons (f1 "xxx") collection)
>

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to add a function to a collection ?

2014-05-22 Thread Di Xu
>
>   (defn *f1* [msg] (*fn[msg](println (str "hello " msg))*))
>   (def collection '())
>   (cons (f1) collection)
>

​change ​ (cons (f1) collection) into  (cons (f1 "xxx") collection)

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


how to add a function to a collection ?

2014-05-22 Thread sorin cristea
Hi all,
 do you know how is possible to add a function result, that is another 
function, to a collection, a list for example:

  (defn *f1* [msg] (*fn[msg](println (str "hello " msg))*))
  (def collection '())
  (cons (f1) collection)
 
in this situation f1 must be of type ISeq to can be added to 'collection'. 
Do you know how is this possible because if I call (cons (seq (f1)) 
collection) it doesn't work.

Thanks,
Sorin

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.