Idea for algorithm for renaming in an Clojure IDE

2012-04-13 Thread André Ferreira
I was thinking about how things like function or variable renaming are complicated by lisps macros. That it's almost impossible to track the scope of anything, since 2 symbols near each other might mean completely different things after macro expansion. So I came up with an algorithm that *might* w

Re: Regarding lexical scoping and usage of 'let' in a recursive function call

2010-11-12 Thread André Ferreira
Well, a more important matter, this example in the documentation of atom is wrong! The recursive calls will not be memoized if called like that. Running this code clearly shows: (defn memoize [f] (let [mem (atom {})] (fn [& args] (if-let [e (find @mem args)] (val e) (le

Re: Confused about "=", native java arrays and seqs...

2010-03-24 Thread André Ferreira
Arrays are mutable, seqs immutable. Clojure ='s compares immutable structures by value, and mutable structures by reference (for the objects that it is aware of, for others it just prays that they have a resoanable equals method). This behaviour is described in the very interisting Henry Baker's eg

Re: bounded memoize

2010-03-08 Thread André Ferreira
On 8 mar, 23:22, Michał Marczyk wrote: > I'd suggest a vector instead; they're countable in constant time and > you can use, say, conj and rest for add to end of queue / eject from > front of queue. Conj adds to the end of a vector in constant time, but rest will not return another vector, but a

Defn-memo doesn't work for recursive functions

2010-03-07 Thread André Ferreira
;Simple example (defn fib1 [n] (if (or (= 0 n) (= 1 n)) 1 (+ (fib1 (- n 1)) (fib1 (- n 2) (defn-memo fib2 [n] (if (or (= 0 n) (= 1 n)) 1 (+ (fib2 (- n 1)) (fib2 (- n 2) ;workaround for this problem (declare aux-fib) (defn-memo fib3 [n] (if (or (= 0 n) (=

Re: Interesting ICFP slides from Guy Steele -- Organizing Functional Code for Parallel Execution

2010-02-10 Thread André Ferreira
What he said is basically right, only instead of list it's called vector. Not sure if vector branching is 64 or 32. On 10 fev, 15:42, Paul Mooser wrote: > I ran across this on reddit this morning, and thought people on the > group might find it interesting: > > http://docs.google.com/viewer?url=

Re: Clojure Scoping Rules

2009-11-23 Thread André Ferreira
Would it be possible to create an implementation of delay and lazy-seq that didn't use fn to delay evaluation, or atleast captured dynamic variables? (delay (+ x 3)) reasonable semantics in current clojure (let [x x] (delay (+ x 3))) (delay (fn [y] (+ x y))) semantics should be the same it alread

Re: Gensym collisions can be engineered.

2009-11-08 Thread André Ferreira
It's one thing to try to protect the programmer from accidentally shooting himself on the foot, but I don't think it is as necessary for a language to prevent him from doing it on purpose. On 8 nov, 02:59, John Harrop wrote: > user=> (def q 'G__723) > #'user/q > user=> (def r (gensym)) > #'user/

Re: Proposal: New Reader Macro #s{ ... }

2009-10-12 Thread André Ferreira
Lua's solution to long strings is having multiple levels of delimiters. [[ is the opening delimiter of level 0, and is closed by ]] . [=[ is of level 1, closed by ]=] , etc. No matter what string you are trying to represent, it can always be literally represented that way. On 12 out, 17:25, Greg

Re: Is "apply" slow or am I incorrectly benchmarking this?

2009-05-20 Thread André Ferreira
If efficiency is really an issue (if it's not just use apply), how about using a macro for doing the dirty work of writing the direct function application for you? On 20 maio, 19:44, CuppoJava wrote: > Thanks a lot for that really detailed analysis Stephen. > I do find "apply" very convenient in

Amb operator

2009-04-09 Thread André Ferreira
So, I was wondering if anyone had implemented the amb operator in Clojure, so I decided to give it a try. This is my first Clojure program bigger then 5 lines, the code still needs ALOT of work, it is ugly as hell atm, but I think it kind of works. (Yes, I know, it's very easy to bug it, its just

Re: doseq vs. map

2009-04-03 Thread André Ferreira
Laziness is the rule only on sequence operations. On Apr 2, 11:34 pm, Sean wrote: > Thanks for the response everyone!  I was able to get it working.  If I > understand what everyone is saying, the following statement is true: > > In Clojure, laziness is the rule not the exception. --~--~---