Re: Code introspection: Clojure vs Python

2009-12-14 Thread Dima Dogadaylo
Thanks, Konrad. clojure.lang.Compiler/LOCAL_ENV is what I need. -- 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

Re: Code introspection: Clojure vs Python

2009-12-13 Thread Konrad Hinsen
On 13 Dec 2009, at 11:18, Dima Dogadaylo wrote: > Is it possible to create a macros that knows from what function it was > called and what variables (bindings) are defined in the caller > function? Yes. Look at the recent thread on debug REPLs: http://groups.google.com/group/clojure/bro

Code introspection: Clojure vs Python

2009-12-13 Thread Dima Dogadaylo
Is it possible to create a macros that knows from what function it was called and what variables (bindings) are defined in the caller function? For example following python code defines function print_env that prints name of function that called print_env() along with local variables of those func

Re: vs. Python

2009-08-31 Thread John Harrop
On Mon, Aug 31, 2009 at 5:04 PM, Brian Hurt wrote: > On Sun, Aug 30, 2009 at 9:31 AM, Jason Baker wrote: > >> On Aug 30, 2:24 am, Dan Fichter wrote: >> > The Clojure version is more concise and radically safer but a little >> more >> > conceptually packed. Is it worth your trouble? >> >> Being

Re: vs. Python

2009-08-31 Thread John Harrop
On Mon, Aug 31, 2009 at 5:15 PM, Brian Hurt wrote: > If I recall correctly (and correct me if I'm wrong), Python uses a > reference counting garbage collector. Which means as soon as the reference > to the object goes away, the object gets collected and the handle closed. > Most JVMs use some fo

Re: vs. Python

2009-08-31 Thread Brian Hurt
On Mon, Aug 31, 2009 at 9:03 AM, Konrad Hinsen wrote: > > > In this particular case, there is no reason to worry: open() returns a > file object that is fed to the method read(), but after that method > returns, there is no more reference to the object, so it is garbage > collected. Upon destructi

Re: vs. Python

2009-08-31 Thread Brian Hurt
On Sun, Aug 30, 2009 at 9:31 AM, Jason Baker wrote: > > On Aug 30, 2:24 am, Dan Fichter wrote: > > The Clojure version is more concise and radically safer but a little more > > conceptually packed. Is it worth your trouble? > > Being primarily a Python programmer, I can say that the first thing

Re: vs. Python

2009-08-31 Thread Laurent PETIT
Usually the java libraries explicitly mention not to place OS resource handles on the finalize() method called by the GC, that why I had the reflex of thinking it was generally applicable to all languages with a GC. -- Laurent 2009/8/31 Konrad Hinsen > > On 31 Aug 2009, at 14:08, Laurent PETIT

Re: vs. Python

2009-08-31 Thread Konrad Hinsen
On 31 Aug 2009, at 14:08, Laurent PETIT wrote: > [Python] > > open(filename, 'r').read() # who cares about closing files opened in > read-mode? > > "who cares about closing files opened in read-mode" ? > > I would say anybody concerned about blowing up the underlying OS if > not releasing fil

Re: vs. Python

2009-08-31 Thread B Smith-Mannschott
On Mon, Aug 31, 2009 at 14:08, Laurent PETIT wrote: > Hi, > > Just one point: > > 2009/8/30 Dan Fichter >> >> Read the contents of a file. >> >> [Clojure] >> >> (slurp filename) >> >> [Python] >> >> open(filename, 'r').read() # who cares about closing files opened in >> read-mode? > > "who cares

Re: vs. Python

2009-08-31 Thread Laurent PETIT
Hi, Just one point: 2009/8/30 Dan Fichter > Read the contents of a file. > > [Clojure] > > (slurp filename) > > [Python] > > open(filename, 'r').read() # who cares about closing files opened in > read-mode? > "who cares about closing files opened in read-mode" ? I would say anybody concerned

Re: vs. Python

2009-08-30 Thread John Harrop
On Sun, Aug 30, 2009 at 12:32 PM, CuppoJava wrote: > > Your examples are very good I think. It always helps to have a > straight-forward conversion from one language to another for > beginners. They will eventually pick up idioms and methodology by > playing around. > > One comparison that bothers

Re: vs. Python

2009-08-30 Thread Jonathan
There are two styles of expression in higher level languages (including Python and Clojure). Functional programming (map, filter, reduce, fold) on one side and set (and list) comprehensions on the other. This is somewhat a matter of culture, not capability. Although slightly less convenient, funct

Re: vs. Python

2009-08-30 Thread James Cunningham
On Aug 30, 3:24 am, Dan Fichter wrote: > [...] > Take a dictionary of defaults and a user-supplied dictionary and return a > new dictionary that combines them, with the user's entries winning when both > dictionaries have the same key. > > [Clojure] > > (defn foo [defaults user] >   (merge defaul

Re: vs. Python

2009-08-30 Thread CuppoJava
Your examples are very good I think. It always helps to have a straight-forward conversion from one language to another for beginners. They will eventually pick up idioms and methodology by playing around. One comparison that bothers me though is this: (not= (new Exception) (new Exception)) Agai

Re: vs. Python

2009-08-30 Thread Michael Wood
2009/8/30 Dan Fichter : [...] > [Clojure] > > (println "Hello, world") > > [Python] > > print "Hello, world" Or Python 3.x: print("Hello, world") > A list (in Clojure, a vector) of three integers. > > [Clojure] > > [1 2 3] This can also be written in Clojure as [1, 2, 3]. Commas are considere

Re: vs. Python

2009-08-30 Thread Dragan Djuric
> For example, consider these two snippets: > > [Clojure] > (if x >   (foo y) >   (bar y)) > > [Python] > if x: >   foo(y) > else: >   bar(y) > Yeah, but then, in plain old Java: if x { foo(y); } else { bar(y); } which is not that different at all. The point is that these trivial micro-sni

Re: vs. Python

2009-08-30 Thread Rob Wolfe
Dan Fichter napisał(a): > I'd like to convince some Python developers that Clojure is not foreign and > does many things better than Python. I'd appreciate whatever suggestions > you have about what I've written. [...] > Check whether every object in the collection x can be called like a > fu

Re: vs. Python

2009-08-30 Thread Jason Baker
On Aug 30, 2:24 am, Dan Fichter wrote: > The Clojure version is more concise and radically safer but a little more > conceptually packed.  Is it worth your trouble? Being primarily a Python programmer, I can say that the first thing my co-workers would say is that Clojure isn't as readable as Py

Re: vs. Python

2009-08-30 Thread Chas Emerick
On Aug 30, 2009, at 3:24 AM, Dan Fichter wrote: > I'd like to convince some Python developers that Clojure is not > foreign and does many things better than Python. I'd appreciate > whatever suggestions you have about what I've written. > > Though I am crazy about STM and Clojure agents, I

vs. Python

2009-08-30 Thread Dan Fichter
I'd like to convince some Python developers that Clojure is not foreign and does many things better than Python. I'd appreciate whatever suggestions you have about what I've written. Though I am crazy about STM and Clojure agents, I don't deal with them here. This has to be a gentle introduction

Re: Speed issues vs. Python

2009-03-13 Thread Christophe Grand
It wont solve your performance problem but I think that your python code translates to: (defn f[a b c] (+ (* c c c c) (* b b b) (* a a))) (count (into #{} (for [c primes :while (< (f (first primes) (first primes) c) limit) b primes :while (< (f (first primes) b c) limit)

Re: Speed issues vs. Python

2009-03-13 Thread André Thieme
On 12 Mrz., 07:48, tristan wrote: > my clojure version > http://github.com/tristan/project-euler-code/blob/4a17bc271b4b2743ee1... Not about speed, but about readability: (loop [c primes n #{}] (let [r (loop [b primes n n] (let [r (loop [a primes n n] ...))) You should think about us

Re: Speed issues vs. Python

2009-03-12 Thread Sergio
You should profile your code. A cousin of mine was solving a problem from programmingchallenges.com in C++. I wrote a solution in Clojure. At the beginning, my version was astronomically slower. After profiling, I reduced it to about 2x slower. After modifying it to use Java arrays, it actually b

Re: Speed issues vs. Python

2009-03-12 Thread bOR_
Setting that one (set! *warn-on-reflection* true) Helped a lot in my simulation model to find out where clojure/java were having trouble. It pointed out that one of my main functions was causing trouble, and could do with a bit of typehinting. (defn #^Short find-all-epi "turns the rx and stri

Speed issues vs. Python

2009-03-11 Thread tristan
Hi guys, I'm loving Clojure, but i'm having a lot of trouble writing programs in it that run as fast as my python equivalents. One example is code i've written for projecteuler.net problem 87 (for those who don't want to see any solutions don't click the links below :)) my python version http://