This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-01-27
Channels
- # aws-lambda (2)
- # babashka (22)
- # beginners (188)
- # calva (24)
- # cider (16)
- # clj-kondo (2)
- # cljfx (5)
- # clojars (15)
- # clojure (146)
- # clojure-czech (1)
- # clojure-europe (10)
- # clojure-france (3)
- # clojure-provo (1)
- # clojure-sweden (8)
- # clojure-uk (6)
- # clojurescript (28)
- # conjure (3)
- # core-logic (1)
- # cursive (13)
- # datahike (2)
- # datomic (18)
- # defnpodcast (2)
- # figwheel-main (2)
- # fulcro (1)
- # honeysql (4)
- # hoplon (21)
- # jobs (3)
- # jobs-rus (1)
- # kaocha (5)
- # off-topic (49)
- # pathom (86)
- # reagent (4)
- # remote-jobs (2)
- # ring (4)
- # schema (1)
- # shadow-cljs (40)
- # spacemacs (12)
- # sql (20)
- # startup-in-a-month (30)
- # xtdb (19)
I am trying to use a custom deps.edn
in my ~/.clojure/
folder.
{
:paths ["src"]
:aliases
{
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Creating projects from templates
;; clj-new -
:new {:extra-deps {seancorfield/clj-new {:mvn/version "1.1.234"}}
:exec-fn clj-new/create
:exec-args {:template "app"}}}
}
https://github.com/seancorfield/clj-new
According to the documentation it states that i can use the alias to create a new project. But whenever i try to execute the command clojure -X:new :name myname/myapp
i get an error message
Execution error (FileNotFoundException) at java.io.FileInputStream/open0 (FileInputStream.java:-2).
-X:new (No such file or directory)
When i make a typing error in the deps.edn
it states the error, so i am sure the custom deps.edn
is used.
Any pointers what i am doing wrong?which version of clojure cli you using?
(Checking my notes) The first command to use is clojure -A:new app practicalli/simple-api-server which doesn't work, because we have to install the clj-new project. This is done by updating ~/.clojure/deps.edn and adding an alias Note that copying and pasting the example from the readme doesn't work {:aliases {:new {:extra-deps {seancorfield/clj-new {:mvn/version "1.1.234"}} :exec-fn clj-new/create :exec-args {:template "app"}}} ...} But this does: :aliases { :deps {:extra-deps {org.clojure/tools.deps.alpha {:mvn/version "0.9.857"}}} :test {:extra-paths ["test"]} :new {:extra-deps {seancorfield/clj-new {:mvn/version "1.1.234"}} :exec-fn clj-new/create :exec-args {:template "app"}} } Sorting this out was interesting (something to do with the curly braces).
that same command and same deps alias works fine for me. the error makes it seem like there might be an extra argument being passed
it looks like it's trying to open a file named "-X:new"
execution mode was added in https://clojure.org/releases/tools#v1.10.1.697
yes) update should fix that
@delaguardo It worked!!! Again thanks!
@marco.pasopas you may find this book useful when using Clojure with CLI tools http://practicalli.github.io/clojure/ I also have a well documented user-wide deps.edn configuration with a wide range of tools https://github.com/practicalli/clojure-deps-edn
there are plenty documentation available for both )
I have done one which works wih on-click
but I see also some of them which uses subscribe
so confusing
I recommend the guides on http://purelyfunctional.tv
https://purelyfunctional.tv/guide/reagent/ https://purelyfunctional.tv/guide/re-frame-building-blocks/
Any suggestions on getting started and designing apps with Clojure and Kafka streams? I've ask this in #apache-kafka so appreciate answers there. https://clojurians.slack.com/archives/CDAA5T4KZ/p1611742901000200
@jr0cket Thanks for the pointer! I already found the deps.edn collection and surely they are usefull!!
An error has occured for me a couple of times the past days (Using Vs Code and Calva). Anyone know why this is happening?
Syntax error compiling at (src/clojure_functions/core.clj:22:1). Unable to resolve symbol: defn in this context
do you have :refer-clojure
in your ns
?
I’m asking because it is possible to exclude symbols from clojure.core
using form like that (:refer-clojure :exclude [defn])
in ns
do you mind to share the code? it is hard to guess based on exception message
Yeah I understand! Here is the full code:
(ns clojure-functions.core)
(defn my-reduce
"expects a funtion a value and a collection"
([f coll]
(if (empty? coll) (f)
(my-reduce f (f (first coll) (second coll)) (rest (rest coll)))))
([f val coll]
(loop [acc val remaining-coll coll]
(if (empty? remaining-coll)
acc
(recur (f acc (first remaining-coll)) (rest remaining-coll))))))
(defn my-count
"returns the number of items in a collection"
([coll] (my-count coll 0))
([coll acc]
(if (empty? coll)
acc
(my-count (rest coll) (inc acc)))))
It is working when I test the functions with Midje, so its related to the Calva I think
yeah, lgtm so probably it is midje or calva
this can often happen if you execute (in-ns my-namespace)
before requiring or executing a proper ns
form
right! I can reproduce
dev> (in-ns 'sample.core)
;; => #namespace[sample.core]
sample.core> (defn foo [])
Syntax error compiling at (*cider-repl xapix/clojud:localhost:49518(clj)*:2721:14).
Unable to resolve symbol: defn in this context
With Calva the easiest way is to always start with loading the file, Calva avoids loading things automatically for you. I think that is the way it should be, but it does create a Ux problem for people that are new to the dynamic nature of a Clojure program in development. I’ve tried to mitigate it some by having the https://calva.io/try-first/ article of the docs start with: > You should start with loading the file you are working with. Do this with Load Current File and Dependencies, `ctrl+alt+c enter`.
Thank you so much for the answer, loving Calva btw, made me change from Emacs & Cider:v:

I’m getting this error when trying to jack-in using Cider
. Unhandled clojure.lang.Compiler$CompilerException
Error compiling src/reader/snake.clj at (1:41)
Compiler.java: 7526 clojure.lang.Compiler/load
REPL: 1 user/eval6049
REPL: 1 user/eval6049
Compiler.java: 7062 clojure.lang.Compiler/eval
Compiler.java: 7025 clojure.lang.Compiler/eval
core.clj: 3206 clojure.core/eval
core.clj: 3202 clojure.core/eval
interruptible_eval.clj: 82 nrepl.middleware.interruptible-eval/evaluate/fn/fn
AFn.java: 152 clojure.lang.AFn/applyToHelper
AFn.java: 144 clojure.lang.AFn/applyTo
core.clj: 657 clojure.core/apply
core.clj: 1965 clojure.core/with-bindings*
core.clj: 1965 clojure.core/with-bindings*
RestFn.java: 425 clojure.lang.RestFn/invoke
interruptible_eval.clj: 82 nrepl.middleware.interruptible-eval/evaluate/fn
main.clj: 243 clojure.main/repl/read-eval-print/fn
main.clj: 243 clojure.main/repl/read-eval-print
main.clj: 261 clojure.main/repl/fn
main.clj: 261 clojure.main/repl
main.clj: 177 clojure.main/repl
RestFn.java: 1523 clojure.lang.RestFn/invoke
interruptible_eval.clj: 79 nrepl.middleware.interruptible-eval/evaluate
interruptible_eval.clj: 56 nrepl.middleware.interruptible-eval/evaluate
interruptible_eval.clj: 145 nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
AFn.java: 22 clojure.lang.AFn/run
session.clj: 202 nrepl.middleware.session/session-exec/main-loop/fn
session.clj: 201 nrepl.middleware.session/session-exec/main-loop
AFn.java: 22 clojure.lang.AFn/run
Thread.java: 748 java.lang.Thread/run
1. Caused by java.lang.Exception
No namespace: examples.import-static
I’m following an example for Programming Clojure This is the code so far
(ns reader.snake
(:import (java.awt Color Dimension)
(javax.swing JPanel JFrame Timer JOptionPane)
(java.awt.event ActionListener KeyListener))
(:refer examples.import-static :refer :all))
(import-static java.awt.event.KeyEvent VK_LEFT VK_RIGHT VK_UP VK_DOWN)
but the error seems straightforward : "No namespace: examples.import-static". relating to your (:refer examples.import-static :refer :all)
(which seems quite strange to me
yes. the examples.import-static is a reference to shcloj3-code/code/src/examples/import_static.clj
Here's something that didn't work:
(ns com.logicgate.helper.config)
...
(defn -main []
(test/run-tests 'com.logicgate.helper.config))
any thoughts on how i can do this? for context, i'm trying to run these tests in a docker container, since i bet i'm going to mess up configuring for that environment
should the cmd be clojure -A:test-config?
i'm pretty fuzzy on M vs A vs X, adam-james.... what i had was copypasta from my "true" main functions that do work from other ns's
From the code you posted, it looks as if :test-config is an alias. My understanding is that -M specifies a namespace in which a main function exists, but -A will run an Alias from a deps.edn file. I use aliases to launch dev or build depending on needs.
apologies, it looks like i was mixing up -M with -m. please disregard, I don't think I'm helping after all 😕
I wonder why:
(map Integer/parseInt ["2011" "3" "21"]) ;this doesn't work
(Integer/parseInt "2011") ; but this is fine
It’s a Java method, not a Clojure function
Integer/parseInt
is a Java method, not a clojure function. To use it with map
and so on, you need to wrap it in an anonymous function like #(Integer/parseInt %)
@manutter51, I didnt know this limitation. I guess it is more general where else does it apply ?
@caumond on the vm / bytecode level, "methods" don't exist as real things, they are something an object knows how to do and only the objects are concrete
@caumond a clojure IFn is an object that only exists to carry a method (one which clojure calls if you put it in parens)
so, more concretely, you can't put something that isn't an Object on the stack, and IFn is an object, so you can put it on the stack, unlike a method
in order to pass something as an argument, it needs to end up on the stack
you can use method call interop syntax with IFn objects
user=> (.invoke str nil)
""
Yes. Very clear. Thanks. Im definitly not sure ive ever read something like that in the books I read.
(there's the potentially misleading fact that reflection api offers "method handles", which are Objects that allow you to manipulate / use the methods on another Object, but we'd be badly off if we needed to reflect and use method handles everywhere)
Hey Guys, I'm kind of stuck trying to get some data from a textfile. It already worked today but I destroyed it likely.
(map #(subs % (count prefix)(clojure.string/split-lines (slurp file-name))))
#object[clojure.core$map$fn__4781 0x5f20155b clojure.core$map$fn__4781@5f20155b]
After converting the data I'm trying to compare them with clojure.set/difference but this works neither.
(let [proef (set/difference (set prae) (set post)) ]
(println proef)
))
Any suggestions what's going wrong?your map
is only given a single argument here rather than two. i imagine you need to spit the split-lines form out of the subs form
single arg map arity strikes again
in the history of clojure paper (and elsewhere i think) rich mentioned that if he started Clojure again today it would be based on transducers by default rather than laziness. i wonder what that would look like
there are two distinct reifications of methods as objects java.lang.reflect.Method and java.lang.invoke.MethodHandle, reflect.Method is the older reflection api, MethodHandle is the new stuff built to work with (but possible to use independent of) invoke dynamic
@3samgal your second piece of code has an extra paren
On the 3rd line
yeah - I suggest taking some time to learn normal formatting / indentation conventions, they tend to make it easier to find and fix these sorts of bugs
indentation doesn't matter to the computer but properly indented code will make mistakes jump out at you
it's like traffic rules or human language - at first it doesn't help, but it makes working with others a lot easier, and in theory an isolated Galapagos of coders could invent their own conventions that are equally useful in their context
(I learned this lesson about math recently, upgrading from an ad-hoc rotation and mirroring of shapes to standard matrix transforms)
I mean much more generally than that - my ad-hoc rotation / flipping code did everything the matrix transform did, but by using the standard mathematical object (a transform matrix) I have a reference which makes finding bugs easier
@3samgal we don't leave dangling braces, and split lines for clarity - eg.
(map #(subs % (count prefix))
(clojure.string/split-lines (slurp file-name)))
notice that the args for map line up (since they are at the same abstraction level)
(let [proef (set/difference (set prae) (set post))]
(println proef))
the println aligns under the let
not the [binding block]
- it doesn't belong as a child of the bindings, it belongs as a child of letOk thank you. In school we are learning C. There we usually use parenthesis the other way.
right, that's why I compare it to traffic rules (we drive on our side of the street, they drive on theirs)
@noisesmith Reminds me of something I read once about Richard Feynman -- he reinvented / rediscovered parts of trigonometry on his own, and had a period of adjustment when he found out what notation others used for it in math classes.
haha, right - as programmers we do a lot of off-roading but sometimes its useful to be able to adopt the official traffic rules and get on the freeway
and the more math I learn (mostly set theory, linear algebra, group theory, category theory so far), the more I see things I used informally / in a very basic way, reformatted to be simpler and more reusable
not claiming to be anything like a Feynman, I'm just fiddling with some numbers
I was impressed that he rediscovered parts of trigonometry on his own before learning it from others. Pretty cool.
he would have been a polymath if he was born two centuries sooner, he was just that kind of thinker
Thanks for the hint, but the parenthesis is part of the function ahead. Any other ideas?
It's gotta be a #{set} to use clojure.set/union, clojure.set/difference
https://clojuredocs.org/clojure.set/union
https://clojuredocs.org/clojure.set/difference
I think you could do (into #{} (distinct -vals-)
since a set must have unique values only
Am I right that subcribe
is re-frame where on-click
is reagent and on both something happens ?
the :on-click function of an html element is the function that gets called if you click it - this is a direct translation of an html feature subscribe is an abstraction over reagent r/atom r/atom is a data structure that will cause your page element to be re-rendered if the data you access changes
instead of specifying a change to the DOM in order to change what renders, you provide a function that uses application data (via r/atom or subscription), and then the framework promises to call your rendering code if the data you used changes
on-click is one popular way to trigger an app data change that would lead to a re-render, but there are a few steps in between
the "something" that happens is that your template function gets called again with new data
you can think of it as a way to get data, but also as a way of telling your app to reload “this specific part of the html” when the data changes. for example this one has both:
(defn home-page []
(let [form-data @(re-frame/subscribe [::subs/form-data])]
[main-layout
[:div.card>div.card-content
[:div.field.has-addons
[:label.label "What's your name?"]
(form-input "text" :name form-data)
[:button.button.is-info.is-light {:on-click #(re-frame/dispatch [::events/push-state :quizzes/index])} "Select Quiz"]]]]
))
so in this case if the form-data changes, this part of the dom gets reloaded, and if you click the button, it dispatches an event (in this cases changes the “route”
:on-click is typically used to turn user actions into data changes
then subscribe is used to turn data changes into content changes
(other things can cause data changes too, eg. data coming back from an api, or just landing on a new route)
hmm, on the reagent course I followed I never used subcribe
and on the re-frame course of the same person ` subscribe is used
reagent doesn't have subscribe, it's something re-frame introduces
in fact you could say that re-frame is reagent + subscribe (plus a few nice widget definitions you can use)
oke, maybe I stay then with reagant because the only thing I need is to show a modal when a user clicks on a painting
yeah, the basic big picture of a reagent version is that the atom would have a key for the data the modal uses, and the click would fill in data under that key
because I do not need subscribe. I solved the problem with fetching from api wth pre-loading
then the template decides whether to output the markup for the modal, based on whether it sees the data
right - this example is probably small enough that re-frame doesn't become especially useful yet, and you can always add re-frame to a reagent project later
hmm, I thought with a click could first fetch he data from the apio because I cannot know which pianting a user wants to see some info
1. user click makes a fetch start 2. fetch completes, r/atom gets filled in with new data 3. reagent runs your template again with the new data
one advantage of re-frame is its subscriptions make that flow more explicit, but it's still probably more than you need for this case
just remember that most UI changes start with changing contents of an r/atom
and maybe later I could try re-frame to instead of the pre-loading that the user sees a empty painting whcih is switched to the real image as soon as the url is returned
It's not possible to destructure in the arguments, right? Example might explain better:
(defn decomp-test [[a b c]]
(+ a b c))
(decomp-test [[1 2 3]]) ; so this can be 6?
here a simple apply would work, it's more of a thought experiment, because it's perfectly fine in prologNB nested destructuring (or mix of map and sequential destructure) is usually better done in a let block
the first one is just the arguments that come in, the second one is the first vector, and the third one is the second vector
@christiaaan because you are passing a one element vector of vectors, so your destructure needs to match the shape
destructure gives you named arguments
maybe I misunderstand that question
no, you are right. I was just stumbling over the [[[ thing, as it looks not that idiomatic
@christiaaan right, the part that is weird is that you'd define operations on single item vectors of vectors
my function gets a sorted list, and I wanted to avoid apply, I guess apply is prettier
Here you can run this and see all the stages of destructuring that you went through
(let [first [[1 2 3]]
[second] first
[[a b c]] first
[a2 b2 c2] second]
(prn (str "first=" first))
(prn (str "second= " second))
(prn (str "sum of a b c= " (+ a b c)))
(prn (str "sum of a2 b2 c2= " (+ a2 b2 c2))))
I would have had [a b c] second
on that last binding line (same result)
I think it's easier to understand with the let
(defn is-valid?
"Checks the three sides of a would be triangle."
[a b c]
(let [[shortest short longest] (sort [a b c])]
(and (< 0 shortest)
(> (+ shortest short) longest))))
@christiaaan also consider (< 0 shortest longest (+ shortest short))
I guess that needs to be <=
maybe...
@christiaaan my mental model for <
is that it takes a series of numbers whose line graph rises like the top half of the symbol 😄
it appears that we have no :stonks: or :line_goes_up:, which is probably for the best
right, shortest and longest could be equal
of course you could have (< 0 shortest (inc longest) (+ 1 shortest short))
but that's weird
Hi! I finally made fast binary exponentiation algorithm. Could you review it? https://github.com/reflechant/binary-pow/blob/main/src/binary_pow/core.clj
so powers
isn't the powers of x, it's x, square x, square(square x) etc?
I don't know this algorithm off the top of my head, but with a name like powers I expected powers of x
ins)user=> (take 10 (iterate #(*' % %) 2))
(2 4 16 256 65536 4294967296 18446744073709551616N 340282366920938463463374607431768211456N 115792089237316195423570985008687907853269984665640564039457584007913129639936N 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084096N)
(ins)user=> (take 10 (iterate #(* % 2) 2))
(2 4 8 16 32 64 128 256 512 1024)
• - edit, that last step's a doozy@noisesmith it depends on whether the power is even or odd
I was using this description: https://cp-algorithms.com/algebra/binary-exp.html
oh, it is a sequence of squares, super surprising but I see