This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-27
Channels
- # aleph (1)
- # announcements (39)
- # aws (11)
- # beginners (58)
- # calva (10)
- # cider (7)
- # clj-kondo (65)
- # cljs-dev (5)
- # clojure (90)
- # clojure-dev (48)
- # clojure-europe (23)
- # clojure-madison (1)
- # clojure-norway (1)
- # clojure-uk (40)
- # clojured (11)
- # clojurescript (20)
- # conjure (12)
- # core-async (4)
- # core-logic (4)
- # cursive (3)
- # datalevin (1)
- # emacs (7)
- # events (2)
- # fulcro (48)
- # introduce-yourself (2)
- # lsp (36)
- # malli (11)
- # missionary (1)
- # off-topic (1)
- # other-languages (72)
- # pathom (4)
- # polylith (13)
- # portal (94)
- # re-frame (14)
- # react (5)
- # releases (1)
- # sci (12)
- # shadow-cljs (29)
- # spacemacs (3)
- # vim (4)
- # xtdb (12)
Back to "Brave and True"...
2. write a function, append, which will append a new suspect to your list of suspects
I can get this to work stand-alone:
(conj (parse (slurp filename)) ["John Smith" "0"])
=>(["John Smith" "0"]
["Edward Cullen" "10"]
["Bella Swan" "0"]
["Charlie Swan" "0"]
["Jacob Black" "3"]
["Carlisle Cullen" "6"]
["John Cena" "0"])
But when I try to wrap it into a function:
(defn append
[name glitter-index]
(conj (parse (slurp filename)) [name glitter-index]))
I get...
; Execution error (ArityException) at fwpd.core/eval7950 (form-init9865369693235614087.clj:70).
; Wrong number of args (1) passed to: fwpd.core/append
How do I pass a record (Name and glitter-index) as a single argument?
the error message says you're passing one argument but the function is written to take two arguments. can you just do (append name glitter-index)
instead? that will work with the current code
otherwise you'll need the function to take a single argument, like (defn append [name-and-glitter-index] (conj ... name-and-glitter-index))
and call it like (append [name glitter-index])
@U02N27RK69K (append "new name" "0")
worked. I originally ran it as (append ["new name" "0"])
. Why isn't the latter a valid call?
because it's passing one argument, a vector, instead of two
Am using https://github.com/ptaoussanis/carmine to interact with Redis. Each time I start a REPL or compile I get the following warnings. Is there a way to not show these warnings ?
WARNING: abs already refers to: #'clojure.core/abs in namespace: taoensso.encore, being replaced by: #'taoensso.encore/abs
WARNING: update-keys already refers to: #'clojure.core/update-keys in namespace: io.aviso.exception, being replaced by: #'io.aviso.exception/update-keys
WARNING: parse-long already refers to: #'clojure.core/parse-long in namespace: taoensso.carmine, being replaced by: #'taoensso.carmine/parse-long
WARNING: parse-double already refers to: #'clojure.core/parse-double in namespace: taoensso.carmine, being replaced by: #'taoensso.carmine/parse-double
You need to exclude them explicitly.
(ns your-namespace
(:refer-clojure :exclude [abs update-keys])
...)
But, that would need to be done inside taoensso, so otherwise if you don't have access to that code since it's a library O don't think you can hide the warming
Well, technically I think you could do something, but it's a bit complicated and I wouldn't recommend it, best to just live with the warnings and ignore them.
I would like to have a base library providing components to several other applications. components (mount) in the base: β’ config β’ postgress connection β’ db2 connection β’ ibm mq connection (with jms listener) β’ pathom β’ immutable web server β’ rabbit mq streams β’ fucro β’ soap β’ ..... So the goal is that my apps would use just a couple of deps beside the base. And there comes a problem, I just don't want that app using rabbit-mq-stream and postgress will include all the jars from the base (all jars required by fulco, pathom ...). The base should be tested well enough that I am sure that all components can be used in one project. Is it possible to solve it with aliases in base/deps.edn and referring required alias in app/deps.edn?
this is not the nicest road but you can get some inspiration from this set of articles - https://corfield.org/blog/2021/02/23/deps-edn-monorepo/
I'm not sure what the input is to your problem. Is a user going to run a command program with flags like +fulcro?
If they are building the deps file manually, then i assume a base deps file added to others would achieve this as well.
One of my programs will listen on rabbitmq stream and put some data into postgress and ibmmq. Another app will listen to rabbit and visualize events on frontend fulcro UI. Another app will listen on ibmmq and forward events to soap endpoints. So many apps, and I could end with copy pasting boilerplate code from one to another. So I want DRY and small docker images
Did you have a look at #polylith? It helps you organize your repository to span over multiple projects, components and a decoupled development project (that you set up to be repl friendly) dependencies are defined per use-case.
Thanks, I am going to study polylith and monorepo and do some experiments. I was hoping for some some does.edn magic, so that my base project would be usable outside my organization.
This is a rough sketch of something I figured out the other day https://gist.github.com/bsless/839bbf7b7ab73adfba6703e79c079cff Aligning dependencies between modules isn't solved yet with this, but I have a few idea
@UK0810AQ2 the link is giving me a 404.
The final deps.edn is built from 3 deps.edn files: system, user, project. If there would be a possibility to inject another one, all problems could be solved with aliases?
@U0DJ4T5U1 fixed, must have missed a character
When I use clj
in the same dir as a deps.edn
file, how can I have it run a repl while also loading some namespace? So I can have some src/main.clj
with a bunch of helper functions ready to go.
using clj -i src/main.clj
errors:
WARNING: Implicit use of clojure.main with options is deprecated, use -M
And I'm not sure exactly how to use -M/tmp/foo via :coffee: v17.30
β― cat deps.edn
{:paths ["."]}
/tmp/foo via :coffee: v17.30
β― cat foo.clj
(ns foo)
(def x 3)
β― clj -M -e "(doto 'foo require in-ns)" -r
foo
foo=> x
3
so you just -e
to evaluate a form to require and set the namespace and -r
to get a repl.
I think this is a bit much and i just prefer to use the normal interactions of a repl to require whatever namespace i needthere is a shady trick - you can use not well documented feature of clojure repl add somewhere in your path file user.clj and it will be loaded automatically whenever you start new repl
/tmp/x via β v11.0.11 took 8s
β― tree .
.
βββ deps.edn
βββ src
βββ user.clj
1 directory, 2 files
/tmp/x via β v11.0.11
β― cat deps.edn
{:paths ["src"]}
/tmp/x via β v11.0.11
β― cat src/user.clj
(defn foo [] "!")
/tmp/x via β v11.0.11
β― clj
Clojure 1.11.1
user=> (foo)
"!"
I usually have a dev directory with user.clj and everything else that I need during development. then in deps.edn I add an alias :dev {:extra-paths ["dev"]}
and use this alias to spin up the repl
@U11BV7MTK That worked nicely thank you!
@U04V4KLKC What am I doing wrong here?
[email protected] .cljhome % tree
.
βββ README.md
βββ deps.edn
βββ src
βββ main.clj
1 directory, 3 files
> [email protected] .cljhome % cat deps.edn
{:deps
{clj-http/clj-http {:mvn/version "3.12.3"}
org.clojure/core.async {:mvn/version "1.5.648"}}
:paths ["src"]}
> [email protected] .cljhome % cat src/main.clj
(ns main
(:require [clojure.core.async :as async]
[clj-http.client :as client]))
(defn health-check []
(:body (client/get "")))
> [email protected] .cljhome % clj
Clojure 1.11.1
user=> (health-check)
Syntax error compiling at (REPL:1:1).
Unable to resolve symbol: health-check in this context
user=>
Filename must be user.clj
Ahh gotchya. I see that said here now: https://practical.li/clojure/clojure-cli/projects/configure-repl-startup.html surprised it's not in the deps and cli docs: https://clojure.org/guides/deps_and_cli
How do you comp
a seq
functions?
(def search-function
(->> search-settings
(select-keys search-functions)
(vals)
(comp)))
vals
returns a clojure.lang.APersistentMap$ValSeq
, passing it to comp
doesn't change it.Cheers, that seem to have evaluated them. However the arity of those functions is 2, I'm getting an exception of wrong arity passed (1).
(search-function people "eva")
Guessing that (apply comp)
needs some more help?I want one function, composed of several functions that I got out from a map of keyword, function
.
You mean partially apply them? If so, I need to keep the arity 2 as I want to reuse this function for different inputs. Eg:
(search-function people1 "eva")
(search-function people2 "steve")
Ah yes, sorry, can't π
just throwing out ideas - how about wrapping them first in an FN that takes 1 argument and returns a function with the second argument while the first ist bound
Sort of like a lazy partial? Yeah that probably works. Not great, but it works.
I've used Ramdajs in the past, rewriting some stuff in Clojure.
There it's:
const searchFunction = R.compose(...searchFunctions)
Does Clojure automatically support currying? Maybe that's the reason.
Ah, that explains the problem and your suggested solution!
If you want great tutorials about everything Clojure (testing, React/Reagent, tooling, Datomic, etc), checkout https://lambdaisland.com/episodes which just released their paywalled videos to the public.