import functions from different .clj files

2014-07-12 Thread sorin cristea

Hi all,

I have file fileB.clj
 (ns a.b.c)
   (defn inc-sample [no] (+ no 1))

and file fileA.clj
  (ns a.b.c.d 
 (:require [a.b.c.fileB :as fB]))

  (defn method-a [] 
(println number incremented (fB/inc-sample 2))
  )

 in fileA.clj I'm not able to see the functions from fileB.clj even I use 
:require to import namespace of fileB. Can tell me anyone what is wrong or 
how to do to see the functions from fileB.clj in fileA.clj ?

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.


Re: import functions from different .clj files

2014-07-12 Thread sorin cristea

 I want to do something like when you import a file from a clojure package, 
for example the case of jdbc, you wrote* (:require [clojure.java.jdbc :as 
sql])* than you call functions from clojure jdbc with statement 
(sql/fc-name..)

 but seams that this not working in case you have two .clj files or I do 
something wrong.




On Saturday, July 12, 2014 7:15:56 PM UTC+3, Mike Fikes wrote:

 And alternatively you could declare the first namespace as being 
 a.b.c.fileB

-- 
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: macro - unquote

2014-06-20 Thread sorin cristea

 http://blog.8thlight.com/colin-jones/2012/05/22/quoting-without-confusion.html



On Thursday, June 19, 2014 12:22:36 PM UTC+3, sorin cristea wrote:



  hi all,
 related to macro definition, what are the differences between*[** ' ]* 
 char and *[ ` ]* char ?

 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.


macro - unquote

2014-06-19 Thread sorin cristea


 hi all,
related to macro definition, what are the differences between*[** ' ]* char 
and *[ ` ]* char ?

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.


store a value in a PersistentVector and PersistentHashMap

2014-06-04 Thread sorin cristea
 
  Hi all,

do you know how is store a 'value' in a PersistentVector or in a 
PersistentHashMap ?

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.


Re: store a value in a PersistentVector and PersistentHashMap

2014-06-04 Thread sorin cristea


On Wednesday, June 4, 2014 4:32:00 PM UTC+3, François Rey wrote:

 On 04/06/14 14:59, sorin cristea wrote: 
   do you know how is store a 'value' in a PersistentVector or in a 
  PersistentHashMap ? 
 Hi Sorin, 
 Your question is difficult to understand without more context. 
 Are you trying to use Clojure data structures from Java? 
 http://www.lispcast.com/3-things-java-can-steal-from-clojure 
 Are you trying to understand how to use clojure data structures? 
 http://pleac.sourceforge.net/pleac_clojure/arrays.html 
 http://pleac.sourceforge.net/pleac_clojure/hashes.html 
 Are you trying to understand how clojure data structure work internally? 
 http://hypirion.com/musings/understanding-persistent-vector-pt-1 
 http://hypirion.com/musings/understanding-persistent-vector-pt-2 
 http://hypirion.com/musings/understanding-persistent-vector-pt-3 




Hi Francois, 

I'm trying to understand how clojure persistence data structure, specially 
PersistentVector and PersistentHashMap, work internally 

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.


PersisTVector PersistHashMap - internal implementation.

2014-06-03 Thread sorin cristea

 Hi all,

   I don't know if this question was already asked by someone here but can 
you tell me(explain) or guide me to a properly documentation about how is 
internal implemented PersistenVector and PersistentHashMap , how they 
behave to an insert , remove, update; this question is came from 
presentation of Rich Hickey - 
Persistent Data Structures and Managed 
References(http://www.infoq.com/presentations/Value-Identity-State-Rich-Hickey).


Thanks in advance,

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.


PersistentVector PersistentHashMap - internal implementation

2014-06-03 Thread sorin cristea
 Hi all,

   I don't know if this question was already asked by someone here but can 
you tell me(explain) or guide me to a properly documentation about how is 
internal implemented PersistenVector and PersistentHashMap , how they 
behave to an insert , remove, update; this question is came from 
presentation of Rich Hickey - 
Persistent Data Structures and Managed References(
http://www.infoq.com/presentations/Value-Identity-State-Rich-Hickey).


Thanks in advance,
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.


Re: PersistentVector PersistentHashMap - internal implementation

2014-06-03 Thread sorin cristea


On Tuesday, June 3, 2014 5:07:30 PM UTC+3, Stefan Kamphausen wrote:

 Hi,

 On Tuesday, June 3, 2014 4:02:45 PM UTC+2, sorin cristea wrote:

  Hi all,

I don't know if this question was already asked by someone here but 
 can you tell me(explain) or guide me to a properly documentation about how 
 is internal implemented PersistenVector and PersistentHashMap , how they 
 behave to an insert , remove, update; this question is came from 
 presentation of Rich Hickey - 
 Persistent Data Structures and Managed References(
 http://www.infoq.com/presentations/Value-Identity-State-Rich-Hickey).



 The posts by Karl Krukow describe this very well.  See 
 http://blog.higher-order.net/2009/02/01/understanding-clojures-persistentvector-implementation.html
  
 and the linked post on hash maps.  Code links are outdated, though.


 Best,
 stefan


  Hi, thanks for this resource, 

  I take a look through the description on PersistentHashMap, but was not 
so clear how exactly is searched for a element on level three for example ?

 

-- 
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 define a variable of type collection to keep other functions.

2014-05-28 Thread sorin cristea
 Thanks Sean, indeed this help me a lot ..

 one question, beside that it's not indicated to define def inside of a 
defn, as you pointed before, if I have the bellow code:






*( defn some-method[arg]   (def thred (. Thread currentThred)   
(println on current thread thread use variable arg))*

 'thred' - is only visible inside of some-methd, because is a little 
confuse for me your statement - *`def` and `defn` create global bindings - 
they are not variable assignments - and you don't want `def` nested into 
`defn`.*  

 do you know why is more advantages to use *let *instead of *def  *inside a 
*defn 
*?

thanks
Sorin

On Saturday, May 24, 2014 2:04:55 AM UTC+3, Sean Corfield wrote:

 On May 23, 2014, at 2:19 AM, sorin cristea srncr...@gmail.comjavascript: 
 wrote: 
  Thank Philippe for your advices,I came from java environment and seems I 
 still remain with some 'bad' habits. 

 Coming from Java, the main thing to bear in mind in Clojure is that you do 
 not have variables in the sense you are used to and you generally avoid 
 loops in favor of operations on whole collections (such as map/reduce). 

 `def` and `defn` create global bindings - they are not variable 
 assignments - and you don't want `def` nested into `defn`. 

 You can use `let` to create local bindings (again, not variables). 

 Clojure has `future` built-in so you might consider something like this: 

 (defn sample-fc 
   [] 
   (let [futures (repeatedly 3 (fn [] (future task result !!!)))] 
 (doseq [f futures] 
   (println (deref f) 

 Or just: 

 (defn sample-fc 
   [] 
   (doseq [f (repeatedly 3 (fn [] (future task result !!!)))] 
 (println @f))) ;; @f is short for (deref f) 

 `repeatedly` takes a count and a no-arg function and return a sequence of 
 results of calling that function. 

 Or if you want to see the results differ: 

 (defn sample-fc 
   [] 
   (doseq [f (for [i (range 3)] (future (str task result  i !!!)))] 
 (println @f))) 

 But all of these are still procedural in that they loop over the data and 
 print results, rather than constructing data structures and transforming 
 them (and ultimately printing the result). 

 Consider: 

 (defn make-tasks 
   [inputs] 
   (for [i inputs] 
 (future (str task result  i !!! 

 (defn join-tasks 
   [tasks] 
   (clojure.string/join \n (map deref tasks))) 

 (println (join-tasks (make-tasks (range 3 

 Here we've separated out task creation (based on a sequence of inputs), 
 task completion (gathering the results as a single string), and printing 
 the result. Note that `map` is lazy so the actual task completion - deref - 
 is forced by joining the results together since that is an eager operation. 

 At this point you could also do: 

 (- (range 3) 
 make-tasks 
 join-tasks 
 println) 

 which makes the pipeline sequence of steps more obvious. 

 Since we've broken things down into small steps - and I mentioned `map` 
 being lazy - it's instructive to see what happens if we don't force the 
 mapped sequence to be used: 

 (do (map deref (make-tasks (range 3))) (println DONE)) 

 This will just print DONE (and nil, the result of calling `println`) but 
 the tasks will not even be created because nothing uses them. You can prove 
 this to your self by adding a `println` inside the `future` call like this: 

 (future (do (println RUNNING  i) (str task result  i !!!))) 

 There are several ways to force the mapped sequence to be used 
 (realized). You could wrap it in a call to `doall`: 

 (do (doall (map deref (make-tasks (range 3 (println DONE)) 

 This realizes the mapped sequence (but still throws away the result). You 
 could use `dorun`: 

 (do (dorun (map deref (make-tasks (range 3 (println DONE)) 

 This realizes the mapped sequence and returns nil (which is then thrown 
 away). Or you could use `mapv` which produces a vector and is not lazy: 

 (do (mapv deref (make-tasks (range 3))) (println DONE)) 

 Or you could simply loop over the tasks, calling deref and throwing the 
 result away via `doseq` (which is why this is kind of procedural): 

 (doseq [f (make-tasks (range 3))] 
   (deref f)) 

 `doseq` returns nil. 

 Which you choose depends on what, if anything, you want to do with the 
 result. 

 Hope that helps? 

 Sean Corfield -- (904) 302-SEAN 
 An Architect's View -- http://corfield.org/ 

 Perfection is the enemy of the good. 
 -- Gustave Flaubert, French realist novelist (1821-1880) 





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

how to define a variable of type collection to keep other functions.

2014-05-23 Thread sorin cristea

Hi all,

do you have any idea how I can define a variable, global or inside a 
function, used to store for example the FutureTask objects resulted from 
ExecutorService submit(fn) call,I want to put all futures in a collection 
and later call 'get' on each of them. bellow is a sample of that code: 

(defn sample-fc
  []
  (def futures '())
  (dotimes [i 3]
(def f (. thread-pool (submit (fn [] (task result !!!)
(cons f futures)
)
   shutdown the pool
  (. thread-pool shutdown)
  (. thread-pool awaitTermination (. Long MAX_VALUE) (. TimeUnit SECONDS))

  go through all futures an call get on them
  (doseq [f futures]
(println (. f get))
)
)

 when I do 'dosync' futures collection is empty, even if (def f (. 
thread-pool (submit (fn [] (task result !!!) is a a non empty object 
of type FutureTask(java.util.concurrent package).

Do you know how to define 'futures' variable such that to keep all returned 
future ?

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.


Re: how to define a variable of type collection to keep other functions.

2014-05-23 Thread sorin cristea

Thank Philippe for your advices,I came from java environment and seems I 
still remain with some 'bad' habits.

On Friday, May 23, 2014 12:04:52 PM UTC+3, Philippe Guillebert wrote:

 Hello

 This is not written as functional code. You have to understand that :

 (cons f futures)

 creates a new version of futures with f in front of it and cons *returns 
 it to you*. Put another way,* futures is not modified by cons*. In your 
 dotimes construct, the consed value is lost each loop. Have a look at 
 loop/recur, map, and reduce, these are the backbone functions when 
 programming in clojure.

 Also, do not use (def) inside a function, this is ugly. use let to define 
 local bindings instead.

 --
 Philippe.




 On Fri, May 23, 2014 at 10:16 AM, sorin cristea 
 srncr...@gmail.comjavascript:
  wrote:


 Hi all,

 do you have any idea how I can define a variable, global or inside a 
 function, used to store for example the FutureTask objects resulted from 
 ExecutorService submit(fn) call,I want to put all futures in a collection 
 and later call 'get' on each of them. bellow is a sample of that code: 

 (defn sample-fc
   []
   (def futures '())
   (dotimes [i 3]
 (def f (. thread-pool (submit (fn [] (task result !!!)
 (cons f futures)
 )
shutdown the pool
   (. thread-pool shutdown)
   (. thread-pool awaitTermination (. Long MAX_VALUE) (. TimeUnit SECONDS))

   go through all futures an call get on them
   (doseq [f futures]
 (println (. f get))
 )
 )

  when I do 'dosync' futures collection is empty, even if (def f (. 
 thread-pool (submit (fn [] (task result !!!) is a a non empty 
 object of type FutureTask(java.util.concurrent package).

 Do you know how to define 'futures' variable such that to keep all 
 returned future ?

 thanks,
 Sorin

  -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.comjavascript:
 Note that posts from new members are moderated - please be patient with 
 your first post.
 To unsubscribe from this group, send email to
 clojure+u...@googlegroups.com javascript:
 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+u...@googlegroups.com javascript:.
 For more options, visit https://groups.google.com/d/optout.




 -- 
 Philippe
  

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


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: Lazy sequence - how they work internally

2014-04-08 Thread sorin cristea
Hi James,

  I'm new to clojure and maybe for this reason it's possible to put some 
'stupid' questions,  I came for Java so for me it's normal when I call a 
fc/method to execute the body of that fc/method and return a result; this 
is the reason for why I expect a result when I call (test-fc (range 
210432423543654675765876879)), I'm totally agree with you that this will 
take a long time to complete. I try to understand exactly how work 
internally lazy seq and for that I start to wrote this function to know how 
recursive call of function from inside of his body is replaced with plain 
recursion and in this way is avoided Stackoverflow ex..  

It's something wrong on my logic ?
Thanks
Sorin
 

On Monday, April 7, 2014 11:13:51 PM UTC+3, James Reeves wrote:

 Why do you expect (test-fc (range 210432423543654675765876879)) to return 
 a result?

 Even if each iteration of the loop takes only 1 nanosecond, your function 
 would take 6 billion years to complete.

 - James


 On 7 April 2014 21:01, sorin cristea srncr...@gmail.com javascript:wrote:


 Hi Gianluca, 

  I have a question ; why when a run/execute command/code line (test-fc 
 (range 210432423543654675765876879)) it's not executed the function 
 test-fc and return the sum for all 210432423543654675765876879 elements? 
 why should I put the test-fc reference to a variable, x, like you present 
 below. ( this is related to your phrase - your function computes a 
 sequence of just one element (the sum of the collection members - why ?)


  In this case (def x (test-fc (range 210432423543654675765876879)) I see 
 here a problem, I keep a reference to the head of sequence and this will 
 imply that the GC will can't garbage the unused items, if is wrong what I'm 
 say please correct me. 

  thanks a lot
  Sorin.

 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.comjavascript:
 Note that posts from new members are moderated - please be patient with 
 your first post.
 To unsubscribe from this group, send email to
 clojure+u...@googlegroups.com javascript:
 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+u...@googlegroups.com javascript:.
 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: Lazy sequence - how they work internally

2014-04-08 Thread sorin cristea
  
  Hi Webb, 
What exactly you mean by '*The point was you aren't using lazy-seq as 
intended here since you are always creating a singleton sequence*' ? In my 
sum function: 

(
  defn test-fc
  sum of all collection elements using recursion and laziness
  [coll]
  (letfn [(sum-fc [sum coll]
(if (empty? coll)
  (cons sum nil)
  (lazy-seq(sum-fc (+ sum (first coll)) (rest coll

  )
 ]
(sum-fc 0 coll)
  )
)

I intend to compute sum of '*210432423543654675765876879*' elements of a 
collection, by calling (test-fc (range 210432423543654675765876879)), if I 
Do this 
*(def x **(test-fc (range 210432423543654675765876879)))*, and then *x,*this is 
not the same thing with *(test-fc 
(range 210432423543654675765876879))* ?, I understand the issue related to 
time to compute this sum, but the same time is taken when I call x, right ?

Thanks for the hint with trampoline function, really interested .

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.


Re: Lazy sequence - how they work internally

2014-04-07 Thread sorin cristea

 Hi Ginaluca, 

 I have a question ; why when a run/execute command/code line (test-fc 
(range 210432423543654675765876879)) it's not executed the function test-fc 
and return the sum for all 210432423543654675765876879 elements? why should 
I put the test-fc reference to a variable, x, like you present below. 

 In this case (def x (test-fc (range 210432423543654675765876879)) I see 
here a problem, I keep a reference to the head of sequence and this will 
imply that the GC will can't garbage the unused items, if is wrong what I'm 
say please correct me. 

 thanks a lot
 Sorin.


On Monday, April 7, 2014 1:45:41 AM UTC+3, gianluca torta wrote:

 Hi sorin,

 your function computes a sequence of just one element (the sum of the 
 collection members), so I would say it is not a typical use of (lazy) seqs

 to see that the code is indeed lazy, you can try:
   (def x (test-fc (range 210432423543654675765876879)))
 and see that it returns immediately; however, as soon as you evaluate x:
   x
 the whole computation of the only element of x starts and continues all 
 the way to process the 210432423543654675765876879 elements of the range

 As for your question on recursion: this is an example of tail recursion, 
 that is automatically converted into plain iteration.
 When there is only a recursive call, and such a call is the last thing in 
 the body of the function, it can be easily (and automatically) converted to 
 iteration, with no stack overflow problems.

 hope this helps
 Gianluca



 On Sunday, April 6, 2014 6:56:00 PM UTC+2, sorin cristea wrote:


  Hi,

  maybe this question was already put it here, but can someone explain how 
 exactly work internal a function wrapped with lazy-seq keyword. For example 
 in the below code sample:

 (
   defn test-fc
   sum of all collection elements using recursion and laziness
   [coll]
   (letfn [(sum-fc [sum coll]
 (if (empty? coll)
   (cons sum nil)
   (lazy-seq(sum-fc (+ sum (first coll)) (rest coll

   )
  ]
 (sum-fc 0 coll)
   )
 )

 if I test the function: (test-fc (range 5)) I got the right result, if I 
 continue to test with bigger number I don't got StackoverflowException, but 
 if run  (test-fc (range 210432423543654675765876879)) I didn't get 
 StackoverflowEx but the application didn't return any result, because take 
 to much time to compute this ?

 How exactly work this internally and how is removed recursion( inside 
 call sum-fc with new parameters) from the flow in this case ? From what I 
 saw in java code of LazySeq class and clojure source code, it's made a list 
 with LazySeq object and in my opinion in that list the LazySeq object 
 contain enough information to compute the requested item and in this way is 
 removed recursion and implicit StackoverflowException issue, if I 
 understand something wrong please explain to me. 
 I test this function from IntellijIDEA + LaClojure plugin.

 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.


Re: Lazy sequence - how they work internally

2014-04-07 Thread sorin cristea

Hi Gianluca, 

 I have a question ; why when a run/execute command/code line (test-fc 
(range 210432423543654675765876879)) it's not executed the function test-fc 
and return the sum for all 210432423543654675765876879 elements? why should 
I put the test-fc reference to a variable, x, like you present below. ( 
this is related to your phrase - your function computes a sequence of just 
one element (the sum of the collection members - why ?)

 In this case (def x (test-fc (range 210432423543654675765876879)) I see 
here a problem, I keep a reference to the head of sequence and this will 
imply that the GC will can't garbage the unused items, if is wrong what I'm 
say please correct me. 

 thanks a lot
 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.


Lazy sequence - how they work internally

2014-04-06 Thread sorin cristea

 Hi,

 maybe this question was already put it here, but can someone explain how 
exactly work internal a function wrapped with lazy-seq keyword. For example 
in the below code sample:

(
  defn test-fc
  sum of all collection elements using recursion and laziness
  [coll]
  (letfn [(sum-fc [sum coll]
(if (empty? coll)
  (cons sum nil)
  (lazy-seq(sum-fc (+ sum (first coll)) (rest coll

  )
 ]
(sum-fc 0 coll)
  )
)

if I test the function: (test-fc (range 5)) I got the right result, if I 
continue to test with bigger number I don't got StackoverflowException, but 
if run  (test-fc (range 210432423543654675765876879)) I didn't get 
StackoverflowEx but the application didn't return any result, because take 
to much time to compute this ?

How exactly work this internally and how is removed recursion( inside call 
sum-fc with new parameters) from the flow in this case ? From what I saw in 
java code of LazySeq class and clojure source code, it's made a list with 
LazySeq object and in my opinion in that list the LazySeq object contain 
enough information to compute the requested item and in this way is removed 
recursion and implicit StackoverflowException issue, if I understand 
something wrong please explain to me. 
I test this function from IntellijIDEA + LaClojure plugin.

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.


call clojure from java

2014-02-18 Thread sorin cristea
Hi 

do you know how I can call a clojure script from a java method ?


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


Re: call clojure from java

2014-02-18 Thread sorin cristea
Hi guys,

Thanks for your information. I would take the advantage of concurrency in 
clojure and implement a concurrent scenario in clojure and call it from 
java code. For example I want to read/modify the content of file from many 
threads, this scenario I want to implement in clojure, and call this from 
java, in order to avoid the implementation of this scenario in java to put 
locks on file when it's modify by one thread.

Sorin

On Tuesday, February 18, 2014 3:10:18 PM UTC+2, Stathis Sideris wrote:

 I think you're looking for this method here:


 https://skillsmatter.com/skillscasts/3864-impromptu-rich-hickey-lightning-talk

 (you need to register to see the video)

 On Tuesday, 18 February 2014 11:39:20 UTC, sorin cristea wrote:

 Hi 

 do you know how I can call a clojure script from a java method ?


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