Re: Trouble implementing Dijkstra algorithm in Clojure

2009-12-07 Thread harrison clarke
you can use recur. it calls the fn/loop it's contained in with new args. (so, with the updated array and queue) On Dec 7, 8:19 pm, ajay wrote: > Hi all, > > I am new to FP in general and I am trying to pick up Clojure. I am > having trouble thinking in FP terms. > > I am trying to implement the D

Re: Datatypes and Protocols - early experience program

2009-11-17 Thread harrison clarke
can anyone explain why this doesn't work? (defprotocol arrow (>>> ([f g] [f g & fs]) "compose left to right")) (extend clojure.lang.Fn arrow {:>>> (fn ([f g] #(g (f %))) ([f g & fs] (apply >>> (>>> f g) fs)))}) (>>> inc inc inc) ; gives this error: ; java.lang.IllegalA

Re: pointfree library

2009-10-31 Thread harrison clarke
i have updated the library to use arrows, rather than just functions. (it still works with functions) to make a new kind of arrow, you need to implement: arr (creates an arrow from a function) >>> (combines arrows left to right) fst (makes arrow work on the first element of a vector, leaving the

Re: pointfree library

2009-10-29 Thread harrison clarke
. > > >>> is the same as (reverse (comp x)) right? > > &&& is called juxt > *** - I believe this (map (juxt f-coll) coll) > > curry is called partial > > Still, good to see the comparison. > > On Oct 29, 10:20 am, harrison clarke wrote: > &g

Re: pointfree library

2009-10-29 Thread harrison clarke
rry wrote: > Would love to see some examples usages of these > > On Sun, Oct 25, 2009 at 4:16 PM, harrison clarke wrote: > > > > > > > so i was using haskell, and the pointfree stuff is fun, so naturally i > > had to implement some of it in clojure. > > >

Re: Scientific computing

2009-10-28 Thread harrison clarke
maps could also be an option. you can use vectors of ints as keys. (and you can stick dimensions and such in there with keywords) i'm not sure how that compares to nested vectors for perforance. you have the overhead of the hash function, but you don't have any nesting. it's also pretty handy if

pointfree library

2009-10-25 Thread harrison clarke
so i was using haskell, and the pointfree stuff is fun, so naturally i had to implement some of it in clojure. this is what i have so far. library and examples within: http://github.com/hclarke/pointfree-clojure it has >>>, &&&, ***, +++, |||, and others they take functions as arguments and retu

Re: Transient Data Structures

2009-08-04 Thread harrison clarke
you can't really use this as regular old mutable data. if you store it somewhere, and then you change it, the original will break. i don't really see how you could use this in a non-functional way and still have it work at all. like, you probably won't actually be let-binding them very often. see

Re: Functional programming newbie question

2008-12-14 Thread harrison clarke
yep. a function f(n) is O(n) if there are constants c and n0 such that f(n) <= c * n for all n >= n0. sometimes you do care about the c and the n0, though. On Sun, Dec 14, 2008 at 12:41 PM, levand wrote: > > Ah, ok... I would have assumed that would be labeled as O(2n). Didn't > realize that was

Re: Lazy sequences without caching?

2008-12-09 Thread harrison clarke
ue, Dec 9, 2008 at 3:48 PM, Drew Olson <[EMAIL PROTECTED]> wrote: > On Tue, Dec 9, 2008 at 2:28 PM, Stephan Mühlstrasser < > [EMAIL PROTECTED]> wrote: > >> >> On Dec 9, 12:34 am, "harrison clarke" <[EMAIL PROTECTED]> wrote: >> > you're k

Re: Lazy sequences without caching?

2008-12-08 Thread harrison clarke
you're keeping the head of the sequence, and thus all the elements between the head and nth. it's because you're using def, basically. if you make a function to return the sequence, and pass the result directly to nth, without let-binding it or anything, it should work. --~--~-~--~~-

Re: Bug (I think): Can't sort collection of vectors containing big integers

2008-12-04 Thread harrison clarke
the same issue is there for sorted-map and sorted-set. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, sen

Re: Bug: recur won't work in tail position within cond

2008-12-03 Thread harrison clarke
did cond change syntax? last i checked, it was (cond (case) (expr) (case) (expr) ) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojur

Re: delimited continuations for web development

2008-12-03 Thread harrison clarke
the hard part about implementing continuations in a language that doesn't already support them is that you're trying to capture it from within. with a delimited continuation, you're capturing it from the outside, so you don't have that problem. --~--~-~--~~~---~--~

Re: quit

2008-11-30 Thread harrison clarke
another issue would be that your function call would have to be on one line. (the nested ones could have multiple lines, since they'd be in parens) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To p

Re: number boxing issue in prime number sieve?

2008-11-23 Thread harrison clarke
found the problem: sorted-set doesn't play nice with longs. the "fix" to my specific problem is to not square the primes when adding new counters. any way to change the comparator on a sorted set? i'd also like to use lazy seq's as counters, and it doesn't liek that either. --~--~-~--~--

number boxing issue in prime number sieve?

2008-11-23 Thread harrison clarke
i made a lazy prime number seive, and it seems to work for a while: (defn natural [] (iterate #(+ % 1) 1)) (def primes ;;takes a sorted set of counters and a seq of numbers to filter ((fn sieve [in-counters checked] ;;first part of the cons is the first in said seq. hurray!

Re: mutability

2008-11-20 Thread harrison clarke
i was thinking that each stat would be an agent. whatever boats your float, i guess. i'm probably not the person to go to about idiomatic code. :V user> (let [player {:str (agent 5) :dex (agent 5)} str (:str player) dex (:dex player)] (println @str @dex) (send str +

Re: mutability

2008-11-20 Thread harrison clarke
> (send (:str player) #(+ % 1)) on second thought, this should be the same: (send (:str player) + 1) or: (send (player :str) + 1) if you use agents, just make sure you use await before dereferencing them. could cause some issuses if you don't. --~--~-~--~~~---~--~---

Re: mutability

2008-11-20 Thread Harrison Clarke
i think agents would be a better fit than refs. as you said, you don't need transactions, since everything is sequential anyway. so whenever you need to change something, just send the change to the agent. (send (:str player) #(+ % 1)) --~--~-~--~~~---~--~~ You r