Re: non recursive impl in presence of persistence?

2009-01-13 Thread e
ok ok. . . .but yall made lists functions . .. so I could ask the same question of if foo(3): bar(3). if foo a function or a list? It looks like a function. but it's a list, too. . . .because in clojure lists are functions . . . .but only if they take one argument. I didn't start the confusion.

Re: non recursive impl in presence of persistence?

2009-01-13 Thread James Reeves
On Jan 13, 6:45 pm, e wrote: > sure . . . I'm just impressed with how many things "just work", and this > could be one more.  Not enough args, but you know what I wanted it to mean. > There's no ambiguity. This is a bad idea. It just adds confusion with no real benefit. Reading the code would be

Re: non recursive impl in presence of persistence?

2009-01-13 Thread e
sure . . . I'm just impressed with how many things "just work", and this could be one more. Not enough args, but you know what I wanted it to mean. There's no ambiguity. On Tue, Jan 13, 2009 at 2:07 AM, Timothy Pratley wrote: > > > > On Jan 13, 5:57 pm, e wrote: > > Instead of that being an err

Re: non recursive impl in presence of persistence?

2009-01-12 Thread Timothy Pratley
On Jan 13, 5:57 pm, e wrote: > Instead of that being an error, why not overload the vector function so that > no args calls the version that returns the list.  That seems like a good > idea!  I wonder if people will object. Actually in your case that would not work, because l2 can also be nil.

Re: non recursive impl in presence of persistence?

2009-01-12 Thread e
Instead of that being an error, why not overload the vector function so that no args calls the version that returns the list. That seems like a good idea! I wonder if people will object. On Tue, Jan 13, 2009 at 1:23 AM, e wrote: > seriously? Wow! Interesting. > > > On Tue, Jan 13, 2009 at 12

Re: non recursive impl in presence of persistence?

2009-01-12 Thread e
seriously? Wow! Interesting. On Tue, Jan 13, 2009 at 12:53 AM, Timothy Pratley wrote: > > >(if (l2) > > The problem is on this line. (l2) is a function call. > Replace with (if l2 > and it works fine :) > > java.lang.IllegalArgumentException: Wrong number of args passed to: > LazilyPersiste

Re: non recursive impl in presence of persistence?

2009-01-12 Thread Timothy Pratley
>    (if (l2) The problem is on this line. (l2) is a function call. Replace with (if l2 and it works fine :) java.lang.IllegalArgumentException: Wrong number of args passed to: LazilyPersistentVector (NO_SOURCE_FILE:0) The error message bears a little explaining: vectors are functions, user=> (

Re: non recursive impl in presence of persistence?

2009-01-12 Thread e
my unsafe version works now, thanks to a LOT of help. (defn msort [toSort] (with-local-vars [my-list (for [x toSort] [x])] (while (rest @my-list) (let [[l1 l2 & my-list-rest] @my-list] (var-set my-list (conj my-list-rest (listmerge l1 l2))) )) (first @my-list))) now I'm try

Re: non recursive impl in presence of persistence?

2009-01-12 Thread Timothy Pratley
> by the way, Tim, I've seen NB before as comments in J.  What's it stand for? An abbreviation for nota bene, a Latin expression meaning "note well". > I need to learn how to run closure code as a script then. http://en.wikibooks.org/wiki/Clojure_Programming/Getting_Started first section shows

Re: non recursive impl in presence of persistence?

2009-01-12 Thread e
o #2 . . . and I totally lost site of what I was doing with l1 and l2 ! they were already lists because my-list was a list of lists. I new that when I started, like on Friday. On Mon, Jan 12, 2009 at 10:39 PM, e wrote: > o! all the stuff from listmerge ended up in my-list d

Re: non recursive impl in presence of persistence?

2009-01-12 Thread e
by the way, Tim, I've seen NB before as comments in J. What's it stand for? On Mon, Jan 12, 2009 at 10:39 PM, e wrote: > o! all the stuff from listmerge ended up in my-list directly. so > then when listmerge was called on these elements it rightly complained! > Awesome. Lots of good

Re: non recursive impl in presence of persistence?

2009-01-12 Thread e
o! all the stuff from listmerge ended up in my-list directly. so then when listmerge was called on these elements it rightly complained! Awesome. Lots of good lessons coming out of this. I need to learn how to run closure code as a script then. I seem to remember something about this w

Re: non recursive impl in presence of persistence?

2009-01-12 Thread Timothy Pratley
> I just want to get this out of my system, but I'm getting some class cast > exception and no useful line number. In situations like these I find that looking at the entire stack trace provides clues. The REPL by default does not print the entire stack though I'm sure there is a way to achieve t

Re: non recursive impl in presence of persistence?

2009-01-12 Thread e
i forgot about the wiki. why is this maintained in a totally different page from clojure.org? I should be looking at these examples: http://en.wikibooks.org/wiki/Clojure_Programming/Examples/API_Examples On Mon, Jan 12, 2009 at 9:15 PM, e wrote: > I give up.I don't know what's wrong and I

Re: non recursive impl in presence of persistence?

2009-01-12 Thread e
I give up.I don't know what's wrong and I don't want to just punt and go on to a totally different implementation. Can while loops have more that one statement in the body? Maybe it's something dumb. I'm not turning my back on what people say about loop/recur or functional programming. I'm

Re: non recursive impl in presence of persistence?

2009-01-12 Thread James Reeves
On Jan 12, 5:24 am, e wrote: > It's funny, whenever I tried to be all safe like this and take the time to > make stuff safe in C++, coworkers would say, "we are grown-ups.  At some > point you gotta stop being a paranoid programmer. Given that software bugs are a very common occurrence, I'd say

Re: non recursive impl in presence of persistence?

2009-01-11 Thread e
a few fixes. still not there yet. (defn elisort [toSort] (with-local-vars [my-list (for [x toSort] [x])] (while (rest (var-get my-list)) (let [[l1 l2 & my-list2] (var-get my-list)] (var-set my-list (concat my-list2 (listmerge [l1] [l2] (first (var-get my-list) On Mon, Ja

Re: non recursive impl in presence of persistence?

2009-01-11 Thread e
I'm not planning on programming like this, but just to try to finish this up . . . .it's still not working. I get an odd error when I actually try to sort something that iSeq doesn't work on integers. I have no idea where to still the (first my-list) at the end so it returns, too. No need to rep

Re: non recursive impl in presence of persistence?

2009-01-11 Thread e
looks like an awesome book. will check it out more. thanks. On Mon, Jan 12, 2009 at 1:06 AM, Josip Gracin wrote: > > On Sun, Jan 11, 2009 at 10:33 PM, e wrote: > > thanks for your patience. I think I'm starting to get it. > > Interesting discussion on tail recursion. > > Just to add $0.02...

Re: non recursive impl in presence of persistence?

2009-01-11 Thread Timothy Pratley
> is the @ symbol the same as a var-get . . . or is that an atom. @ is a reader macro that translates to (deref ) which works on vars, atoms, refs, agents. and yes is interchangeable with var-get. > Your sentence about atoms was very compound.  I'm not sure if you said that >you > used an atom

Re: non recursive impl in presence of persistence?

2009-01-11 Thread e
I'm sure you are right. I'm going to have to be good at making these arguments with my coworkers (or find somewhere else to work, maybe? :) ) so I appreciate the depth people are going to. One of my next bouts of confusion is going to come from trying to figure out what's already done. Like I r

Re: non recursive impl in presence of persistence?

2009-01-11 Thread Josip Gracin
On Sun, Jan 11, 2009 at 10:33 PM, e wrote: > thanks for your patience. I think I'm starting to get it. > Interesting discussion on tail recursion. Just to add $0.02... The fact that 'recur' in Clojure is actually used to implement iterative and not recursive processes is easier to understand af

Re: non recursive impl in presence of persistence?

2009-01-11 Thread Timothy Pratley
My point was that it is not a missing capability, Say you want to accumulate some changes, in this case sum odd numbers: In C++ someone might write this: int x = 0; for (int i=0; i<100; i++) { if ( i%2==1 ) x+=i; } However in Clojure you have a choice: (reduce + (range 1 100 2)) Or you could

Re: non recursive impl in presence of persistence?

2009-01-11 Thread Adrian Cuthbertson
Bear with the trials and tribulations (of grokking functional/clojure). It takes a few weeks of trying things out, absorbing the documentation and group archives, watching the group posts and then suddenly there are one or two "aha" moments and then the flood gates open! When you've crossed the t

Re: non recursive impl in presence of persistence?

2009-01-11 Thread e
is the @ symbol the same as a var-get . . . or is that and atom. Your sentence about atoms was very compound. I'm not sure if you said that you used an atom but you didn't have to . . . .or you didn't use an atom because it wasnt necessary . . . . or you did use an atom because it was necessary w

Re: non recursive impl in presence of persistence?

2009-01-11 Thread e
here's a good explanation: http://groups.google.com/group/clojure/browse_thread/thread/3c22b35f079e0de6/95fc0b334ab77c1f I wasn't thinking about closures since I've only recently even learned what they are. I actually don't know if it will ever occur to me to use them, but it sounds like they are

Re: non recursive impl in presence of persistence?

2009-01-11 Thread Timothy Pratley
> thread should own the memory that's created. Each thread should have > its own asynchronous stack to push local variables onto that no one > else is allowed to see. Just for the record, Clojure does support local variable that behave exactly as you would expect them: (with-local-vars [x 3] (

Re: non recursive impl in presence of persistence?

2009-01-11 Thread e
thanks for your patience. I think I'm starting to get it. Interesting discussion on tail recursion. Add a lot of depth to what Rich was talking about. Really smart work-around! On Jan 11, 2:50 pm, James Reeves wrote: > On Jan 11, 7:19 pm, e wrote: > > > oh.  I missed the "recur my-list" in y

Re: non recursive impl in presence of persistence?

2009-01-11 Thread James Reeves
On Jan 11, 7:19 pm, e wrote: > oh.  I missed the "recur my-list" in your answer.  So we still don't > have an iterative solution.  Recursion should never be necessary.  I > agree that it simplifies things sometimes and you can use it when you > are stuck. . . . .but no need to push a whole stack

Re: non recursive impl in presence of persistence?

2009-01-11 Thread James Reeves
On Jan 11, 7:09 pm, e wrote: > if it has tighter scope, then I don't understand why you don't have an > infinite loop.  The nested my-list that you redefined should have > nothing to do with the my-list that you are doing the 'rest' check > on. That's what the loop/recur form does. Again, loop/r

Re: non recursive impl in presence of persistence?

2009-01-11 Thread e
oh. I missed the "recur my-list" in your answer. So we still don't have an iterative solution. Recursion should never be necessary. I agree that it simplifies things sometimes and you can use it when you are stuck. . . . .but no need to push a whole stack frame for such a simple problem, I wou

Re: non recursive impl in presence of persistence?

2009-01-11 Thread e
if it has tighter scope, then I don't understand why you don't have an infinite loop. The nested my-list that you redefined should have nothing to do with the my-list that you are doing the 'rest' check on. (rest my-list) should always be non-nil because the inner let is operating on a different

Re: non recursive impl in presence of persistence?

2009-01-11 Thread James Reeves
On Jan 11, 6:19 pm, e wrote: > This gets to my question perfectly.  Why is your code "my-list > (rest (rest my-list)) " legal? Because you're not actually changing anything. In theory, the let form can be derived from anonymous functions. So (let [x y] ...) is the same as ((fn [x] ...) y). Or,

Re: non recursive impl in presence of persistence?

2009-01-11 Thread Eric Lavigne
> > i see that "my-list (rest (rest my-list))" is in a let section. That > seems like the scope would mean we are talking about a different my- > list. > Yes, it is a new my-list with a smaller scope. I didn't search for the expression (rest (rest my-list)) before my earlier response. --~--~---

Re: non recursive impl in presence of persistence?

2009-01-11 Thread Eric Lavigne
> > > This gets to my question perfectly. Why is your code "my-list > (rest (rest my-list)) " legal? > I wouldn't have even thought to try that because, in essence, you are > changing my-list. I mean, I know how persistence works. You are just > reassigning what you think of as the start of my-l

Re: non recursive impl in presence of persistence?

2009-01-11 Thread e
i see that "my-list (rest (rest my-list))" is in a let section. That seems like the scope would mean we are talking about a different my- list. On Jan 11, 1:19 pm, e wrote: > that's awesome, and I hope it helps others, too.  Thanks for starting > with python. > > This gets to my question perfe

Re: non recursive impl in presence of persistence?

2009-01-11 Thread e
that's awesome, and I hope it helps others, too. Thanks for starting with python. This gets to my question perfectly. Why is your code "my-list (rest (rest my-list)) " legal? I wouldn't have even thought to try that because, in essence, you are changing my-list. I mean, I know how persistence

Re: non recursive impl in presence of persistence?

2009-01-11 Thread James Reeves
Thinking functionally is hard when you're used to programming imperatively. So instead of leaping straight into Clojure, lets stick with Python for the time being. So let's take your Python code: def msort(someList): myList = [[x] for x in someList] while len(myList) > 1: l1 = myList.pop

Re: non recursive impl in presence of persistence?

2009-01-11 Thread Eric Lavigne
On Sun, Jan 11, 2009 at 10:50 AM, e wrote: > > refs seem silly in this context! Now I REALLY have to get my head > wrapped around clojure. sooo I only have one thread, but I have > to do a dosync? Why can this whole function just work in a thread > agnostic way? It's a local variable! If

Re: non recursive impl in presence of persistence?

2009-01-11 Thread e
refs seem silly in this context! Now I REALLY have to get my head wrapped around clojure. sooo I only have one thread, but I have to do a dosync? Why can this whole function just work in a thread agnostic way? It's a local variable! If a thread calls it, then a thread should own the memor

Re: non recursive impl in presence of persistence?

2009-01-11 Thread e
I'm trying to follow. Can you explain in pseudo code? That's impressive that it follows the classic approach on persistent data structures . . .. from what I can tell. You successively divide the list in halves of halves of halves. Then the lists of size 1 are merged together as the stack unwi

Re: non recursive impl in presence of persistence?

2009-01-11 Thread e
great. I wondered about that, too! thanks. On Jan 11, 7:27 am, James Reeves wrote: > On Jan 11, 6:32 am, "Nick Vogel" wrote: > > > Ok, first of all, here's how I translated that python code: > > > (defn msort [myList] > >   (if (> (count myList) 1) > >     (let [l1 (first myList) l2 (second m

Re: non recursive impl in presence of persistence?

2009-01-11 Thread e
that looks interesting, except it is missing the part where you take the original list and make it into a list of lists using list comprehension. That works in python and clojure for me ... "the so far so good part". If the recur were to do that repeatedly, the algorithm would get messed up. St

Re: non recursive impl in presence of persistence?

2009-01-11 Thread e
thanks for all the help. just to answer the last question, 'sorted' should have taken on the new def before getting returned. that return happens after the def is complete. Will check out refs. I think that's what I need to understand. On Jan 11, 1:27 am, "Eric Lavigne" wrote: > > I have no

Re: non recursive impl in presence of persistence?

2009-01-11 Thread John
Hi, I'm just learning Clojure too, so I don't have much to add to what everyone else has said, but here's my crack at a full implenentation of merge-sort in Clojure. I'm sure that there is plenty of room for improvement (especially wrt. the merge function) but in case it's helpful, here it is:

Re: non recursive impl in presence of persistence?

2009-01-11 Thread James Reeves
On Jan 11, 6:32 am, "Nick Vogel" wrote: > Ok, first of all, here's how I translated that python code: > > (defn msort [myList] >   (if (> (count myList) 1) >     (let [l1 (first myList) l2 (second myList)] >       (recur (concat (drop 2 myList) (my-merge l1 l2 >     (first myList))) I'd chan

Re: non recursive impl in presence of persistence?

2009-01-10 Thread Nick Vogel
By the way just to clarify, the use of recur is iterative, it's just written in clojure in its recursive form. On Jan 11, 1:32 am, "Nick Vogel" wrote: > Ok, first of all, here's how I translated that python code: > > (defn msort [myList] >   (if (> (count myList) 1) >     (let [l1 (first myList)

Re: non recursive impl in presence of persistence?

2009-01-10 Thread Nick Vogel
Ok, first of all, here's how I translated that python code: (defn msort [myList] (if (> (count myList) 1) (let [l1 (first myList) l2 (second myList)] (recur (concat (drop 2 myList) (my-merge l1 l2 (first myList))) The main thing that might need explaining is the recur, which b

Re: non recursive impl in presence of persistence?

2009-01-10 Thread Eric Lavigne
> > > I have no idea how to iteratively mess with it since everything is > persistent. Ok, like, say it's a list of lists and I am going to be > merging the lists, like Tarjan's mergesort from some book from > college. > Sorting is done much more easily with recursion than with iteration. However

non recursive impl in presence of persistence?

2009-01-10 Thread e
I'm just trying to understand basic stuff. say I have a local list called "myList" (assigned using 'let' . . . should I have used something else?) Who cares what's in it. Maybe I set it up from a list comprehension from some input to my function. I have no idea how to iteratively mess with it s