Fork me on GitHub
#beginners
<
2019-02-06
>
mikepjb08:02:24

How can I conj into the last element of a vector? e.g (conj-in-last [1 2 [3] 4]) => [1 2 [3 4]]

Chris08:02:42

It’s probably easiest to pop it off, conj it with your value and then conj it back on.

Chris08:02:00

Something like (let [new-val (conj (peek my-vec) my-val))] (conj (pop my-vec) new-val) (Not tested, on phone)

mikepjb08:02:02

just tested in the reply, works a beauty, thanks again @UA8TV3QHF

Chris08:02:34

No worries 🙂

henrik09:02:12

If it's constant size, you can destructure it.

(let [[a b [c] d] [1 2 [3] 4]]
  [a b [c d]])

mikepjb10:02:35

The size grows but the last element is always the one being updated

florentpastor08:02:57

Hi! Is a way to work with the latest version of Google Closure Library in ClojureScript ? The version that is shipped with cljs is two years old 😕

andy.fingerhut18:02:42

You may want to ask in #clojurescript channel to see if someone knows there.

rascio11:02:05

Hi all! When I launch a clojure script is there some way (other than (System/exit n) to close the process with a non-zero exit code?

victorb11:02:11

@manuelrascioni what's the issue with System/exit?

rascio11:02:08

I'm launching a script using the maven-exec-plugin, if I do System/exit it shutdown the entire maven build 🙂

rascio11:02:21

I would like to just stop it

victorb11:02:35

ah, I have no idea about maven-exec-plugin but probably there is a hook/function you can call to exit from whatever wrapper you're inside

lispyclouds13:02:39

@manuelrascioni one work around could be throwing an exception which would cause it to stop as its uncaught.

lispyclouds13:02:23

Also as far as i know, the exec:exec forks the java process so System/exit should be okay. What you could be using is the exec:java goal which runs in the same JVM hence kills the entire thing. Correct me if im wrong though

rascio13:02:19

Hi @U7ERLH6JX, you're totally right. Looking around the internet I found that using the exec:exec goal is the only way to fork process so that I can use System/exit but giving the easiness of using the exec:java I opted for throwing the exception (and having it's rubbish in console)

😄 5
skykanin12:02:48

Are there any good linters for clojure in emacs? I normally use flycheck for linting in emacs, but I see that Clojure isn't on the list over supported languages https://www.flycheck.org/en/latest/languages.html

florentpastor12:02:45

Thanks for that 🙂

👍 5
skykanin13:02:17

Neat, I got eastwood and kibit working from cli, but I can't seem to get squiggly-clojure working by following their readme instructions. I don't get any linting in emacs when I open cider and load the file.

Chase16:02:42

I had better luck going with joker for clojure linting in emacs. https://github.com/candid82/joker Get it installed and on your path (e.g. /usr/local/bin/joker) and then you can use flycheck-joker: https://github.com/candid82/flycheck-joker

lepistane13:02:34

not really a clojure question but more a design one. i made a web app in Clojure that might be used in different languages and i was thinking of doing localization. My idea was to have edn (config) file that would be slurped during startup and then used inside components say like this config

{:usd {:placeholder "hello"
      :title "Hi"}
 :ita {:placeholder "bongiorno"
       :title "ciao"}
 }
and then used like [:input {:placeholder (:placeholder @localization)}] or something like that how do you approach your way of localizing apps?

unni13:02:14

That would be the general idea but you can look at i18n libraries for this eg. https://github.com/ptaoussanis/tower

lepistane14:02:03

thank you very much for suggestions! i didnt know about these

skykanin16:02:34

If I want to add a license notice at the top of my file do I just use a bunch of ;;s or do I use the comment function?

Alex Miller (Clojure team)16:02:00

comment is code and the license string must be read and compiled into bytecode, which takes compile time, load time, and memory

bronsa16:02:17

I don't think it ever reaches bytecode :)

Alex Miller (Clojure team)16:02:59

oh, it’s a macro, I guess that would make sense

andy.fingerhut18:02:15

Still I would also recommend ; since then whatever is in such comments can be arbitrary sequences of characters, without any risk of upsetting the Clojure reader, it need not have balanced parens, brackets, etc.

jorda0mega19:02:26

I'm getting started coding on clojurescript and, coming from the js world, I'm used to setting breakpoints and stepping through the code in order to debug. I've tried a similar approach with cljs sourcemaps and the experience seems to be hit and miss (not all breakpoints are hit and the stepping through the code usually takes me to core js files that are minified and obfuscated). Is there a better alternative? I've tried using the repl but still unfamiliar how I could inspect some of the objects (say an atom inside a let clause) even though I can access globally declared atoms for that namespace. Any tips would help, really enjoying the language so far but the tooling makes me want to go back to js world at times.

lilactown19:02:06

if you’re OK trying out some alpha software, I’ve been working on a tool for inspecting data in a better way than just println or console.log: https://github.com/Lokeh/punk

jorda0mega19:02:24

let me check this out. thanks for the quick reply!

vschepik06:02:16

@jorda0mega punk looks nice. I haven't discovered it yet. What I use all the time is the debux library: https://github.com/philoskim/debux With debux I don't miss step-by-step-debugging. debux works like a trace tool but can be inserted inside of expressions and has the powerful dbgn macro that traces every part of a (complex) expression in a very readable way.

lilactown19:02:20

@jorda0mega using the REPL + printing I think is what the majority of CLJ(S) developers do. CLJS debugging is not super well supported, you’re right

lilactown19:02:55

however, writing your functions that work well at a REPL helps enforce good practice structuring your code

👍 5
seancorfield20:02:29

@lilactown Does ClojureScript support tab> in the latest version? I've found that's very helpful for debugging in Clojure.

lilactown20:02:48

it does support tap> yes 🙂

lilactown20:02:37

that's what my experimental REBL-like tool uses: https://github.com/Lokeh/punk

seancorfield20:02:36

Hah! I should have followed your link. That's very nice!

5
lilactown20:02:39

give it a whirl and let me know what you think! 😄

seancorfield21:02:37

I don't do any cljs stuff at all. Good to know punk is out there in case I ever start using cljs again 🙂 I use REBL all the time with clj!

Lennart Buit21:02:48

What is you guys preferred way to find performance problems. I can use criterion to time code that is slow, but it doesn’t tell me why. I tried VisualVM, but that appears to not want to play nice with cursive’s REPL

eggsyntax00:02:36

It’s been a long while since I’ve used Cursive, but doesn’t it have some built-in profiling? I could easily be misremembering.

Lennart Buit21:02:35

(VisualVM appears to be quite unstable~ish on MacOS, often not updating)

JIacheng Yang22:02:50

Why is this a memoized fibonacci calculation? It seems to me that an atom of empty map is created every time memoize is called and not passed around

seancorfield22:02:15

@yjc961020 (def fib (memoize fib)) is a one-time call that binds the result of calling (memoize fib) -- which returns a function -- to the symbol fib, and the subsequent calls to fib call that (returned) function, they do not call memoize again.

JIacheng Yang22:02:08

oh, i see so there is only one atom which serves as the cache for values?

seancorfield22:02:14

If you said (defn fib2 [n] ((memoize fib) n)) then you would be calling memoize with each call to fib2.

seancorfield22:02:03

(def fib1 (memoize fib))
(def fib2 (memoize fib))
(def fib3 (memoize fib))
now you have three separate atoms, one for each call to memoize.

seancorfield22:02:46

But each of fib1, fib2, and fib3 can be called separately (they are three different functions, each with their own cache). So (fib1 35) will be slow on the first call and fast on the second (and subsequent ones). If you then call (fib3 35) it will also be slow on that first call and then fast on the second etc.

JIacheng Yang23:02:01

Yes, it is much clearer to me now. Thanks