Re: apply inc

2013-08-11 Thread drclj
Thanks everyone, in the apply function source code I see

([^clojure.lang.IFn f args]
 (. f (applyTo (seq args



Seems the (applyTo (seq args)) returns arg parameters,

And the f is invoked only once:

(. f args)






-- 
-- 
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/groups/opt_out.




Re: apply inc

2013-08-11 Thread Devin Walters
Is there an implicit question there? If so, does this 
(https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/IFn.java) 
help?

'(Devin Walters)

On Aug 10, 2013, at 10:55 PM, drclj deepikaro...@gmail.com wrote:

 Thanks everyone, in the apply function source code I see
 
 ([^clojure.lang.IFn f args]
  (. f (applyTo (seq args
 
 
 
 Seems the (applyTo (seq args)) returns arg parameters,
 
 And the f is invoked only once:
 
 (. f args)
 
 
 
 
 
 
 -- 
 -- 
 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/groups/opt_out.
  
  

-- 
-- 
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/groups/opt_out.




Re: apply inc

2013-08-11 Thread Marshall Bockrath-Vandegrift
drclj deepikaro...@gmail.com writes:

 Thanks everyone, in the apply function source code I see

 ([^clojure.lang.IFn f args]
 (. f (applyTo (seq args

 Seems the (applyTo (seq args)) returns arg parameters,

 And the f is invoked only once:

 (. f args)

I think you’re missing that `.` is a special form with special
evaluation rules.  The following forms are all equivalent:

(. f (applyTo (seq args))
(. f applyTo (seq args))
(.applyTo f (seq args))

With the last being syntactic sugar converted during macro-expansion to
the middle form.

So there’s no `applyTo` *function*, just the `applyTo` *method* of IFn
instance `f`.

OOC, do you have a background using R or similar languages?  I was
confused myself learning R, because what R calls `apply` is nothing like
what Lisps call `apply` and (as others in this thread pointed out) is
more similar to what Clojure calls `map`.

-Marshall

-- 
-- 
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/groups/opt_out.


Re: apply inc

2013-08-11 Thread drclj

Looking at it as

(. f applyTo (seq args)) 

The object instance of IFn  'f' calls the method 'applyTo' with sequence 
'args'.

From http://clojure.org/java_interop
(*.* instance-expr member-symbol)(*.* instance-expr (method-symbol args*)) 
or(*.* instance-expr method-symbol args*)


That makes perfect sense. 


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/groups/opt_out.




apply inc

2013-08-10 Thread drclj
Hi there:

Why does 

(apply str [2 3]) work

and not

(apply inc [4 5])

though 

(apply inc [4])

does work?


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/groups/opt_out.




Re: apply inc

2013-08-10 Thread Andy Fingerhut
(apply str [2 3]) does the same thing as (str 2 3), which is to attempt to
convert each of its args to a string, then concatenate them all.

(apply inc [4 5]) does the same thing as (inc 4 5), which is to throw an
exception because inc takes exactly one argument and returns that value
plus 1.

This site has more examples of apply, and many other Clojure functions, too:

http://clojuredocs.org/clojure_core/clojure.core/apply

Andy


On Sat, Aug 10, 2013 at 7:21 AM, drclj deepikaro...@gmail.com wrote:

 Hi there:

 Why does

 (apply str [2 3]) work

 and not

 (apply inc [4 5])

 though

 (apply inc [4])

 does work?


 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/groups/opt_out.




-- 
-- 
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/groups/opt_out.




Re: apply inc

2013-08-10 Thread Softaddicts
How many args does inc supports ? Only one.
(apply inc [ 1 3 ]) is the same as (inc 1 3) which would also trigger an arity 
exception.

apply does not call the given fn on each item in the collection it's given,
it calls it once with the whole collection as the argument list. 

(map inc [1 3]) calls inc on every item in the vector and would return (2 4).

Hope it's clear.

Luc P.


 Hi there:
 
 Why does 
 
 (apply str [2 3]) work
 
 and not
 
 (apply inc [4 5])
 
 though 
 
 (apply inc [4])
 
 does work?
 
 
 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/groups/opt_out.
 
 
 
--
Softaddictslprefonta...@softaddicts.ca sent by ibisMail from my ipad!

-- 
-- 
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/groups/opt_out.




Re: apply inc

2013-08-10 Thread Christian Sperandio
When you write (apply inc [4 5]) it's like
(inc 4 5)
But the inc function accepts only one argument.

-- 
-- 
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/groups/opt_out.