This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-02
Channels
- # announcements (2)
- # beginners (69)
- # boot (1)
- # cider (35)
- # clara (1)
- # cljs-dev (1)
- # clojure (40)
- # clojure-spec (11)
- # clojure-uk (8)
- # clojurescript (9)
- # cursive (1)
- # datomic (5)
- # figwheel-main (25)
- # fulcro (64)
- # jobs (2)
- # jukebox (1)
- # kaocha (3)
- # off-topic (7)
- # pathom (39)
- # planck (5)
- # random (1)
- # re-frame (11)
- # reagent (8)
- # shadow-cljs (58)
- # test-check (41)
- # vim (13)
in re-frame I'm building a simple timer with a button. On button press I :start-timer
and save the current time, then after another press I save the new current time with :stop-timer
. Is a fn calculating the duration a view function?
I'm trying to make a function which merges two vectors together recursively, but for some reason I'm getting an weird vector in return and I'm not sure what's happening here.
vector
builds a vector containing its arguments, which in this case is first item of either x or y and then another vector returned by the recursive call to my-merge
this looks reasonable, but the recursive mrg
call should be replaced with a recur
call https://gist.github.com/baabelfish/6573984
@nicholas.jaunsen can the vectors be of different lengths?
(sort (concat x y))
this is presumably a merge function for merge sort. the vectors will be of differing lengths and calling sort will circumvent the purpose of writing the function in the first place
so when looking at docs it seems ok to use one word parameters, eg. s
for string, n
for numbers, f
for functions. But I also see people do things like pull in spec :as s
Does that make it confusing for others or does the context usually make it obvious? How far can I go? c
for char? Any other ones I should know? Collections seem to be coll
right?
for example, the exercise asked me to create a function finding the frequency of a letter in a string. So I wrote this:
(defn freq-of-letter [c s]
(count (filter #(= % c) (seq s))))
Will clojure programmers know what I'm saying there or is it too obtuse?I'm no authority, but the use of "letter" and "frequency" in the function name makes me intuitively realize that we will be working with a seq of characters
so c and s are automatically recognized as what they are meant to be
Namespace aliases are meaningful only in a small set of places where they can only be aliases, so I never worry about confusion there
In your code I might use letter
or ch
instead of c
Ok, I got it working with cons
but now I've rewritten it with a loop, but it think it's stuck in an infinite loop. I can't get emacs to evaluate a merge anyways .
Can you give me an example that this hangs on?
The x and y in the loop refer to the outer params, not the loop bindings
So it never hits the termination conditions
Instead of [a & as], do [a & as :as xs] then xs inside the loop, same for bs/ys
Since the var x is never rebound to anything else, it will never be empty. So you have to use the :as keyword for destructuring, which will be rebound on every iteration. Is that right?
If you write the loop head like a let with newlines it’s clearer that only the left hand sides are bound
From a language design perspective, it makes sense to keep x and y bound to their original values because you might want to test against the starting values at the end of the loop or something like that.
Instead of like an "implicit" :as
so you want something like this. Might have gotten the variables mixed up but the idea is to use the :as keyword to refer to the bound var
why is it that loop recur is more performant than just calling the function name recursively?
Calling the function adds a stack frame, which consumes memory (and stack depth is limited). recur does not - turns into a loop (really a goto at the bytecode level)
I literally just read about that! Look on this page for the recursion section about half way down: https://aphyr.com/posts/305-clojure-from-the-ground-up-macros
To add to the above, java doesn't have native support for tail call optimization, so the recur macro adds that for our benefit.
I think the tl/dr is that if you use the function name recursively you have to hold every single recursive call in memory until it's all complete. recur tells the compiler you don't need to hold on to it.
Or it is actually a special form. But there is a small benefit to using the "recur" explecitly for TCO, because you will be warned when your recursion point isn't in the tail position.
if I re-frame/dispatch
two events at the same time are they evaluated at the same time or fifo? eg (re-frame/dispatch [:event1 :event2])
(or should that be two vectors?
There is a #re-frame channel if you don't get an answer here.
When using specs - if I want to run all the generative tests, how can I do it easily with Leiningen? Is there something like lein test
are there literals to enter numbers in base 16? if not, what would be the idiomatic way? i'm talking about clojurescript in case that depends on interop
Clojure on the JVM lets you write things like 0xdeadbeef for hex literals in the source code. I just tried that in a ClojureScript node.js REPL, and it worked there, too.
Is there something that's the equivalent of this function in Clojure? http://php.net/manual/en/function.base-convert.php
(Integer/toBinaryString 12)
looks like I can use this to go from base 10 to base 2: https://youtu.be/kVvP5MNIND4
I'm thinking about using iterate
to generate the sequence from 32 (for example) back down to 0 (by div 2), there will be a point where I want to stop generating the sequence (at 0) is that the responsibility of the thing moving over the sequence or the iterate
function?
if it is the iterate f
how do I signal the end of the sequence?
iterate
returns an infinite lazy sequence. You can use take
, take-while
, etc, to consume a portion of that sequence. For example, take-while
could be used to consume everything up to the first zero value.
Hello, I started with clojure and spacemacs yesterday and have created an simple project
lein new project_name
. When i try run cider on core.clj a bunch of warnings come out and repl does’nt startCan anyone help me?
do you guys know some GUI-using project that isn't "hello world"? I'm trying to figure out how people usually do it I saw a while ago a clojure library for dealing with Swing, but I also would like to use animations (e.g. https://github.com/kirill-grouchnikov/radiance)
and if I'm going to use this library and the swing API's objects directly, I might as well interop with Java directly
but perhaps there is something like this for GUI clojure already and I don't know about it
@joao.paulo.silvasouza Have you looked at this https://github.com/daveray/seesaw ?
(I have no idea about this area -- I never build Java UIs -- but Seesaw is the library mentioned most when folks ask about Swing)
I thought Swing was sort of deprecated in favor of JavaFX these days?