Re: Binding and temporary global state

2010-09-06 Thread Jarkko Oranen
Cameron Pulsford wrote: Is there a way to do this? Besides cleaning up function signatures is this a premature optimization to begin with? (declare *macros*) (defn macro-expand [tokens] (map #(get *macros* % %) tokens)) (defn compile-op [op] (macro-expand op)) (defn assemble

Re: Basic Lisp Compiler: How to tell which functions to compile?

2010-08-09 Thread Jarkko Oranen
On Aug 9, 7:54 pm, CuppoJava patrickli_2...@hotmail.com wrote: Hello everyone, Just for educational purposes, I'm writing a simple lisp compiler and am stuck on a small problem. I'm trying to write a function called (compile-function), which will take a function as input and compile it.

Re: special form vs. macro

2010-05-31 Thread Jarkko Oranen
On May 31, 10:35 am, alux alu...@googlemail.com wrote: [  ] A special form is what can be implemented by a macro. That depends. My understanding is that a special form is something that is fundamental to the language, that the evaluator handles as a special case. That is, they need to be

Re: Transient HashMaps with not more than 8 elements?

2010-05-29 Thread Jarkko Oranen
On May 30, 12:32 am, Daniel Borchmann daniel.borchm...@googlemail.com wrote: The same happens if i goes up to 100, 1000, ... Is this a bug or is this a fundamental misconception of mine? You're using them wrong. Transients are not imperative data structures. You need to capture the return

Re: convert this to loop/recur?

2010-05-17 Thread Jarkko Oranen
On May 18, 2:23 am, Base basselh...@gmail.com wrote: (defn lazy-date-seq [d1 d2]   (let [start (- d1                 (.dayOfMonth)                 (.withMinimumValue))]      (lazy-seq        (cons start          (if (joda/before? start d2)            (lazy-date-seq (.plusMonths start 1)

Re: How to visualise relations, bahavior and so on in functional programming ?

2010-05-11 Thread Jarkko Oranen
On May 11, 11:18 am, Donell Jones alliwantisca...@googlemail.com wrote: Hi Team, I am really interested in functional programming. But I am asking myself, what if the project get bigger, like the software Runa realise with Clojure. In OOP we got diagrams like UML to visualise this. But what

Re: Using a macro to define a function - nested backquotes?

2010-05-04 Thread Jarkko Oranen
On May 4, 10:40 pm, Bryce fiat.mo...@gmail.com wrote: I have a macro, deriv, that produces an expression, and I'd like to create another macro that turns this into a function.  So far I have (defmacro deriv-fn [fn-args exp v degree]   `(fn ~fn-args (deriv ~exp ~v ~degree))) Which of

Re: Funcalls vs. lists (Was: Clojure Concurrency Screencast Available)

2010-05-02 Thread Jarkko Oranen
On May 2, 11:14 pm, Mike Meyer mwm-keyword-googlegroups. 620...@mired.org wrote: On Sun, 02 May 2010 13:06:56 +1000 To get behavior similar to the vector constructs, you want to use list, which works like vector, except returning a list instead of a vector: (list 1 2 3 (print :hello)). It

Re: deftype and final classes

2010-04-28 Thread Jarkko Oranen
On Apr 28, 5:00 am, Richard Newman holyg...@gmail.com wrote: Opinions, thoughts, critiques, you're insanes, etc. welcome. The patches look fine to me and the change is well justified since you have a real use case. I don't think restricting deftype to final classes would serve any real

Re: Cannot find juxt in clojure 1.1 (??)

2010-04-23 Thread Jarkko Oranen
 *clojure-version* {:interim true, :major 1, :minor 1, :incremental 0, :qualifier alpha} Looks like you have some old version of 1.1 prior to release. The release version of 1.1 shouldn't have the alpha qualifier. Try upgrading. -- You received this message because you are subscribed to

Re: primitive arrays, am I reading this right?

2010-04-19 Thread Jarkko Oranen
On Apr 19, 1:17 pm, Joel Gluth joel.gl...@gmail.com wrote: (def floatarray (make-array Float/TYPE 2)) (for [i (range (alength floatarray))] (aset floatarray i (float ([1 2] i You can just do (into-array Float/TYPE [1.0 2.0]) There is no need to explicitly cast the vector items as they

Re: Problem with Destructuring in A Function Call

2010-04-16 Thread Jarkko Oranen
On Apr 16, 11:59 am, Bytesource stefan.rohlf...@gmail.com wrote: Hi, I am currently reading Programming Clojure but got stuck at the destructuring done in the head-overlaps-body? function call that is part of the snake game: (defn head-overlaps-body? [{[head body] :body}]   (includes?

Re: Problem with Destructuring in A Function Call

2010-04-16 Thread Jarkko Oranen
On Apr 16, 5:25 pm, Asim Jalis asimja...@gmail.com wrote: It does conform to the pattern that the bound variable precedes the value to bind in forms like let. A benefit of this ordering is that destructuring patterns like {:keys [a b c]} are unambiguous. Hi Per, Could you explain the

Re: New clojure support in Polyglot Maven

2010-04-08 Thread Jarkko Oranen
Hopefully you can see that this syntax falls out of the direct construction of maven Model object, unmediated by intermediate syntax or data structuring. So there's a good reason for the way it looks. Right. Thanks for the thorough explanation. It's not so bad if you quote the vectors

Re: defprotocol's support for variadic arguments seems broken

2010-04-06 Thread Jarkko Oranen
On Apr 6, 8:16 am, Zach Tellman ztell...@gmail.com wrote: Possibly this fall out from the latest commit requiring an explicit 'this' reference (ba6cc3b), I haven't checked any versions but the most recent. user (defprotocol Protocol (f [a b c])) Protocol user (def p (reify Protocol (f [a

Re: A syntax question: positional keyword

2010-04-06 Thread Jarkko Oranen
On Apr 7, 12:25 am, Sophie itsme...@hotmail.com wrote: Just curious   - what folks think of fixed-positional-keyword params   - whether it was considered for Clojure I don't know for certain whether Rich ever considered smalltalk-style parameters, but I doubt it. I do like them, though; in

Re: copying structures

2010-03-30 Thread Jarkko Oranen
The def was for legibility (or I was going for legibility). Speaking of redefing, is there a way to block a redef so I or someone else doesn't monkey-patch a function? You can set a validator on the Var to prevent accidents. However, someone who really wants to redefine a function can just

Re: Impact of gen-class on clojure-ness

2010-03-29 Thread Jarkko Oranen
Specifically, I prefer to define the important components of my software as Java interfaces. Partly to see myself think, partly because it just makes more sense to me. I then want to implement these interfaces using gen-class and clojure functions and pass resulting objects as function

Re: copying structures

2010-03-29 Thread Jarkko Oranen
On Mar 29, 1:26 am, strattonbrazil strattonbra...@gmail.com wrote: Is this the common way to do it? (def sister (assoc brother :name Cindy)) Please note that actually def'ing each value is not what you're supposed to do :) def is reserved for global constants and dynamically rebindable

Re: Choosing a Clojure build tool

2010-03-26 Thread Jarkko Oranen
On Mar 26, 8:53 am, Per Vognsen per.vogn...@gmail.com wrote: It's not semantic nitpicking. There's a clear-cut difference a piece of reusable code with a function that can be called to generate a bundled Windows installer based on a set of arguments versus something that only works as part

Re: ANN: Kanshiki Boom! - Japanese handwriting recognition

2010-03-26 Thread Jarkko Oranen
This looks neat. I probably won't find much use for it though, as my input method already has this functionality, and even that doesn't get much use due to the fact that I am horrible at writing kanji with the mouse (I'm left-handed, but my mouse-hand is right.) If you have no plans to try to

Re: Beginning Clojure. Recursion

2010-03-25 Thread Jarkko Oranen
jfr wrote: Hello, I've just started to play a little bit with clojure to get a feel for the language. It seems to be quite interesting (and it's a relief to leave my clumsy IDE behind and use Emacs). Concerning immutable data: Is the following code ok or should (must) I use transients as

Re: Sequential vs. divide and conquer algorithm

2010-03-21 Thread Jarkko Oranen
On Mar 19, 6:53 pm, Andrzej ndrwr...@googlemail.com wrote: I've been toying with various implementations of reduce-like functions, trying to do something smarter than a simple iteration over a collection of data. This hasn't worked out very well, my implementation is a lot (~50x) slower than

Re: lazy-cons

2010-03-20 Thread Jarkko Oranen
On Mar 20, 1:52 pm, Glen Rubin rubing...@gmail.com wrote: Hey all, I am working through the problems on project euler.  On question number 11 (http://projecteuler.net/index.php?section=problemsid=11), I was unable to come up with a solution, so I cheated and looked at some other people's

Re: Why do functions in the state monad only accept one value?

2010-03-17 Thread Jarkko Oranen
On Mar 17, 1:17 am, Steven E. Harris s...@panix.com wrote: Michał Marczyk michal.marc...@gmail.com writes: a State-using programme builds up a stateful computation first, then uses runState (or perhaps execState / evalState) to run it as a whole; only at this final step does the initial

Re: Why do functions in the state monad only accept one value?

2010-03-16 Thread Jarkko Oranen
What would be lost by defining Clojure bind operator like this:   (fn m-bind-state [mv f]     (fn [s]       (let [[v ss] (mv s)]         (f v ss Is there more to it than, Monadic functions must return monadic values. My first thought was that it would be problematic for the result

Re: Why do functions in the state monad only accept one value?

2010-03-16 Thread Jarkko Oranen
*facepalm* I should've known GG was just hiding the post from me. -- 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: Why do functions in the state monad only accept one value?

2010-03-16 Thread Jarkko Oranen
Is there more to it than, Monadic functions must return monadic values? Any clarifying advice would be welcome. Gah, I already wrote a reply, but looks like I lost it somehow. To summarise: I think one of the main benefits of the monad abstraction is the uniformity of all monads. ie. all

Re: objects, interfaces and library design

2010-03-03 Thread Jarkko Oranen
On Mar 3, 7:47 pm, cageface milese...@gmail.com wrote: I've been reading through the examples of OO in clojure using multi- methods and they certainly seem very flexible and powerful. I'm wondering, however, how people handle interface library design. If people can implement objects as maps,

Re: newbie question: Please help me stop creating constructors

2010-03-01 Thread Jarkko Oranen
On Mar 1, 9:55 am, Richard Newman holyg...@gmail.com wrote:    (defn house-sale-profit      [house-sales-price house-sale-expenses]      (- house-sales-price house-sale-expenses)) I'd like to note that if you do this, you might just as well use the - function directly. It's not as flexible

Re: Question about how to write efficient code in functional style

2010-02-28 Thread Jarkko Oranen
On Feb 28, 4:03 pm, Heinz N. Gies he...@licenser.net wrote: How about reducing it? Something along the limes of: (not tested) (reduce (fn [lists number]         (update-in lists [           (if (odd? number)           (if (= 0 (mod number 5) :odd-5 :odd)           (if (= 0 (mod number

Re: functional abstraction

2010-02-28 Thread Jarkko Oranen
On Feb 28, 7:36 pm, reynard atsan...@gmail.com wrote: Perhaps my choice of function names (abstract and concrete) for my original post is not very appropriate.  I did not mean to apply the OO concept of abstract class, abstract methods, etc.  Since it seems that my original post did not

Re: functional abstraction

2010-02-27 Thread Jarkko Oranen
On Feb 27, 9:10 pm, reynard atsan...@gmail.com wrote: This may be more about functional programming in general, rather than clojure specific.  However, since I mainly use clojure for learning functional programming, I would like to discuss it here. Basically, I can think of the following 2

Re: Prefixed or suffixed symbols?

2010-02-25 Thread Jarkko Oranen
On Feb 25, 12:17 am, joshua-choi rbysam...@gmail.com wrote: When it comes to distinguishing certain types of symbols from other things, should one use prefixes or suffixes? Whichever makes more sense, of course. :) Example: naming tests with clojure.test/deftest. If you distinguish your

Re: funny (?) str behavior

2010-02-24 Thread Jarkko Oranen
On Feb 23, 10:47 am, Alfred Tarski atar...@gmail.com wrote: Hi, I have this function: (defn wrap [x]   (str % x %)) and I do bf= (str boo hoo (map wrap [fdfd ggfs])) boo hoo clojure.lang.lazy...@9e050eb0 This looks odd to me, but if the powers that be consider this to be the right

Re: Do I need to add dosync when I read the ref in this case

2010-02-21 Thread Jarkko Oranen
But surely in this case you could do: (defn print-info []   (let [[src dst] (dosync [...@source-account @dest-account])]     (println src)     (println dst))) or maybe: (defn print-info []   (let [[src dst] (dosync                     (ensure source-account)                    

Re: First program, in case you want to give hints

2010-02-16 Thread Jarkko Oranen
On Feb 16, 12:26 pm, alux alu...@googlemail.com wrote: Hello, the current state of Conway's Prime Machine is athttp://paste.lisp.org/+21BR Instead of using a quoted list, a vector is more idiomatic in Clojure. I'l go on learning. The next state should be seperation of print and produce.

Re: newbie question: Please help me stop creating constructors

2010-02-16 Thread Jarkko Oranen
On Feb 16, 8:27 pm, Yaron ygol...@gmail.com wrote: Sean and Richard perhaps I can address both of your mails in a single go. Here is an example of one of the functions from my calculator: (defn tax_deductible_expenses         The total expenses incurred in business month m that are

Re: how to use with-bindings*

2010-02-15 Thread Jarkko Oranen
On Feb 15, 12:03 pm, Аркадий Рост arkr...@gmail.com wrote: oh wait...I take a look on binding and with-binding* realesation.http://github.com/richhickey/clojure/blob/f4c58e3500b3668a0941ca21f9a... Why with-binding* function wasn't write like this: (defn with-bindings*   [bindings f args]  

Re: Inheriting from IDeref - good idea or bad practise?

2010-02-08 Thread Jarkko Oranen
On Feb 8, 3:22 am, Stuart Halloway stuart.hallo...@gmail.com wrote: IMO Anything that implements IDeref should adhere to Clojure's vision   for identity, e.g. reads need to be thread safe, cheap, require no   coordination, and block no one. Dereferencing futures or undelivered promises block

Re: How to Initiate Clojure Application

2010-02-01 Thread Jarkko Oranen
On Feb 1, 3:16 pm, Timothy Pratley timothyprat...@gmail.com wrote: On 1 February 2010 09:32, Wardrop t...@tomwardrop.com wrote: Could someone step me through the idea behind the -main function (which I've also seen written as just main without the hyphen). Is -main special in any way, or

Re: Suggestion: Get rid of java.lang.Exception: EOF while reading..

2010-01-27 Thread Jarkko Oranen
You should really give paredit.el a go some time. It feels silly to worry about matching parentheses nowadays. That aside, I am supportive of any improvement in either compiler or reader error messages. -- You received this message because you are subscribed to the Google Groups Clojure group.

Re: What are Vars supposed to be used for?

2010-01-24 Thread Jarkko Oranen
On Jan 24, 6:40 am, CuppoJava patrickli_2...@hotmail.com wrote: Thanks for the reply. That seems to match well with how I thought they were supposed to work. I'm just a little confused by the set!, with-local-vars, functions. What are they supposed to be used for?   -Patrick Vars are

Re: What's the idiomatic way to parse a binding form

2010-01-12 Thread Jarkko Oranen
On Jan 12, 11:08 am, Gabi bugspy...@gmail.com wrote: What's the idiomatic Clojure way for extracting values/keys from a binding form vector [key1 val1 key2 val2..] ? I suppose that depends on what you want, but: (apply hash-map keyvals) to make a map or (map first (partition 2 keyvals)) (map

Re: 1.1.0 *release* of clojure-contrib?

2010-01-05 Thread Jarkko Oranen
On Jan 6, 2:21 am, Mark Derricutt m...@talios.com wrote: Is there likely to be a RELEASE version of clojure-contrib 1.1.0 in the maven repo to match clojure 1.1.0 at all? The lack of a release build prevents using the maven release plugin to run with any project using it :( Also - if

Re: Code arrangement for understandability

2009-12-11 Thread Jarkko Oranen
On Dec 11, 11:14 am, ngocdaothanh ngocdaoth...@gmail.com wrote: Because of indents, my previous Clojure code lied to my eyes that x, y, f, g are not at the same block level. This is my difficulty with Clojure. In short, I can't see a rough algorithm from any Clojure code any more just by

Re: Code arrangement for understandability

2009-12-11 Thread Jarkko Oranen
((comp negate inc) 6) - -7 Hm, I was sure negate existed... But seems like it doesn't. Oh well. (comp - inc) works. :) -- 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

Where is the Clojure 1.0 API documentation?

2009-12-09 Thread Jarkko Oranen
I just noticed that the API link on the clojure web site brings up documentation for the master branch of Clojure instead of 1.0.0. I can't find the 1.0.0 docs anywhere either. This is obviously a problem for 1.0.0 users, since the docs refer to features that don't exist. I think it would be

Re: Question about The whole language is there, all of the time.

2009-12-09 Thread Jarkko Oranen
Jeff Dik wrote: The part Running code at read-time lets users reprogram Lisp's syntax caught my attention. Is this talking about reader macros? I believe I read that clojure doesn't have reader macros, so would it be more accurate to say The whole language is there, _most_ of the time?

Re: Java Class Factory

2009-12-03 Thread Jarkko Oranen
On Dec 3, 6:15 am, lazy1 miki.teb...@gmail.com wrote: Hello, I'm trying to create a factory method for Java classes, however I'm doing something wrong. (import '(java.util Dictionary HashMap)) (def *containers* { :dict Dictionary :hash HashMap}) (defn new-container   [type]   (new

Re: Suggestion: Add should_cache? flag to lazy-seq

2009-11-20 Thread Jarkko Oranen
On Nov 19, 11:52 am, Gabi bugspy...@gmail.com wrote: This would solve the holding to the head problem. Many times, lazy-seq would be used without the need to get the same cell twice. In this case, avoiding cashing would both enhance performance and more importantly would avoid

Re: ExceptionInInitializerError in eval with user defined functions

2009-11-14 Thread Jarkko Oranen
On Nov 14, 8:08 pm, gun43 bg-561...@versanet.de wrote: Using r1366 under Win XP. r1366? From Subversion? That's ancient. Clojure moved to git ages ago; see http://github.com/richhickey/clojure A user defined function: 1:27 user= (defn plus2 [x] (+ x 2)) #'user/plus2 1:28 user= (plus2 5)

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Jarkko Oranen
On Nov 13, 9:13 am, Krukow karl.kru...@gmail.com wrote: I was thinking this may make syntax irregular. I suspect this is a deliberate design choice to distinguish clojure protocols from java interfaces? Is this the case? As far as I understand it, in defprotocol's case, I suspect there is no

Re: Is it possible to implement break or return in Lisp?

2009-11-02 Thread Jarkko Oranen
On Nov 3, 2:03 am, CuppoJava patrickli_2...@hotmail.com wrote: Thanks Brian. For my own purposes, yes I have no need for a break or return statement. But I'm writing a DSL for others to use. People that don't have experience with functional programming, and for them it's easier to have a

Re: clojure / ruby yield comparison

2009-10-25 Thread Jarkko Oranen
But whilst this is useful, this doesn't really demonstrate why macros are so powerful. Macros are useful because they automatically rearrange your source code into something else. They're most similar to the Ruby 'eval' function, but operate of data structures rather than strings. Nitpick,

Re: Beginner: java.lang.Integer cannot be cast to clojure.lang.IFn (repl)

2009-10-19 Thread Jarkko Oranen
On Oct 19, 5:52 pm, Peregrine stiebs...@gmail.com wrote: Hey I am new to Clojure and I am doing some Project Euler problems to help me get started with the language. I've run into a issue I cannot seem to get past. I have this code: (defn findFib         Find the sum of all the even-valued

Re: let-while

2009-10-17 Thread Jarkko Oranen
On Oct 17, 10:32 am, Timothy Pratley timothyprat...@gmail.com wrote: But name is multiply evaluated. This might be preferable: Hi John, Could you explain this a bit more for me? I can understand if the condition is duplicated that is unnecessary calculation but don't appreciate the issue

Re: function names ending with !

2009-10-16 Thread Jarkko Oranen
On Oct 16, 5:44 pm, Mark Volkmann r.mark.volkm...@gmail.com wrote: What's the rule of thumb for deciding whether a function name should end with an exclamation point? I thought maybe it was when the function modifies its first argument, but it seems there are functions that do that and do not

Re: ANN: scriptjure, a library for generating javascript

2009-10-07 Thread Jarkko Oranen
On Oct 8, 5:01 am, Allen Rohner aroh...@gmail.com wrote: Hello, I'd like to announce the availability of a new library, called Scriptjure. It's a macro that generates javascript strings from Clojure s-exprs. My initial use for it is in glue code for Clojure webapps. For example:  (js (fn

Re: Syntax for proxy methods?

2009-10-01 Thread Jarkko Oranen
On Oct 1, 9:18 pm, timc timgcl...@gmail.com wrote: snip (def prx (proxy [IX][]   (doit     ([] (doseq [x someSeq] (doit x))     ([y] (print y When I tried something of this form, it looks like the call of the 1- arg function from the 0-arg function can't be resolved. Thanks in

Re: how to understand macro in clojure?

2009-09-28 Thread Jarkko Oranen
On Sep 28, 12:13 pm, Michael Wood esiot...@gmail.com wrote: Hi 2009/9/26 gerryx...@gmail.com gerryx...@gmail.com: (defn float2 [f a b]  (f (float a ) (float b))) (float2 + 1 2) = 3.0 (defmacro mfloat2 [f a b]  (f (float a) (float b))) (mfloat2 + 1 2 ) = 2.0  ???   macro

Re: Naming structs

2009-09-24 Thread Jarkko Oranen
On Sep 24, 11:01 am, Miron Brezuleanu mbr...@gmail.com wrote: Hello, I find that I tend to name struct instances like the struct. For instance, (defstruct person :name) and then (let [person (struct person John)] ) which breaks further use of (struct person ...) in that let. Is

Re: How to override .toString for a struct?

2009-09-22 Thread Jarkko Oranen
On Sep 22, 2:23 am, Jung Ko koj...@gmail.com wrote: Hi, Can someone teach me how I can override the toString method for a struct ? Here's a code snippet that shows what I'm trying to do: user (defstruct bookinfo :book :filename) user (struct bookinfo hello world) = {:book hello,

Re: - with anonymous functions

2009-09-22 Thread Jarkko Oranen
On Sep 22, 3:58 pm, Roman Roelofsen roman.roelof...@googlemail.com wrote: Hi there! Lets assume I have this map: user= (def person {:name Father :childs [{:name Son :age 10}]}) Testing: user= (- person :childs first) {:name Son, :age 10} Now lets filter the child map: user= (def

Re: Q: dosync semantics

2009-09-21 Thread Jarkko Oranen
On Sep 21, 4:38 pm, Roger Gilliar ro...@gilliar.de wrote: I still have some problems to correctly understand the dosync   semantic.  What happens exaclty if two threads try to modify the same   list: Nitpick: you're not modifying any lists. :) The only mutating things are the Refs

Re: delays are forced by deref too early?

2009-09-21 Thread Jarkko Oranen
On Sep 21, 6:53 pm, patrickdlogan patrickdlo...@gmail.com wrote: I expected a delay only to be forced by an explicit call to force. instead it looks like, being a kind of IDeref, a delay will be forced by the REPL. e.g. user= (def del (delay (println printed) (+ 2 3))) #'user/del user=

Re: OutOfMemoryError with loop/recur

2009-09-18 Thread Jarkko Oranen
On Sep 18, 10:52 pm, Patrik Fredriksson patri...@gmail.com wrote: Hi! Could someone please help me understand why the following causes a java.lang.OutOfMemoryError: Java heap space for large n:s (10 works fine, 100 does not). (def integers (iterate inc 1)) (defn limited-reduce

Re: Redefining Special Forms

2009-09-17 Thread Jarkko Oranen
On Sep 17, 7:33 pm, Gorsal s...@tewebs.com wrote: Basically i need to redefine the meaning of a special form. While i am willing to change the name for things like ns to defpackage, i am not willing to change the name of forms like apply and defn to achieve my goals. Instead, i would like

Re: Unwind-protect?

2009-09-15 Thread Jarkko Oranen
On Sep 15, 6:54 pm, Gorsal s...@tewebs.com wrote: I was just wondering about the unwind-protect form, I've heard that it doesn't protect against certain types of exits, but what exactly are these exits? I've heard return, break, and continue statements said but i can't seem to find these

Re: Pong!

2009-09-13 Thread Jarkko Oranen
On Sep 13, 2:43 am, jng27 jgran...@gmail.com wrote: http://jng.imagine27.com/articles/2009-09-12-122605_pong_in_clojure.html Neat. I have some suggestions though. 1) I think you use too many refs. the sx, sy, etc. could all be replaced with a simple (defstruct position :x :y) (def

Re: Fixing production systems on-the-fly

2009-09-04 Thread Jarkko Oranen
On Sep 4, 11:22 am, Krukow karl.kru...@gmail.com wrote: I was thinking about the capability of changing production systems on the fly. E.g. by having an accessible repl in a running production system. If you have a bug in a function, you can fix it by re-def'ing it - that is great. However,

Re: Eval troubles

2009-09-03 Thread Jarkko Oranen
On Sep 3, 9:24 am, Miron Brezuleanu mbr...@gmail.com wrote: Hello, I'm a Clojure newbie (many thanks to Rich Hickey and everyone involved - it's a great programming environment) and I have some trouble with 'eval'. What I'm trying is: $ java -cp clojure.jar clojure.lang.Repl Clojure

Re: Lazy binding

2009-09-03 Thread Jarkko Oranen
On Sep 3, 3:42 pm, ngocdaothanh ngocdaoth...@gmail.com wrote: Hi, In Rails you can create a view like this: my_view.erb: %= hello + @name % I'm new to Clojure. I want to create something like the above like this: (defn my-view []   (str hello name)) The point is: * name is not

Re: with-open should use a close multimethod?

2009-08-28 Thread Jarkko Oranen
I'll submit a patch if it's wanted.  This would fit in core, or maybe contrib.duck-streams with a slightly different name. This should be in core I think, so that it can work with with-open— unless we're going to duplicate with-open in contrib. :/ -- Jarkko

Re: Symbol to keyword

2009-08-25 Thread Jarkko Oranen
On Aug 25, 1:47 pm, Dragan Djuric draga...@gmail.com wrote: I needed a macro if I wanted to avoid ' in calls. It may seem as nitpicking but (to-keyword name) is more readable and less error prone than (to-keyword 'name) if I need to  use it in lots of places. If that's all you do, then the

Re: Calculating digits of π (Salamin-Brent)

2009-08-22 Thread Jarkko Oranen
On Aug 22, 5:56 am, jng27 jgran...@gmail.com wrote: Took a shot at implementing PI in Clojure using a reasonably fast algorithm. So why is it so slow ? Is BigDecimal just that bad ? Would fixed point arithmetic be better using BigInteger ? Hmm, my impression is that the java boxed numbers

Re: Calculating digits of π (Salamin-Brent)

2009-08-22 Thread Jarkko Oranen
On Aug 22, 1:51 pm, jng27 jgran...@gmail.com wrote: This updated version is 2x as fast as the previous version : (import 'java.lang.Math) (import 'java.math.MathContext) (import 'java.math.BigDecimal) (defn sb-pi [places]   Calculates PI digits using the Salamin-Brent algorithm    and

Re: what's the appropriate way to process inner nested seqs in clojure?

2009-08-16 Thread Jarkko Oranen
On Aug 16, 12:02 pm, botgerry botge...@gmail.com wrote: Hello,all I'm new to functional programming,want to know how to address nested inner seqs in clojure (def a [[1 2 3 4] [ ok metoo] [ 5 8 9 ]]) 1:  searching in a, if find one inner vector includes number 9 then append it a number 13

Re: How to have a fast access to a java array of non-primitives?

2009-08-15 Thread Jarkko Oranen
Nicolas Oury wrote: Dear all, I try to write a program where I access a java array of non primitive and realize aget is very slow. (6x slower than the same program with clojure vectors instead of java arrays access) I tried a few combinations of type hints but can't manage to prevent mty

Re: Proposal: Promote clojure.contrib.def to a core lib

2009-08-14 Thread Jarkko Oranen
I'm in favour. Though, I think that a def- would be redundant if the defvar macros are promoted. Perhaps it would be sensible to keep def as a the underlying special form and just move in defvar, defvar- and defmacro-. I'm not sure whether defonce is useful enough that it should be moved to

Re: Clojure Golf, episode 1

2009-08-14 Thread Jarkko Oranen
On Aug 14, 10:51 pm, Sean Devlin francoisdev...@gmail.com wrote: I'd start with you usage docs ;; usage: ;; (filter-collecting ;;   (fn [x y] ( x y)) ;;   (fn [x y] (+ x y)) ;;   [1 7 3 9] ;;   [5 5 5 5]) ;;  == (6 8) ;; usage: ;; (filter-collecting + ;; [1 7 3 9] ;; [5 5 5 5])

Re: Adding optimizations to Clojure

2009-08-14 Thread Jarkko Oranen
fft1976 wrote: On Aug 13, 9:57 pm, Daniel Lyons fus...@storytotell.org wrote: the code is open source and the techniques for adding   optimizations to compilers are well known. So marshall your impulses   for the good and we'll all benefit. It does seem that the optimizations Andy

Re: Pure-functional N-body benchmark implementation

2009-08-10 Thread Jarkko Oranen
On Aug 10, 12:41 pm, fft1976 fft1...@gmail.com wrote: I just uploaded to the group an implementation of the n-body benchmark in Clojure (see nbody_init.clj) http://shootout.alioth.debian.org/u32/benchmark.php?test=nbody〈=j... My goal was to write a pure-functional version and to avoid any

Re: transient quicksort

2009-08-04 Thread Jarkko Oranen
On Aug 4, 11:08 am, Jonas jonas.enl...@gmail.com wrote: Hi I'm playing with the new transient/persistent! features in Clojure. I have implemented quicksort as described on wikipedia (http:// en.wikipedia.org/wiki/Quicksort#Algorithm). Here is the code: (defn swap-index! [v i j]   (let

Re: Newbie question about anonymous functions

2009-08-02 Thread Jarkko Oranen
Chad Harrington wrote: I have a newbie question about anonymous functions. Why does the first form below work and the second form does not? user ((fn [] foo)) foo user (#(foo)) ; Evaluation aborted. fn and #() are not interchangeable. In the first example, you simply return foo.

Re: Possible addition to swing-utils?

2009-08-02 Thread Jarkko Oranen
On Aug 2, 2:12 am, Meikel Brandmeyer m...@kotka.de wrote: (defmacro with-chosen-file    Opens a file chooser, binds the result the user chose to the given    variable name and executes the body. In front of the body there might    be two options given:      :directory is the initial

Re: let a variable number of bindings

2009-07-18 Thread Jarkko Oranen
user= (macroexpand-1 '(let-coll [a b c] {:a 1 :b 2 :c 3} (println a b   c))) (clojure.core/let [val-fn__23 {:a 1, :b 2, :c 3}                     a          (val-fn__23 :a)                     b          (val-fn__23 :b)                     c          (val-fn__23 :c)]    (println a b c))

Re: turn a seq into a list

2009-07-15 Thread Jarkko Oranen
On Jul 15, 1:54 pm, Jan Rychter j...@rychter.com wrote: I've been looking for a function that would take a seq and create a list (a real clojure.lang.PersistentList), but haven't found one. The closest I got was: (apply list my-seq) Essentially, I'm looking for something similar to (vec)

Re: clojure.test - Test fixtures and ordering

2009-07-14 Thread Jarkko Oranen
On Jul 14, 6:58 pm, Stuart Sierra the.stuart.sie...@gmail.com wrote: Namespace-wide fixtures (once-fixtures) are easy -- they should just run around the top-level test function.  That's something I can fix, and it will be sufficient for your example. But per-test fixtures (each-fixtures)

Re: another binding issue?

2009-07-14 Thread Jarkko Oranen
On Jul 14, 10:04 pm, bgray graybran...@gmail.com wrote: I'm not sure if this is a binding issue or not. user= (def a 1) #'user/a user= (binding [a 3] (filter #(= % a) '(1 2 3))) (1) user= In this case, I was expecting a list with 3 in it. This is a common gotcha. It's actually a

Re: Using Ref

2009-07-13 Thread Jarkko Oranen
On Jul 13, 1:39 pm, sailormoo...@gmail.com sailormoo...@gmail.com wrote: Hi :   I would like to simulate a simple database with the STM of clojure. The rules are 1. There can be many rooms, and each room has its own attirbute 2. One room contains many people, and each person has its own

Re: Why do Enlive template functions return a seq instead of a str?

2009-07-11 Thread Jarkko Oranen
On Jul 11, 6:01 pm, Robert Campbell rrc...@gmail.com wrote: Hey guys, I'm just curious why Christophe chose to return seq instead of a str for Enlive for his template functions. Example: (deftemplate my-page-transformation index.html [message style]   [:style] (content style)   [:h1]

Re: Questions / guidelines for adopting Clojure

2009-07-07 Thread Jarkko Oranen
snip Shawn Hoover wrote: For example, Java doesn't have language support like C#'s using statement for executing some block of code and deterministically cleaning up an object at the end. You could implement that as a function (in many languages) and call it like this: (defn do-and-close [o

Re: tests involving threads

2009-07-06 Thread Jarkko Oranen
On Jul 6, 7:51 am, Timothy Pratley timothyprat...@gmail.com wrote: Very glad that test is now part of clojure core. I've run into 2 strange behaviours when trying to write tests where threads are involved. My case is a little complex so here is a minimal version which shows what I mean:

Re: Adding type hint causes compiler error

2009-07-06 Thread Jarkko Oranen
On Jul 6, 1:26 pm, philip.hazel...@gmail.com philip.hazel...@gmail.com wrote: On Jul 5, 10:31 pm, Mark Triggs mark.h.tri...@gmail.com wrote: (defn bi-get-pixels   [#^BufferedImage bi]   (let [raster (.getData bi)         pixels (.getPixels raster 0 0 (.getWidth bi) (.getHeight bi)  

Re: ANN: libraries promoted from contrib to clojure

2009-06-29 Thread Jarkko Oranen
On Jun 29, 6:14 pm, John D. Hume duelin.mark...@gmail.com wrote: There may already have been a discussion about this in IRC, but I would have loved to see the 'are' macro continue to support the old syntax (maybe with deprecation warnings) as well as the new until after 1.1 is released.

Re: Buggy behavior of recur with primitives

2009-06-28 Thread Jarkko Oranen
On Jun 28, 8:53 am, Handkea fumosa hfum...@gmail.com wrote: (defn foo [z-r z-i c-r c-i bailout max-iters]   (let [G__12819 (double c-r)         G__12820 (double c-i)         G__12817 (double -1)         G__12818 (double 2)         mi (int max-iters)         b (double (* bailout bailout))]

Re: Trying to use lazy-seq for the first time, failing.

2009-06-27 Thread Jarkko Oranen
On Jun 27, 3:23 am, _hrrld hhaus...@gmail.com wrote: Hi, I'm trying to use lazy-seq to implement a cool piece of functionality I saw in the Factor programming language. Here is the documentation for that functionality:http://docs.factorcode.org/content/word-produce,sequences.html I think

Re: Trying to use lazy-seq for the first time, failing.

2009-06-27 Thread Jarkko Oranen
On Jun 27, 3:23 am, _hrrld hhaus...@gmail.com wrote: Hi, I'm trying to use lazy-seq to implement a cool piece of functionality I saw in the Factor programming language. Here is the documentation for that functionality:http://docs.factorcode.org/content/word-produce,sequences.html I

Re: Roadmap of Clojure 1.1

2009-06-25 Thread Jarkko Oranen
On Jun 25, 9:51 am, michael frericks michael-freri...@web.de wrote: Hello, i am a little bit lost about the roadmap of clojure 1.1. Is there anywhere an (evolving) list available of a) new features planned, b) things that break Clojure 1.0 c) and maybe removed features? You could take

  1   2   >