beginners

practicalli-johnny 2026-06-01T04:38:51.046679Z

Rebel readline will highlight namespace and function names (also has completion, built-in docs, etc) I find rebel readline especially useful to run webapps and other longer running processes (or just want to quick experiment) There is a demo on this page https://practical.li/clojure/clojure-cli/repl/

👍 1
Krishnansh Agarwal 2026-06-01T05:41:16.004059Z

rebel-readline is a crazy good project!

Mtende Kuyokwa 2026-06-01T16:13:30.894909Z

I just implemented fibbonanci in the weirdest way lol

(defn add-prev-next [array]
 (def value-end (reduce + (
                           if (=(count array) 1)
                            (take-last 1 array)
                           (take-last 2 array))))
 (concat array (list value-end) )
)
(
 defn generate-numbers [collection numbers-to-generate]
 (loop [x numbers-to-generate collection collection]
  (if (= x 0)
collection
  (recur (- x 1) (add-prev-next collection)))
   )
 )


(defn fibonnaci-sequence [x]
 (if (= x 0)
  '()
  (generate-numbers '(1) x)
   )
  )


(fibonnaci-sequence 8)

Harold 2026-06-01T17:38:27.441699Z

def inside of defn is not really idiomatic, I like your idea though! 🙂 --- Boils down to something like:

(-> (iterate #(conj % (apply + (take-last 2 %))) [1 1])
    (nth 8))

2026-06-01T18:50:50.285139Z

to be specific: even inside a function, def creates a namespace level value, which means if you used threads the function could misbehave badly

Mtende Kuyokwa 2026-06-02T03:25:00.323049Z

@hhausman wtf. just one line is crazy lol

1
Mtende Kuyokwa 2026-06-02T03:25:04.107839Z

@noisesmith I do not get what you mean. whats the story

2026-06-02T03:27:02.817119Z

def creates a value at namespace scope. if the function runs in two threads, the value of value-end can be over-written

2026-06-02T03:30:05.351349Z

(ins)user=> (defn racer [x] (def y x) (if-not (= x y) (println :race)))
#'user/racer
(ins)user=> (dotimes [i 1000] (racer i))
nil
(ins)user=> (dotimes [i 1000] (future (racer i)))
:race
:race
:race
:race
:race
nil

Harold 2026-06-02T03:50:35.543489Z

Since you seem like a fun-loving person, here's another fun one to think about. What should the value of this infinite form be?

(+ 1 (/ 1 (+ 1 (/ 1 (+ (/ 1 (+ 1 (/ 1 (+ 1 (/ 1 (+ 1 (/ 1 (+ 1 (/ 1 (+ 1 ...)))))))))))))))
--- Also, heh:
user> (deftype Fiberator [^:unsynchronized-mutable ^clojure.lang.BigInt a
                          ^:unsynchronized-mutable ^clojure.lang.BigInt b]
        java.util.Iterator
        (hasNext [_] true)
        (next [this]
          (let [res a]
            (set! a b)
            (set! b (+ res b))
            res)))
user.Fiberator
user> (take 11 (iterator-seq (Fiberator. 0N 1N)))
(0N 1N 1N 2N 3N 5N 8N 13N 21N 34N 55N)
user> (nth (iterator-seq (Fiberator. 0N 1N)) 100000)
259740693472217241661550340212759154148804853865176965847247707039525345435112736862655567728367167447546375872230744321116383994738750910309656973821883044930522876385313349213530267927895670105127657827163560807305053220024323311438398651613782723812477745377833729991621463405005466986039086275099663936640921189012527196017210506030035058689402855810367511765825136837743...
user> (count (str (nth (iterator-seq (Fiberator. 0N 1N)) 100000)))
20899

❤️ 1
hrtmt brng 2026-06-02T06:11:41.915039Z

Looks good. :-) Keep practicing! Only 3 comments: Def is a no go. The parens are misplaced. Please try to always ask yourself if you are on the right path. Here it might be obvious for you that this is not the right way. But often you don't realise this. This is why these exercises are so important,

Ben Sless 2026-06-04T09:10:41.352779Z

> (+ 1 (/ 1 (+ 1 (/ 1 (+ (/ 1 (+ 1 (/ 1 (+ 1 (/ 1 (+ 1 (/ 1 (+ 1 (/ 1 (+ 1 ...))))))))))))))) Golden post

1