Re: is ok use a blocking get !! at the end of sequence of async calls

2015-03-25 Thread coco
thanks for the reply  Erik, that's what I feared, I'm using vertx with the 
ring adapter, basically I do several http async request in my handler and 
I've rewrote  several libs for adapt thes e to vertx, so block my server is 
really bad for me :D ...

http-kit offers an adaptation for ring which handle channel responses 
and https://github.com/mpenet/jet seems do something similar, unfortunately 
vertx doesnt have a big community and could take some time for get this 
adaptations..

seems than I'll need keep using clojure with vertx directly and don't use 
nice libs like compojure,buddy,liberator...that is sad...if you know about 
some small adapter or some code which can I use please let me know...
thanks



El miércoles, 25 de marzo de 2015, 17:29:29 (UTC-4:30), Erik Price escribió:

 There is no best approach for this. Yes, you do end up blocking the 
 request thread, but that’s what needs to happen if you the response 
 requires the value returned by the channel. You can’t return a response to 
 the browser and then change it later when the channel sends its value. 
 (You’d have the same problem with Rx, btw.)

 The closest equivalent to Rx’s complete event is that a channel is closed 
 (in which case anything blocked or parked on that channel will receive nil
 ).

 e
 ​

 On Wed, Mar 25, 2015 at 12:08 AM, coco clasespart...@gmail.com 
 javascript: wrote:

 Hi guys...I've a code similar to this:

 (defn user-data []
   (!/go
 (let [a (!/! (fun-async 2))
   b  (!/! (fun-async a))]
   {:response b})))

 (defn handler-something []
   (let [data (!/!! (user-data))] ;;block here
 (print data)
 (response  data..)))

 user-data do a sucession of async calls and return a channel (because 
 it's inside a go block no?) 
 my handler-something need extract this data and return it in a ring 
 response...I can wrap my response function inside a go block, if I do this 
 I get

 java.lang.IllegalArgumentException: No implementation of method: :render 
 of protocol: #'compojure.response/Renderable found for class: 
 clojure.core.async.impl.channels.ManyToManyChannel

 so basically I use a block get !! and then return the data...I'm more 
 familiar with FRP and in FRP I would use a onComplete method which 
 basically do the same as !!

 this pattern is correct or I'll end blocking code?...which could be the 
 best approach for this?..thanks!


  -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.com 
 javascript:
 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.


is ok use a blocking get !! at the end of sequence of async calls

2015-03-24 Thread coco
Hi guys...I've a code similar to this:

(defn user-data []
  (!/go
(let [a (!/! (fun-async 2))
  b  (!/! (fun-async a))]
  {:response b})))

(defn handler-something []
  (let [data (!/!! (user-data))] ;;block here
(print data)
(response  data..)))

user-data do a sucession of async calls and return a channel (because it's 
inside a go block no?) 
my handler-something need extract this data and return it in a ring 
response...I can wrap my response function inside a go block, if I do this 
I get

java.lang.IllegalArgumentException: No implementation of method: :render of 
protocol: #'compojure.response/Renderable found for class: 
clojure.core.async.impl.channels.ManyToManyChannel

so basically I use a block get !! and then return the data...I'm more 
familiar with FRP and in FRP I would use a onComplete method which 
basically do the same as !!

this pattern is correct or I'll end blocking code?...which could be the 
best approach for this?..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.


about binding and dynamic vars

2015-03-21 Thread coco
Hi guys, I'm curious about how work some codes with binding and dynamics 
vars, for instance, in sqlkorma you define your db settings

(defdb prod (postgres {:db korma
   :user db
   :password dbpass}))


and then you can use other functions like this

(select user
  (with address)
  (fields :firstName :lastName :address.state)
  (where {:email ko...@sqlkorma.com}))


without pass your config db as parameter..

some korma functions expects your db configuration as first parameter...but if 
you had defined your db before using defdb macro, then you can omit this 
parameter


(defentity users
  ;; Basic configuration
  (pk :id) ;; by default id. This line is unnecessary.
   ;; it's used for relationships joins.
  (table :users) ;; by default the name of the symbol.
 ;; The line above is also unecessary.
  (database db) ;; if none is specified the last defdb  ---
;; will be used. Also unnecessary.

)


I've found this pattern in many clojure codes, but I can't understand how it 
works..can someone provides me a simple and clear example about how write 
something like this?..thank so much!

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


about binding and dynamic vars

2015-03-21 Thread coco
Hi guys, I'm curious about how work some codes with binding and dynamics 
vars, for instance, in sqlkorma you define your db settings

(defdb prod (postgres {:db korma
:user db
:password dbpass}))

and then you can use other functions like this
(select user
(with address)
(fields :firstName :lastName :address.state)
(where {:email korma sqlkorma.com})) ko...@sqlkorma.com}))

without pass your config db as parameter..
some korma functions expects your db configuration ...but if you had 
defined your db before using defdb macro, then you can omit this parameter, 
other sample:

(defentity users
;; Basic configuration
(pk :id) ;; by default id. This line is unnecessary.
;; it's used for relationships joins.
(table :users) ;; by default the name of the symbol.
;; The line above is also unecessary.
(database db) ;; if none is specified the last defdb ---
;; will be used. Also unnecessary.
)

I've found this pattern in many clojure codes, but I can't understand how 
it works..can someone provides me a simple and clear example about how 
write something like this?..thank so much!

-- 
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: avian vm or robovm for desktop binary executables?..anyone has tried??

2015-03-16 Thread coco
thanks for the reply skuro, yep aviam seems a bit immature yet and even the 
scala support fails, robovm seems more promising, there is a package for 
build native iOS apps with clojure https://github.com/oakes/lein-fruit , I 
think than would be great use clojure for scripting and command line apps 
but the low startup and how heavy the jvm is makes me rethink it again 
:D...hope someone has experience with robovm and clojure.





El domingo, 15 de marzo de 2015, 2:28:42 (UTC-4:30), skuro escribió:

 Hi coco,

 I tried with Avian, and unfortunately there's quite a big part of the 
 standard classes that Clojure needs that Avian still doesn't implement. 
 Clojure fails to bootstrap altogether.

 c.

 Il giorno sabato 14 marzo 2015 00:59:01 UTC+1, coco ha scritto:

 Hi guys, I'm curiouss if its possible use avian or robovm for distribute 
 binary desktop executables for linux,mac or windows...seems to be possible 
 https://news.ycombinator.com/item?id=7579737 , 
 http://labb.zafena.se/?p=673

 but I've not found so much information about it :S..
 I think than it would be a great big step for java , dont depend of VM 
 which consume a lot of memory and slow app startups caused by JIT 
 compiler...the jvm is great for web apps but obviously it's not the better 
 choice for desktop apps and considering than clojure is great language for 
 scripts and sys admin but the jvm is not, would be great use an alternative 
 for command line apps too... what do you think?
 anyone has experience using avian or robovm?..what disadvantages has 
 found? any problem or issue?...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.


avian vm or robovm for desktop binary executables?..anyone has tried??

2015-03-13 Thread coco
Hi guys, I'm curiouss if its possible use avian or robovm for distribute 
binary desktop executables for linux,mac or windows...seems to be possible 
https://news.ycombinator.com/item?id=7579737 , http://labb.zafena.se/?p=673

but I've not found so much information about it :S..
I think than it would be a great big step for java , dont depend of VM 
which consume a lot of memory and slow app startups caused by JIT 
compiler...the jvm is great for web apps but obviously it's not the better 
choice for desktop apps and considering than clojure is great language for 
scripts and sys admin but the jvm is not, would be great use an alternative 
for command line apps too... what do you think?
anyone has experience using avian or robovm?..what disadvantages has found? 
any problem or issue?...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: about macro exception : Unable to resolve classname: LinkedList, macro question and possible better approach

2015-03-08 Thread coco


  All your macro needs to do is to convert the first form into the second. 

 

 thanks james, that make sense for me...



I don't know what the rest of your function is supposed to be doing 


you can check my second example 

(def data (atom ))
(defmacro blahhh []
   (go
  (let [ch (chan)]
 (do
(loop []
   (let [res (! ch)]
  (if (= res secret)
 (do (println  res)
 (reset! data res))
 (recur)
(do(doseq [word [blah bang secret goal]] (put! ch word))


It only waits a specific value in the channel and do somehting...in this case 
change an atom...I'm still curious about why I get that error when I declare it 
likes macro but it works when it's a function


3)  I've this other code


(defmacro defbus [bus-name args code]
   `(eb/on-message (str *ns* : ~bus-name) (fn ~args ~code)))




basically I need convert from this


(defbus some-bus [a] (eb/reply (str  a)))

to this


(eb/on-message some-namespace:some-bus (fn [a](eb/reply (str  a

 
I did this

(defmacro defbus [bus-name args code]
   `(eb/on-message (str *ns* : ~bus-name) (fn ~args ~code)))


or


(defmacro def-bus [bus-name args code]
   `(let [fun# (fn ~args ~code)]
   (eb/on-message (str *ns*   ~bus-name) fun#)))




the macro-expansion looks ok but when I try use it..I get some-bus is not 
defined..seems than it's trying evaluate the name..is it ok??..how can avoid 
it??...


thanks again james

-- 
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: about macro exception : Unable to resolve classname: LinkedList, macro question and possible better approach

2015-03-08 Thread coco
 


Sure, because you haven't quoted the symbol. If you write:

 (str *ns* : some-bus)

 ups!!, yes I forget quoted the symbol, thanks james!!...
 

In Clojure, then Clojure will look for a variable called some-bus. The 
 error you get is because it can't find such a variable.

 You want to either quote the symbol, or turn it into a string, e.g.

 (str *ns* : (quote ~bus-name))
 ; or
 (str *ns* : ~(str bus-name))

 - James



just now I'm gonna use the defbus macro, I preferred use a function instead 
for the other case based in your suggestion and works really well (I 
changed the async code for a more readable too :D)...

 

-- 
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: about macro exception : Unable to resolve classname: LinkedList, macro question and possible better approach

2015-03-06 Thread coco


 sorry for my crappy code, but I was changing some conditions and testing my 
 parameters before and I end with this code

 (if (not (false? res))
 res

  (recur)) 

I must write just

(if  res
 res

  (recur)) 


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


about macro exception : Unable to resolve classname: LinkedList, macro question and possible better approach

2015-03-06 Thread coco
Hi guys, first I'm really noob using macros, basically I've this

(!b (function-blah hi))

Hey..I didn't know than intellij copy/paste the text with format!..cool!

Ok..returning to my question...I don't need call to function-blah...I need 
send a message to one address possibly named some-namespace:blah..how I 
discover which is the correct namespace is simple...I send a message to 
every possible namespace stored in a vector..when some bus return a 
response, I index it in a map (:function full-address) ...next calls only 
needs find the correct address in the map and send the message... 

just now I've this code:

(defmacro !b [f]
   (if
  (some nil? [(resolve 'vertx-bus-routes) (resolve 'solved-vertx-routes)])
  (println need use require-vertx function first)

  (let [function-name (first f)
arguments (rest f)]
 (if-let [function-route (get @solved-vertx-routes function-name 
false)];;if the route address was indexed
(send function-route arguments) 
;;only send the message using this address
(go
   (let [full-names   (map #(str % : function-name) 
@vertx-bus-routes)  ;;1)concatenate the name with the full address list
 response-channel (chan (count @vertx-bus-routes))  
  ;;2)create a channell
 [correct-route res] (loop []   
  ;;4) take only the address where you get a non false response
(let [res (! response-channel)]
   (if (not (false? res))
  res
  (recur]
  (do
 (doseq [name full-names] (test-bus name arguments 
response-channel))   ;;3) take the address list and send a message to every 
address
 (assoc @solved-vertx-routes function-name correct-route)   
;;5) store the correct address in a map function-name - correct 
address
 res)))



I add this to gist https://gist.github.com/anonymous/9fc79679e17e36c47994


when I try run it I get: CompilerException java.lang.IllegalArgumentException: 
Unable to resolve classname: LinkedList


I did a simplified version of the code (also uploaded to gist line 25)..I move 
the correct response outside the let thinking than maybe could be the 
problem...but this fails


(def data (atom ))
(defmacro blahhh []
   (go
  (let [ch (chan)]
 (do
(loop []
   (let [res (! ch)]
  (if (= res secret)
 (do (println  res)
 (reset! data res))
 (recur
(doseq [word [blah bang secret goal]] (put! ch word))


I've three questions:

1) why the exception

2) is correct use a macro?..I'm using a macro because I need avoid try evaluate 
the function in the argument and instead I use it as data..but the code results 
a bit weird because I'm not generating code..I though than I need quote the 
full macro body but I read this article


http://www.braveclojure.com/writing-macros/


and He did something similar

(defmacro postfix-notation
  [expression]
  (conj (butlast expression) (last expression)))
(macroexpand '(postfix-notation (1 1 +))); = (+ 1 1)


One key difference between functions and macros is that function arguments are 
fully evaluated before they're passed to the function, whereas macros receive 
arguments as unevaluated data structures.


3) Any better way of do it?...suggestion?..the way how I use the channel is not 
elegant neither...


thanks so much guys!

2


-- 
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: call superclass constructor in clojure class generation with defrecord

2015-02-07 Thread coco
Sorry for don't reply before, thanks so much michael, that works...and gary 
for the explanation, now it's much more clear to me...thanks guys

El viernes, 30 de enero de 2015, 18:35:02 (UTC-4:30), coco escribió:

 Hi everybody, I need implement this java code in clojure

  public class MyWindow extends Window
  {
 public MyWindow()
  {
   super(My Window!);
  }
 }

 MyWindow myWindow = new MyWindow();


 unfortunately the clojure documentation for generate classes is not so 
 complete or straightforward for my understand...must I use gen-class or can 
 I use defrecord for this task?...how can I call super class 
 constructors??...

 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: call superclass constructor in clojure class generation with defrecord

2015-01-31 Thread coco
thanks Michael this does the job...in this code, now I've other doubt

public class MyWindow extends Window
{
public MyWindow()  // --- not clear where I need declare it
{
super(My Window!);
Panel horizontalPanel = new Panel(new Border.Invisible(), 
Panel.Orientation.HORIZONTAL);
Panel leftPanel = new Panel(new Border.Bevel(true), 
Panel.Orientation.VERTICAL);
Panel middlePanel = new Panel(new Border.Bevel(true), 
Panel.Orientation.VERTICAL);
Panel rightPanel = new Panel(new Border.Bevel(true), 
Panel.Orientation.VERTICAL);

horizontalPanel.addComponent(leftPanel);
horizontalPanel.addComponent(middlePanel);
horizontalPanel.addComponent(rightPanel);

addComponent(horizontalPanel); // this is a confusing part too
}
}



in this code addComponent(horizontalPanel)  is basically something like
this.addComponent(horizontalPanel)

does clojure have the this reference??...how can I call the 
constuctor...I'm thinkingin something like this

  (defn MyWindow []
  (proxy [Window] [My windows!!]
(MyWindow [] (. this addComponent (Label. Bang!!)  

is it wrong no? :D

thanks!!!

El viernes, 30 de enero de 2015, 18:47:48 (UTC-4:30), Michael Blume 
escribió:

 (defn my-window []
   (proxy [Window] []))

 should do the trick

 Proxy takes a vector of implemented interfaces and at most one superclass 
 (in your case, Window), and then a second vector of arguments to pass to 
 the superclass constructor (in your case, an empty vector) and then a 
 series of methods implemented/overridden on the parent class/interfaces -- 
 in your case there's none of those.

 My understanding is that proxy is not quite as performant as 
 reify/defrecord, but it's the only game in town if you actually want to 
 subclass something.

 Hope this helps =)

 On Fri Jan 30 2015 at 3:05:11 PM coco clasespart...@gmail.com 
 javascript: wrote:

 Hi everybody, I need implement this java code in clojure

  public class MyWindow extends Window
  {
 public MyWindow()
  {
   super(My Window!);
  }
 }

 MyWindow myWindow = new MyWindow();


 unfortunately the clojure documentation for generate classes is not so 
 complete or straightforward for my understand...must I use gen-class or can 
 I use defrecord for this task?...how can I call super class 
 constructors??...

 thanks

 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.com 
 javascript:
 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.


call superclass constructor in clojure class generation with defrecord

2015-01-30 Thread coco
Hi everybody, I need implement this java code in clojure

 public class MyWindow extends Window
 {
public MyWindow()
 {
  super(My Window!);
 }
}

MyWindow myWindow = new MyWindow();


unfortunately the clojure documentation for generate classes is not so 
complete or straightforward for my understand...must I use gen-class or can 
I use defrecord for this task?...how can I call super class 
constructors??...

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: noob question about error with tail recursion

2011-11-30 Thread coco
now I'm in a similar trouble...I'm trying  resolve the problem 31 from 
4clojure ...It says:
Write a function which packs consecutive duplicates into sub-lists.
[image: test not run]
(= (__ [1 1 2 1 1 1 3 3]) '((1 1) (2) (1 1 1) (3 3)))

I know than I can use identity and others clojure functions but I wanna 
resolve this using loop too
my idea is it:
I've a mem..this is the final list than I will return and a temporary 
list...
first I compare my first and second item and if these are the same I 
include it in my temp list
if they are different then I include my temp list inside mem (a better name 
would be final_list) and
clear my temp putting the second item in it
I iterate until than my list become empty

the code could be this:


(defn packing [lista]
  (loop [[fst snd  rst] listamem []tmp '(fst)]
(if (seq? lista)
  (if (= fst snd)
(recur (rest lista) mem (cons snd tmp))
(recur (rest lista) (conj mem tmp) (list snd)))
  (seq mem

if I run this I get a java.lang.OutOfMemoryError: Java heap space 
(NO_SOURCE_FILE:0)

It is tail recursive, I'm not sure if I can use 2 distinct recursions 
inside a loop but I think than must be possible..what am I doing wrong??...
thanks so much

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

Re: noob question about error with tail recursion

2011-11-30 Thread coco
yep..that is an error but (recur (rest rst) I think wouln't work...maybe 
something like

(defn packing [lista]
  (loop [[fst snd :as all] listamem []tmp '(fst)]

   (print all is   all   \n\n) ;;something is wrong...all always is 
a empty list

(if (seq? all)
  (if (= fst snd)
(recur (rest all) mem (cons snd tmp))
(recur (rest all) (conj mem tmp) (list snd)))
  (seq mem

something is still wrong..:(

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

noob question about error with tail recursion

2011-11-22 Thread coco
Hi..I've a little problem using recur for recursive calling...I'm
trying do the clojure koans and the recursive reverse function
[1 2 3 4] - '(4 3 2 1)


first I try this code:


(defn recursive-reverse [coll]
  (loop [col coll mem '()]
(if (empty? coll)
  mem
  ((cons (last col) mem)
   (recur (butlast col) mem) 

this didn't work and I thought the problem was (butlast col) and
rewrite the code to this

(defn recursive-reverse [coll]
  (loop [col (butlast coll) mem (list (last coll))]
(if (empty? coll)
  mem
  ((cons (last col) mem)
   (recur col mem) 

why isn't a tail recur?...my recursion is de latest operation in the
functin

thanks so much
I hope learn a lot about functional programming

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


Re: noob question about error with tail recursion

2011-11-22 Thread coco
thanks for the answer, well, I rewrote the function lik this:

(defn recursive-reverse [coll]
  (loop [col coll mem '()]
(if (empty? col)
  mem
  (recur (rest col) (cons (first col) mem)) )))

I've a little logic problem but I fix it

thanks

On Nov 23, 12:54 am, Sean Corfield seancorfi...@gmail.com wrote:
 On Tue, Nov 22, 2011 at 8:49 PM, coco clasesparticulares...@gmail.com wrote:
       ((cons (last col) mem)
        (recur (butlast col) mem) 
 ...
       ((cons (last col) mem)
        (recur col mem) 

 In both of these, you have a function call with (cons (last col) mem)
 as the function...

 You're going to need (recur something something-else) as the else
 expression for recur to be in the tail position.

 HTH,
 --
 Sean A Corfield -- (904) 302-SEAN
 An Architect's View --http://corfield.org/
 World Singles, LLC. --http://worldsingles.com/

 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


Clojure vs Clisp...How big is the difference??

2010-11-21 Thread coco
Hi  everybody...I'm interested in learning clojure but there're only a
few books and more focused to advanced programmers...I found today a
nice book about Clisp but I don't know how different is itplease
can tell if can be recommendable learn first Clisp with a easy follow
book..or if there are many differences about these and It's not
recommendable

THANKS!! and greetings from Italy

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