Re: new learner question

2016-05-23 Thread Phil Virgo
Don't want to thank each of you individually - so to all who answered  - 
Thank-you!

On Monday, May 23, 2016 at 9:10:47 PM UTC-4, Phil Virgo wrote:
>
> I just starting to try and teach myself Clojure.  Kindly let me know if 
> there is a more appropriate place I should post simple questions.
>
>
> (def s '(1 1 1 4 99) 
>
> (take-while  #(= (first s) %) s)  ; works fine: (1 1 1)
>
> (take-while  #(= (first %) %) s)  ; IllegalArgumentException Don't know 
> how to create ISeq from: java.lang.Long  clojure.lang.RT.seqFrom 
> (RT.java:505)
>
> It appears as though "%" cannot be used within a nested function - but 
> this works 
>
> (#(prn (+ 3 %) % ) 5) ; works fine:  8 5
>
> Does anyone know what is the rule of statement construction being violated?
>
> ~thanks
>

-- 
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: new learner question

2016-05-23 Thread JvJ

>
>
>
> Nope, that's fine. (Although you can't nest one anonymous function inside 
> another as then it would be ambiguous what % refers to.)
>

To further clarify when anonymous functions can't be nested:

#(+ % (+ % (+ % (+ % ==> totally legal 

#(+ % (#(* 2 %) %)) ===> totally not legal

In the first example, % is always the same.  However, in the second 
example, the #() form tries to introduce a *new* function, which can't be 
nested with this syntax.

However.
#(+ % ((fn [x] (* 2 x)) %)) ===> totally fine.  You can nest as many 
functions as you want if you write them as (fn [] ...)

-- 
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: new learner question

2016-05-23 Thread Alex Miller


On Monday, May 23, 2016 at 8:10:47 PM UTC-5, Phil Virgo wrote:
>
> I just starting to try and teach myself Clojure.  Kindly let me know if 
> there is a more appropriate place I should post simple questions.
>

This is fine! You might also enjoy the #beginners room on the 
http://clojurians.net/ Slack for live chat. 

>
>
> (def s '(1 1 1 4 99) 
>
> (take-while  #(= (first s) %) s)  ; works fine: (1 1 1)
>
> (take-while  #(= (first %) %) s)  ; IllegalArgumentException Don't know 
> how to create ISeq from: java.lang.Long  clojure.lang.RT.seqFrom 
> (RT.java:505)
>

The anon function here is being invoked on the first value, which is 1 so 
that function becomes:

#(= (first 1) 1)

And the error is that (first 1) is being passed a number rather than 
something seqable. 
 

>
> It appears as though "%" cannot be used within a nested function
>

Nope, that's fine. (Although you can't nest one anonymous function inside 
another as then it would be ambiguous what % refers to.)
 

> - but this works 
>
> (#(prn (+ 3 %) % ) 5) ; works fine:  8 5
>

here this turns into:

#(prn (+ 3 5) 5) 

which is fine.

Hope that helps!
 

>
> Does anyone know what is the rule of statement construction being violated?
>
> ~thanks
>

-- 
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: new learner question

2016-05-23 Thread JvJ
Your use of % is syntactically correct.

However, think of what is happening in the second example.

Every time take-while invokes your function #(= (first %) %), % is bound to 
an element of the list s.

So, something like this would happen when take-while is checking the first 
element: (= (first 1) 1).

The exception just means that the function "first" can only work on 
sequences.  Numbers are not sequences.


On Monday, 23 May 2016 18:10:47 UTC-7, Phil Virgo wrote:
>
> I just starting to try and teach myself Clojure.  Kindly let me know if 
> there is a more appropriate place I should post simple questions.
>
>
> (def s '(1 1 1 4 99) 
>
> (take-while  #(= (first s) %) s)  ; works fine: (1 1 1)
>
> (take-while  #(= (first %) %) s)  ; IllegalArgumentException Don't know 
> how to create ISeq from: java.lang.Long  clojure.lang.RT.seqFrom 
> (RT.java:505)
>
> It appears as though "%" cannot be used within a nested function - but 
> this works 
>
> (#(prn (+ 3 %) % ) 5) ; works fine:  8 5
>
> Does anyone know what is the rule of statement construction being violated?
>
> ~thanks
>

-- 
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: new learner question

2016-05-23 Thread Dan Girellini
On May 23, 2016 at 6:10:46 PM, Phil Virgo (pwvi...@gmail.com) wrote:

(take-while  #(= (first %) %) s)  ; IllegalArgumentException Don't know how
to create ISeq from: java.lang.Long  clojure.lang.RT.seqFrom (RT.java:505)


Your problem is that take-while will call the predicate for each item in
the collection ’s’. So you’re calling first on each item in s and you can’t
call first on a number. Thus the error you got.


—dan.

-- 
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.


new learner question

2016-05-23 Thread Phil Virgo
I just starting to try and teach myself Clojure.  Kindly let me know if 
there is a more appropriate place I should post simple questions.


(def s '(1 1 1 4 99) 

(take-while  #(= (first s) %) s)  ; works fine: (1 1 1)

(take-while  #(= (first %) %) s)  ; IllegalArgumentException Don't know how 
to create ISeq from: java.lang.Long  clojure.lang.RT.seqFrom (RT.java:505)

It appears as though "%" cannot be used within a nested function - but this 
works 

(#(prn (+ 3 %) % ) 5) ; works fine:  8 5

Does anyone know what is the rule of statement construction being violated?

~thanks

-- 
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.