This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-29
Channels
- # announcements (8)
- # aws (34)
- # beginners (92)
- # calva (19)
- # capetown (1)
- # cider (10)
- # cljs-dev (7)
- # cljsrn (11)
- # clojars (7)
- # clojure (130)
- # clojure-europe (4)
- # clojure-italy (4)
- # clojure-losangeles (1)
- # clojure-nl (11)
- # clojure-russia (1)
- # clojure-spec (4)
- # clojure-uk (64)
- # clojurescript (51)
- # cursive (9)
- # data-science (6)
- # datomic (29)
- # emacs (3)
- # figwheel-main (14)
- # fulcro (4)
- # graphql (3)
- # jackdaw (2)
- # jobs (4)
- # kaocha (17)
- # leiningen (3)
- # luminus (1)
- # off-topic (46)
- # pedestal (6)
- # portkey (2)
- # re-frame (6)
- # reagent (1)
- # reitit (9)
- # shadow-cljs (9)
- # sql (10)
- # yada (6)
This is kind of a noob js/cljs question. I'm adding an event listener to js/document but whenever figwheel hot reloads the page it gets added again. I tried to prevent it by doing this but it keeps on doing the same. (I saw something like this on a Reagent example with js/setInterval so I expected it to work the same).
The only solution I've found is to prevent figwheel from reloading that file completely.
Hey, I'm new to clojure and clojure.test . So I've written a simple test case for the project while running C-c C-t p or C-c C-c n it is showing "Not a NREPL dict"
Can you past the versions of cider and nrepl?
https://github.com/clojure-emacs/cider/issues/1546 suggests it’t caused by “humane-test-output” but the issue is ancient (2016)
Is there a way to auto load my clj file on save into the cider repl on emacs? It's pretty annoying having to C-c C-l
or C-c C-k
every time I make a change to the file.
@nicholas.jaunsen personally I’d like to have control over that, but if you’re into this, you can use the reloaded workflow and hook it up to an emacs hook
@nicholas.jaunsen this way of working traces back to this: http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded
Can some one point me to what I'm doing wrong here:
(defn create-list [num]
(let [awnser []]
(if (empty? num)
awnser
(recur (int (/ num 10))
(conj awnser (mod num 10)))))
it looks like you're recurring with two arguments, but create-list only access one argument num
you can also use multiarity to "kick start" the recursion if no answers are yet known:
(defn create-list
([n]
(create-list n []))
([n answers]
(if (< n 10)
(create-list (inc n) (conj answers n))
answers)))
note that recur
doesn't play nice with multiarity. it will try to recur on the same function and you'll get the same argument mismatch error
(loop [num num answer []
just binds your num
function parameter to a num
local var inside the loop
it would help to know what you're trying to do, there's a couple other problems in the function you posted
I'm trying to turn a number into a list of seperate digets. But empty? on a number cant work 🙂
got it working
(defn create-list [num]
(loop [num num awnser []]
(if (= num 0)
awnser
(recur (int (/ num 10))
(conj awnser (mod num 10))))))
yes, that might work. the problem I saw was with the (if (empty? num)
as I that would seemingly always return false on a number
also if you're trying to split a number into a list of digits, that can probably be done more readily by just converting the number to string
first
that will take num
as a number and return a list of it's digits, as numbers, by way of string
yes, I was thinking about using a string first, but I wanted to try and use a solution with modulus.
and that'll ... sort of work on negative numbers (first digit becomes -1 if number is negative)
1. @shidima yes, just highlighting that setting up an explicit loop/recur
isn't necessary to solve the problem
the above example with quot
and mod
is the most efficient by far though since you avoid conversions. it can be extended to tackle negative numbers fairly easily
Well, with some help I did the armstrong-numbers problem from http://exercism.io 🙂 Thanks all!
any pointers on why (mapv #(mapv % (keys (@db :input))) (@db :input))
fails with error: IllegalArgumentException Key must be integer clojure.lang.APersistentVector.invoke (APersistentVector.java:294)
:start-time
and :end-time
contain java.time.Instant
and :duration
is an integer
Is columns
meant to be a nested sequence like that?
I'm not sure, I'm just trying to save a csv with headers, using the keys in the map as the header names. then later I have another function which just appends to this csv without creating the headers
Hello I tried to use coast. I had few issues with it.
[email protected]:~/projects/rubbish$ coast new myapp && cd myapp
/home/foobar/bin/coast: 7: /home/foobar/bin/coast: [[: not found
/home/foobar/bin/coast: 17: /home/foobar/bin/coast: [[: not found
/home/foobar/bin/coast: 7: /home/foobar/bin/coast: [[: not found
/home/foobar/bin/coast: 27: /home/foobar/bin/coast: [[: not found
Downloading a fresh copy of coast...
Created a new coast project in directory myapp
I had to replace #!/usr/bin/env sh
with #!/usr/bin/env bash
and it worked without error.
But then I ran into next issues and I don't know how to fix
[email protected]:~/projects/rubbish/todos$ make db/create
clj -A\:db/create
Exception in thread "main" java.io.FileNotFoundException: -A:db/create (No such file or directory)
Does anybody know what's the reason of problem?
Makefile:
.PHONY: test
test:
COAST_ENV=test clj -A\:test
clean:
rm -rf target
uberjar:
clj -A\:uberjar
repl:
clj -R:repl bin/repl.clj
db/migrate:
clj -A\:db/migrate
db/rollback:
clj -A\:db/rollback
db/create:
clj -A\:db/create
db/drop:
clj -A\:db/drop
jobs:
clj -m
assets:
clj -m coast.assets
routes:
clj -m coast.router
I'm afraid that coast is not mature enough... I'm Thinking about returning to Compojure
One more question, is there Clojujre alternative to activeadmin? https://activeadmin.info/
@seancorfield I think I understand now, the issue is here (let [columns [(keys data)]
, so I have a list inside a vector. How do I get rid of that?
if you want columns
to be a vec instead of a list, you could use (vec (keys data))
most collection functions in clojure return something list-like so if you were to run (keys {:a 1 :b 2 :c 3})
in a repl you would get (:a :b :c)
which is a list consisting of :a
:b
:c
right. I guess the question here is: is it a good idea to do this inside a function? My idea is to make it general, so that if I pass a different var
with different keys, the let
bindings will also be different, or do I always have to hardcode the bindings?
sorry let me check your original problem before talking out of my neck ^^
Lets go one step back, how would your data look in a clj datastructure?
I’d assume something like this right:
[{:first-name "Lennart" :last-name "Buit"}
{:first-name "Santiago" :last-name nil}]
And then you would like to have a CSV with columns first-name
and last-name
and a row consisting of Lennart/Buit and Santiago/nil. Is my assumption correct?my goal is to have a function with an if
test that either writes a new csv with headers if the file doesn't exists, or spit
the thing is I'm still prototyping the structure of the "database", so I wanted to avoid hardcoding the names of the keys in the let
statement, if that's possible
ofcourse that is possible
What you could do right, is always store the contents of your CSV in such a vector as I showed right, and then, when writing it back, determine the header, write that followed by the data
The “determining the header” bit is a bit tricky tho, because you would need to determine all possible keys that could exist in “CSV entries”
`(defn save-to-file [filename data] (if (.exists (io/as-file filename)) (spit filename (s/join "," [(data :start-time) (data :end-time) (data :duration)]) :append true) (write-csv filename data)))`
right, but that becomes tricky when you would add extra keys to your data, then your header wouldn’t match
but write-csv doesn't work because (keys data) evaluates to a list, and let [columns ['(:key)]
doesn't work
So, why not read the original CSV file, add your new data, determine the new header, and write the concatenated result
but that solves a downstream problem I get the feeling, no the fact that the let
bindings have to be "dynamic"
well, in my approach they don’t. Because you would construct the “header” from the keys of the entries
let me write it out for you ^^
(def data
;; Assume this comes from some sort of file
[{:last-name "Santiago"}
{:first-name "Lennart" :last-name "Buit"}])
(defn determine-header
[data]
(let [keys-by-row (map keys data)] ;; These are all keys present in the data, will be ((:first-name) (:first-name :last-name)) for the example
(apply set/union (map set keys-by-row))) ;; "Merge" these using set union
(defn write-rows
[data]
(let [header (determine-header data)]
... here you should write some code to write the rows ...))
This would net you with header
being defined as a set consisting of :first-name
and :last-name
. The rest you should really try yourself!
I’d suggest grouping the data by the header, and generating rows
Good luck and glad I could help!
(defn write-csv
[path row-data]
(let [headers (determine-header row-data)
rows (mapv #(mapv % headers) row-data)]
(with-open [file (io/writer path)]
(csv/write-csv file (cons headers rows)))))
🙌😄 works thanks againHas anyone set up in emacs a way for the kill command to skip putting a killed selection on the kill ring if the selection is just an empty string/blank lines?