This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-02-05
Channels
- # announcements (16)
- # babashka (10)
- # beginners (80)
- # calva (18)
- # cider (10)
- # clojure (96)
- # clojure-austin (1)
- # clojure-europe (52)
- # clojure-france (6)
- # clojure-germany (2)
- # clojure-italy (4)
- # clojure-nl (4)
- # clojure-seattle (3)
- # clojure-spec (4)
- # clojure-uk (25)
- # clojurescript (97)
- # community-development (2)
- # cursive (7)
- # datomic (13)
- # figwheel-main (5)
- # fulcro (13)
- # inf-clojure (1)
- # jobs (3)
- # off-topic (33)
- # pathom (10)
- # polylith (8)
- # re-frame (7)
- # reitit (8)
- # releases (1)
- # reveal (2)
- # ring (4)
- # ring-swagger (1)
- # sci (6)
- # shadow-cljs (102)
- # slack-help (1)
- # spacemacs (28)
- # tools-deps (9)
- # vim (1)
- # xtdb (3)
Is there a way to get the function and/or its namespace from within the clojurescript function? Something like
(defn a-function []
(.log js/console <namespace>.<function-name>))
Hi guys, as stupid as it looks, but i literally clueless how to install https://github.com/clojure/data.csv Can i just copy & paste csv.clj into my project "src" folder? if yes, then each time i create a project, i need to paste csv.clj into my src project, am i correct?
How did you set up your project? With leiningen or deps.edn, maybe?
with leinengen
lein new app dummyProject
as an example
edit your project.clj to add these lines for data.csv:
(defproject reference "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url ""
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
:url " "}
:dependencies [[org.clojure/clojure "1.10.0"]
[org.clojure/data.csv "1.0.0"]]
:main ^:skip-aot reference.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all}})
See the dependencies section ^^e.g. something like this
(ns foo.core
(:require [clojure.data.csv :as csv]))
You can now reference it in your code using the csv
alias.oh okay @U013YN3T4DA , i'll try it... thanks for the step by step. so for each project i made, i need to add these lines into my project.clj, CMIIW?
(defproject reference "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url ""
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
:url " "}
:dependencies [[org.clojure/clojure "1.10.0"]
[org.clojure/data.csv "1.0.0"]]
:main ^:skip-aot reference.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all}})
The important part is here:
:dependencies [[org.clojure/data.csv "1.0.0"]]
This is where you specify the dependencies you want to use, so in your case the data.csv.
If you know C#/F# its similar to adding nuget referencesIf you are using deps.edn rather than project.clj, it's different. To find out what the dependency you need to add usually you go to the github page of the project: SO in this case you are using leinengen, so you want the leinengen dependency information:
For lein, it will be in that format. A vector with 2 items, the first being the dependency and the second being the version.
AHHHH GOTCHA! Thanks a lot @U013YN3T4DA!! 😅🙏
Happy Friday fellow new Clojurians 💪 I'm streaming my morning warmup session again this morning if you'd like to join me for a quick 30-minute code challenge! Challenge should start around 9:45-ish EST. Stream located here: https://www.twitch.tv/a_fry_ We're trying to solve https://purelyfunctional.tv/issues/purelyfunctional-tv-newsletter-412-module-depth-is-bogus/ using https://clojure.org/guides/spec. Spec has been an interesting beast so far. I've been poking at it trying to make sense of it for a few days now, but I think I'm about to have a breakthrough. Not only with spec, but also with https://clojuredocs.org/clojure.core/quote, which is yet another powerful tool that I kind of understand in theory, but not in practice. Anyway, we'd be glad to have you along 🙂
Hello guys. Anyone here knows how to convert a vector to a map in clojure? I tried to use "into {}" and "conj {}" but it didn't work the way I want.
Tried: (conj {} [:a "aaa" :c "ccc"])
But returned only => {:a "aaa"}(apply hash-map [:a "aaa" :c "ccc"])
Thanks!! That's exactly what I need!!! Solved my problem!!! Have a nice day!
Team , I have below atom object like this
{<input> #objectcom.dinesh.AbstactModel 0xe316971 <AbstactCom
{:a "a" :b "b"} |
["a", "b", "c"] >]}
atom's have two principal functions to interact with them. reset!
which takes a value and makes the contents of the atom that value, and swap!
which takes a function which takes the current value of the atom and makes the atom's value the result of (f value-of-atom)
. I'm not sure what your data is, but if you know how to transform your data with some function f
, then just (swap the-atom f)
will do whatever you want. The point is that the fact that its an atom should be basically irrelevant with those two functions. If you know how to transform your data, figure that part out and then call (swap! the-atom my-function)
or (reset! the-atom some-value)
atom's are kinda meant to be used with immutable data. if a com.dinesh.AbstractModel
is mutable you might not need the atom around it
classic example, a mutable java hashmap
~/p/clojure ❯❯❯ clj
Clojure 1.10.2
user=> (def x (java.util.HashMap.))
#'user/x
user=> x
{}
user=> (.put x 1 2)
nil
user=> x
{1 2}
user=>
@popeyepwr an atom is only a container, what is an AbstactModel?
why is it in an atom?
anyway, "object returned from a java method" describes every value possible in clojure
the real answer lies in understanding the object you are trying to use
I am calling java method on atom object
(println " ---1---" (swap! atom-name (.removeAll Abstractclas)))
ah right. if .removeAll
returns nil that's what the value of your atom will be set to. atom's aren't a great fit for mutable containers. if you really want to keep using them you could do (swap! store #(doto % (.removeAll))
~/p/clojure ❯❯❯ clj
Clojure 1.10.2
user=> (def x (atom (java.util.HashMap.)))
#'user/x
user=> (swap! x #(.put % 1 2))
nil
user=> @x
nil
user=> (def x (atom (java.util.HashMap.)))
#'user/x
user=> (swap! x #(doto % (.put 1 2)))
{1 2}
user=> @x
{1 2}
user=>
put
mutates the hashmap but returns nil because mutation. i imagine your removeAll does the same
in the general case it's not safe to put mutable things inside atoms, because atoms retry operations which means something side effecting can be done multiple times
If the mutating Java methods called via swap!
are not synchronized in some other way, they can run concurrently if multiple concurrent swap!
calls are made, and they will garble the mutable state. The atom is not helping anything
it's not only pointless, it sort of suggests that things are okay, at least at a cursory glance
if all you are doing is clearing state that should be OK, but it's generally a bad design choice
when I call the method I am getting :message No matching field found: remove for class java.lang.Class
perhaps you forgot to supply the object
abstract-class is an instance of class class
you probably wanted what you had in the original: #(.removaAll % AbstractClass)
- the example @dpsutton provided left out the arg
(swap! a f x)
is the same as (swap! a #(f % x))
the middle arg becomes implicit, but you need it to become explicit again to call a method
This is more of a theoretical question. I often stumble upon operational vs. denotational, when I read articles about FP (and clojure). So maybe someone with a better understanding can tell me, if I am on the correct path. Clojure is based on small step structural operational semantics. That means I can get the meaning of a programm by looking at all the underlying functions and the sum of its parts makes the thing a thing. Haskel is denotational (?) and that means, that I get a function and a function has a meaning by itself. "make fibonacci number x" is just that, no looking at the smaller parts. I don't really get the difference? When I write a procedural python programm, I can get the meaning as well, when I look at the tiniest parts of it. is that an operational semantic now? Or is this more based on the inner structure of the program, as python is line by line and clojure is a list of list of list of list? What is Haskel then? just a word, don't look further?
@christiaaan if that is true, the domain of a python program is always python's internal state machinery
in haskell, you can specify some new semantics (usually something close to how math would represent a problem, or attempting to be that)
you can't do that in python - there's no context or use case where the meaning of the program is constituted by anything but the rules of the language itself - there's no condition that allow an abstraction that doesn't leak
@christiaaan perhaps to make it even more clear: if you look at your CPU's machine operations as transitions of a state machine, all programs that are executable are "pure"
the problem is that you can't write any program in an assembler that ignores that state machine
if haskell were 100% pure, you actually could confidently ignore how it was implemented while implementing your own code (in practice there's plenty of gotchas, but it's less leaky than other languages)
in clojure we can have a Long and a Double as two distinct things
in machine code there's no such thing - there's memory and it goes in a register
(the opcode using that register treats that memory as a Long or Double or whatever)
so in assembly you deal with misaligned data types, overflows, the fact that any given function call might totally break your data stack or dereference invalid data locations
each language that's actually worth using provides some level of simplification over the model the machine implements, and promises that the model won't randomly stop working
So you are saying there is a limit to being pure. I don't get the connection to the semantics here
and by extension, some languages provide a simpler model to build on than others
I'm saying that "purity" is a continuum, and that haskell's main goal as a language is to maximize purity
It helps me a lot to think about all the stuff I read at wikipedia, but I seme to arrive nowhere with it.
I am pretty sure that for most programming languages, it is possible to define either or both of an operational or denotational semantics. Strachey in the 1960s devised one of the first denotational semantics, and he did it for an imperative language (something like Algol of the time, but it could have been C).
I have the rough idea that you have to work a bit harder to define a denotational semantics for mutable languages, but I'm no authority on the matter.