bobbicodes / bobbi-lisp

Interactive Lisp environment for learning Clojure
https://bobbicodes.github.io/bobbi-lisp/
0 stars 0 forks source link

Implementations of `loop`/`recur` that work across multiple function calls #6

Closed bobbicodes closed 12 months ago

bobbicodes commented 12 months ago

No one ever has to know how long this took me to get right.

At least, I hope it's right...

You won't tell anyone, will you?

Probably a week straight. I have notes to prove it. Was probably the most painful thing so far in this project, for no good reason other than it broke my brain.

Disappointingly, about 20 tests are failing that were passing before. Oh, well. I'll merge this anyway and figure it out later. Hopefully I don't have to think about loops for awhile, that was really not fun

bobbicodes commented 12 months ago

Example use:

(defn loop1 [coll]
  (loop [s coll res1 []]
    (if (empty? s) res1
      (recur (rest s) (conj res1 (first s))))))

(defn loop2 [colls]
  (loop [s colls res2 []]
    (if (empty? s) res2
      (recur (rest s) (conj res2 (loop1 (first s)))))))

(loop2 [[1 2] [3 4]])
=> [[1 2] [3 4]]