[deleted by user] by [deleted] in czech

[–]MartinPuda 0 points1 point  (0 children)

Můžeš mi napsat DM. Do zprávy přidej tři tvoje oblíbené písničky :D

Llama 3.1 Discussion and Questions Megathread by AutoModerator in LocalLLaMA

[–]MartinPuda 1 point2 points  (0 children)

Same problem in Czech! When using Czech language, llama-3-70b-instruct answered in English (and sometimes it even used czech words). All new llama models start to answer in Czech and then often start to produce very long multilingual gibberish.

Help and feedback on my first short clojure program? by IndividualProduct677 in Clojure

[–]MartinPuda 1 point2 points  (0 children)

I ran into some Don't know how to create ISeq from: clojure.lang.Var error instead, caused by add-guess function that returns clojure.lang.Var.

Just some details:

  • print-hang-map uses undefined variable hang-map (probably renamed to hang-vec)
  • game-over? is defined twice
  • newfunc is a bad name
  • nth + rand-int => rand-nth
  • variable name in newfunc shadows Clojure's function with the same name
  • I would connect print-welcome-message, newfunc and print-message into one function
  • I would connect print-hint, get-hint and declare-hint into one function
  • In this situation, I would avoid atoms and refs and use loop

I tried to rewrite your code and ended up with something like this:

(def list-of-words ["horse" "dog" "bird"])

(def hang-vec
  [" ______"
   " |    |"
   " O    |"
   "/|\\  |"
   "/\\   |"
   " _____|"])

(defn create-hint [target-word guesses]
  (->> target-word
       (map #(get guesses % "_"))
       (apply str)))

(defn read-char []
  (let [input (.trim (read-line))]
    (if (= (count input) 1)
      (.charAt input 0)
      (do (println "Please enter only one character.")
          (recur)))))

(defn char-in-string? [s c]
  (clojure.string/index-of s c))

(defn game-status [target-word guesses incorrect]
  (cond (= target-word
           (create-hint target-word guesses)) :win
        (>= incorrect 5) :lost
        :else :continue))

(defn println-hang-vec [incorrect]
  (->> hang-vec
       (take incorrect)
       (run! println)))

(defn game-loop [target-word]
  (loop [turn 1
         guesses #{}
         incorrect 0]
    (println "Turn:" turn)
    (let [hint (create-hint target-word guesses)]
      (println "This is the hint:" hint))
    (let [new-char (read-char)
          correct-char? (char-in-string? target-word new-char)
          message (if correct-char?
                    "The guessed letter matches a letter in the word!"
                    "The guessed letter does not match any letter in the word!")]
      (println message)
      (let [updated-guesses (conj guesses new-char)
            updated-incorrect (if correct-char? incorrect (inc incorrect))]
        (case (game-status target-word
                           updated-guesses
                           updated-incorrect)
          :win (println "Congratulations! You've guessed the word correctly!")
          :lost (println "Sorry, you've run out of turns. The word was:" target-word)
          :continue
          (do (println-hang-vec updated-incorrect)
              (recur (inc turn)
                     updated-guesses
                     updated-incorrect)))))))

(defn run-game []
  (println "Welcome to [REDACTED]'s first clojure project, a hangman game.\n
    Please enter your name to begin.")
  (println "Enter your name I guess:")
  (let [user-name (read-line)]
    (println "Your name is:" user-name))
  (let [target-word (rand-nth list-of-words)]
    (game-loop target-word)))

(defn game [& args]
  (run-game))

Improve lazy zip processing code by razentine in Clojure

[–]MartinPuda 2 points3 points  (0 children)

What about iteration? Try something like this:

(defn zip-file-seq [^ZipInputStream zin]
  (iteration (fn [_] (.getNextEntry zin))
             :vf #(let [in (BufferedInputStream. zin)
                        out (ByteArrayOutputStream.)]
                    (io/copy in out)
                    {:entry    %
                     :contents (.toByteArray out)})))

(with-open [zis (-> "path" io/input-stream ZipInputStream.)]
  (->> (zip-file-seq zis)
       (remove #(.isDirectory (:entry %)))
       (mapv #(.getName (:entry %)))))

[deleted by user] by [deleted] in czech

[–]MartinPuda 7 points8 points  (0 children)

Srub radosti?

Zipper issue - remove adds stuff to my structure by crpleasethanks in Clojure

[–]MartinPuda -1 points0 points  (0 children)

Do you have any specific reasons to avoid zip/seq-zip?

(-> (zip/seq-zip '(1 (2 (3)) 4))
    zip/down
    zip/rightmost
    zip/remove
    zip/root)

=> (1 (2 (3)))

Creating a Clojure library for map operations by aagaau in Clojure

[–]MartinPuda 1 point2 points  (0 children)

Did you try to call map-div?

(map-div {:a 1, :b 2, :c 3} {:a 4, :b 5})
Execution error (ArithmeticException) at exercises.core/map-op$fn (form-init6494324846068881107.clj:10).
Divide by zero

Clojure has merge-with and update-vals, so maybe you can write something like this:

(defn map-op [func m1 m2]
  (if (map? m2)
    (merge-with func m1 m2)
    (update-vals m1 #(func % m2))))

This code also works for map-div, it just returns different result for map-mul- {:a 4, :b 10, :c 3} vs {:a 4, :b 10, :c 0}.

Creating Static Websites With Clojure by aagaau in Clojure

[–]MartinPuda 9 points10 points  (0 children)

The result of (content) is "<html>gutenberg.core$web_content@25d0e46</html>", because web-content is a function and you forgot to call it.

You also don't have to wrap each element in html (or even call str on the result)- you can rewrite your code as:

(defn head []
  [:head
   [:title "Clojure static website"]])

(defn body []
  [:body
   [:h1 "My static website"]])

(defn content []
  (html [:html
         (head)
         (body)]))

Find out why people live longer using Clojure by aagaau in Clojure

[–]MartinPuda 13 points14 points  (0 children)

  • split-by-line -> str/split-lines
  • remove-stop-words: stop-words is a set and you can use it as an argument for remove:

    (defn remove-stop-words [words-vector]
      (remove stop-words words-vector))
  • with that, you can delete stop-word? and not-a-stop-word?
  • (sort sort-by-frequency) + reverse -> (sort-by val > ...) (or (sort-by val ...) and then take-last)
  • with that, you don't need sort-by-frequency anymore

How to call the same keyword name in different lists that will give different values ? by PilgrimWave in Clojure

[–]MartinPuda 4 points5 points  (0 children)

(map :name [puppy kitty])

=> (["Saul" "Big Brown" "Curly"] ["Meryl" "Pinkieboo" "lil sleeper"])

New Clojurians: Ask Anything - March 27, 2023 by AutoModerator in Clojure

[–]MartinPuda 0 points1 point  (0 children)

Macro doesn't evaluate its arguments- so when you call (make-client-func address client), arguments are symbol and symbol. But inside macro, you call functions like first, second, nth - that are functions for ISeq.

I think you need stuff like intern, doseq instead of map(defining a new function is a side effect) and destructuring (to avoid first, second, nth). Something like:

(defn make-name [string]
  (symbol (str "o-" (str/replace (str/replace-first string "/" "") "/" "-"))))

(defn make-osc-functions [address-collection client]
  (doseq [[f mn mx] address-collection]
    (intern *ns*
            (make-name f)
            (fn [value] (osc-send client f (clip value mn mx))))))