This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-06-05
Channels
- # announcements (1)
- # babashka (6)
- # beginners (37)
- # clojure (4)
- # clojure-europe (6)
- # clojure-india (3)
- # clojure-spec (6)
- # clojured (1)
- # clojurescript (14)
- # datalog (5)
- # gratitude (1)
- # helix (3)
- # hyperfiddle (1)
- # interop (6)
- # leiningen (2)
- # off-topic (142)
- # other-lisps (2)
- # pathom (20)
- # releases (1)
- # rewrite-clj (4)
- # shadow-cljs (5)
- # tools-deps (3)
I am trying to achieve the solution at this page: https://stackoverflow.com/questions/66211769/filter-matching-strings-between-two-text-files-in-clojure
But when I run the code, I get an error: Exception in thread "main" java.lang.RuntimeException: Unable to resolve symbol: deleted-files in this context, compiling:(dirdiff/core_test.clj:8:27)
I couldnt get that solution working and I dont understand what I am doing wrong sadly 😞
My code is here:
(ns dirdiff.core
(:gen-class))
(ns com.lispcast.my-ns
(:require [clojure.set :as set]))
(defn no-prefix [prefix]
(comp (filter #(clojure.string/starts-with? % prefix))
(map #(subs % (count prefix)))))
(defn load-string-set [a file]
(->> file
slurp
clojure.string/split-lines
(into #{} a)))
(defn deleted-files
;"Die Funktion gibt einen String zurück, der beschreibt, welche Dateien gelöscht wurden.
;Um dies zu ermitteln, nimmt sie zwei mit dem Befehl find erstellten Dateien entgegen.
;prefix-davor bezeichnet das Prefix, welches von den Zeilen in der davor-Datei vor dem Vergleich entfernt werden soll.
;prefix-danach bezeichnet das Prefix, welches von den Zeilen in der danach-Datei vor dem Vergleich entfernt werden soll.
;davor bezeichnet die Datei als String, die den ersten Dateisystemzustand beschreibt.
;danach bezeichnet die Datei als String, die den zweiten Dateisystemzustand beschreibt."
[prefix-davor prefix-danach davor danach]
; TODO
(clojure.set/difference (load-string-set (no-prefix prefix-davor) davor)
(load-string-set (no-prefix prefix-danach) danach)))
(deleted-files "davor" "danach" "resources/davor.txt" "resources/danach.txt")
How to do that, and what's namespace should I add?
Is the problem occured due to this:
(ns com.lispcast.my-ns
(:require [clojure.set :as set]))
I am using an online development environment
I have a really basic/general question about how to structure Clojure programs. I’ve started out doing almost everything in my global project namespace like this:
;;; "Main"
...
(def window-x-min spad)
(def window-x-max (- swidth spad))
(def window-y-min spad)
(def window-y-max (- sheight spad))
;; Number of grid pixels to interpolate/render across each dimension
(def px-count 100)
;; Resulting size of each grid pixel
(def px-size (double (/ (- window-x-max window-x-min) px-count)))
(def data (load-csv "/Users/easy/Downloads/20220519082008-04213-data.csv"))
(def imported-meters-data (->> data
clean-csv-data
drop-header-row
csv-strings->numbers
project-WGS84->meters))
(def data-proportion (/ (- (get-max ALL-X) (get-min ALL-X))
(- (get-max ALL-Y) (get-min ALL-Y))))
(def scaled-data (scale-map-data data-proportion imported-meters-data))
(def grid-resolution 5)
(def scaled-grid (point-grid window-x-min window-y-min
window-x-max window-y-max
grid-resolution))
But I know this is wrong, because I’m not inside -main
(everything just runs when I load the file in Calva) and every function that uses the globals I’m defining is dependent on the order of my functions.So my question is: How do I define constants as I go (in -main) without ending up writing all my code in a (let [])
?
I do have a few complex functions that build from many intermediate values and it looks like the bulk of the code ends up in a long let
Maybe my functions are too big? They’re almost all less than 20 lines, though I see the style guide says they should be less than 10.
Stick them in a map, call it "default-options", top level function merges it with user provided options
This approach was helpful. Thanks, @UK0810AQ2. Clojure/FP is so mind-bendingly new to me that I’m sometimes at a loss for guessing an idiomatic approach to even basic stuff. 🙂
Glad I could help. I recommend 4clojure and the Clojure Koans to get used to the language and idioms. Both immutability and working with data first can be new to programmers coming to Clojure. Keep at it and you'll be fluent in no time
Hello 🙂 I’m creating a simple input component in reagent. I want to check if a validator function exist and also validate if it exist.
;; The validator output a string if there is a error or nil
(if
(and (some? validator) (some? (validator @value)))
(str "error"))
This code work but I wonder if there is a core function that both check if a function exist and then also run the function and return true if a string exist and false if the output is nil.Could you provide a default validator as (constantly true) or (constantly false)? Then you wouldn't have to check whether the validator is nil.
How to turn the contents (which are strings) of a set to simple strings?
#{"/Fotos/Mallorca-2017/dc-10.jpg" "/Fotos/Azoren-2018/buffet" "/Fotos/Azoren-2018/restaurant/dc-43.jpg" "/Fotos/Azoren-2018/restaurant/dc-42.jpg" "/Fotos/Mallorca-2017/dc-19.jpg" "/Fotos/Azoren-2018/restaurant/dc-41.jpg" "/Fotos/Mallorca-2017/dc-11.jpg" "/Fotos/Azoren-2018/restaurant/dc"} expected: (= expected actual) actual: (not (= "/Fotos/Azoren-2018/buffet\n/Fotos/Azoren-2018/restaurant/dc\n/Fotos/Azoren-2018/restaurant/dc-41.jpg\n/Fotos/Azoren-2018/restaurant/dc-42.jpg\n/Fotos/Azoren-2018/restaurant/dc-43.jpg\n/Fotos/Mallorca-2017/dc-10.jpg\n/Fotos/Mallorca-2017/dc-11.jpg\n/Fotos/Mallorca-2017/dc-19.jpg" #{"/Fotos/Mallorca-2017/dc-10.jpg" "/Fotos/Azoren-2018/buffet" "/Fotos/Azoren-2018/restaurant/dc-43.jpg" "/Fotos/Azoren-2018/restaurant/dc-42.jpg" "/Fotos/Mallorca-2017/dc-19.jpg" "/Fotos/Azoren-2018/restaurant/dc-41.jpg" "/Fotos/Mallorca-2017/dc-11.jpg" "/Fotos/Azoren-2018/restaurant/dc"}))
I think the test is requesting from me, not a set but string versions with ", am I wrong?
Can anyone help me what is happening in this code:
(ns dirdiff.core
(:gen-class))
(require '[clojure.set])
(defn no-prefix [prefix]
(comp (filter #(clojure.string/starts-with? % prefix))
(map #(subs % (count prefix)))))
(defn load-string-set [a file]
(->> file
slurp
clojure.string/split-lines
(into #{} a)))
(defn deleted-files
"Die Funktion gibt einen String zurück, der beschreibt, welche Dateien gelöscht wurden.
Um dies zu ermitteln, nimmt sie zwei mit dem Befehl find erstellten Dateien entgegen.
prefix-davor bezeichnet das Prefix, welches von den Zeilen in der davor-Datei vor dem Vergleich entfernt werden soll.
prefix-danach bezeichnet das Prefix, welches von den Zeilen in der danach-Datei vor dem Vergleich entfernt werden soll.
davor bezeichnet die Datei als String, die den ersten Dateisystemzustand beschreibt.
danach bezeichnet die Datei als String, die den zweiten Dateisystemzustand beschreibt."
[prefix-davor prefix-danach davor danach]
; TODO
(disj (clojure.set/difference (load-string-set (no-prefix prefix-davor) davor)
(load-string-set (no-prefix prefix-danach) danach))
"/Fotos/Azoren-2018/buffet/dc-40.jpg"
"/Fotos/Azoren-2018/buffet/dc-41.jpg"
"/Fotos/Azoren-2018/buffet/dc-42.jpg"
"/Fotos/Azoren-2018/buffet/dc-43.jpg"
))
(deleted-files "davor" "danach" "resources/davor.txt" "resources/danach.txt")
The bash line command window:
cloud9.bewerber2:~/environment/dirdiff $ lein test
(#{/Fotos/Mallorca-2017/dc-10.jpg /Fotos/Azoren-2018/buffet /Fotos/Azoren-2018/restaurant/dc-43.jpg /Fotos/Azoren-2018/restaurant/dc-42.jpg /Fotos/Mallorca-2017/dc-19.jpg /Fotos/Azoren-2018/restaurant/dc-41.jpg /Fotos/Mallorca-2017/dc-11.jpg /Fotos/Azoren-2018/restaurant/dc})
lein test dirdiff.core-test
(#{/Fotos/Mallorca-2017/dc-10.jpg /Fotos/Azoren-2018/buffet /Fotos/Azoren-2018/restaurant/dc-43.jpg /Fotos/Azoren-2018/restaurant/dc-42.jpg /Fotos/Mallorca-2017/dc-19.jpg /Fotos/Azoren-2018/restaurant/dc-41.jpg /Fotos/Mallorca-2017/dc-11.jpg /Fotos/Azoren-2018/restaurant/dc})
lein test :only dirdiff.core-test/show-deleted-test
FAIL in (show-deleted-test) (core_test.clj:9)
Find deleted files
erwartet:
/Fotos/Azoren-2018/buffet
/Fotos/Azoren-2018/restaurant/dc
/Fotos/Azoren-2018/restaurant/dc-41.jpg
/Fotos/Azoren-2018/restaurant/dc-42.jpg
/Fotos/Azoren-2018/restaurant/dc-43.jpg
/Fotos/Mallorca-2017/dc-10.jpg
/Fotos/Mallorca-2017/dc-11.jpg
/Fotos/Mallorca-2017/dc-19.jpg
actual:
expected: (= expected actual)
actual: (not (= "/Fotos/Azoren-2018/buffet\n/Fotos/Azoren-2018/restaurant/dc\n/Fotos/Azoren-2018/restaurant/dc-41.jpg\n/Fotos/Azoren-2018/restaurant/dc-42.jpg\n/Fotos/Azoren-2018/restaurant/dc-43.jpg\n/Fotos/Mallorca-2017/dc-10.jpg\n/Fotos/Mallorca-2017/dc-11.jpg\n/Fotos/Mallorca-2017/dc-19.jpg" nil))
Ran 1 tests containing 1 assertions.
1 failures, 0 errors.
Tests failed.
It says failed, regarding the code above, but I dont understand how it fails?
But where does it fail?
It fails because I couldnt list it as strings like below, but returned them in a set?
/Fotos/Azoren-2018/buffet
/Fotos/Azoren-2018/restaurant/dc
/Fotos/Azoren-2018/restaurant/dc-41.jpg
/Fotos/Azoren-2018/restaurant/dc-42.jpg
/Fotos/Azoren-2018/restaurant/dc-43.jpg
/Fotos/Mallorca-2017/dc-10.jpg
/Fotos/Mallorca-2017/dc-11.jpg
/Fotos/Mallorca-2017/dc-19.jpg
You're not showing us the code of the test so it's hard to say, but you are getting a nil
somewhere where you're expecting a string
(ns dirdiff.core-test
(:require [clojure.test :refer :all]
[dirdiff.core :refer :all]))
(deftest show-deleted-test
(testing "Find deleted files"
(let [expected (slurp "resources/erwartet.txt")
actual (deleted-files "davor" "danach" "resources/davor.txt" "resources/danach.txt")]
(is
(= expected
actual)
(str "erwartet:\n" expected "\n\nactual:\n" actual)))))
here is the test
I am still stuck...