beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
suren 2021-02-05T06:57:44.019700Z

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>))

Mno 2021-02-05T08:39:14.021200Z

<http://name.space/function|name.space/function> should work?

2021-02-05T13:02:05.024300Z

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?

javahippie 2021-02-05T13:03:42.024500Z

How did you set up your project? With leiningen or deps.edn, maybe?

2021-02-05T13:06:02.024700Z

with leinengen

lein new app dummyProject

2021-02-05T13:06:35.024900Z

as an example

2021-02-05T13:07:14.025100Z

edit your project.clj to add these lines for data.csv:

(defproject reference "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "<http://example.com/FIXME>"
  :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
            :url "<https://www.eclipse.org/legal/epl-2.0/>"}
  :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 ^^

2021-02-05T13:07:28.025300Z

then you will want to reference it in your .clj file

2021-02-05T13:09:04.025500Z

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.

2021-02-05T13:09:31.025700Z

I think you will have to restart your REPL after adding it as a dependency.

2021-02-05T13:12:37.026100Z

oh okay @qmstuart , 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 "<http://example.com/FIXME>"
  :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
            :url "<https://www.eclipse.org/legal/epl-2.0/>"}
  :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}})

2021-02-05T13:13:27.026300Z

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 references

2021-02-05T13:16:10.026500Z

If 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:

2021-02-05T13:16:17.026700Z

That is the string you want to add to your project.clj

2021-02-05T13:16:21.026900Z

under dependencies

2021-02-05T13:16:39.027100Z

For lein, it will be in that format. A vector with 2 items, the first being the dependency and the second being the version.

2021-02-05T13:23:43.027300Z

AHHHH GOTCHA! Thanks a lot @qmstuart!! 😅🙏

2021-02-05T14:31:59.033900Z

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 🙂

Fernando de Paula Carvalho 2021-02-05T15:05:02.036200Z

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"}

alexmiller 2021-02-05T15:05:59.036500Z

(apply hash-map [:a "aaa" :c "ccc"])

Fernando de Paula Carvalho 2021-02-05T16:17:26.039700Z

Thanks!! That's exactly what I need!!! Solved my problem!!! Have a nice day!

2021-02-05T16:41:07.044Z

aren't we gonna celebrate, #beginners member has reached 12k

7
2
🎉 1
Oliver Lieu 2021-02-05T16:42:37.044400Z

Hello, everybody.

👋 5
popeye 2021-02-05T17:40:56.045800Z

Team , I have below atom object like this

{&lt;input&gt; #objectcom.dinesh.AbstactModel 0xe316971 &lt;AbstactCom   
{:a "a" :b "b"} |  
["a", "b", "c"] &gt;]}

popeye 2021-02-05T17:41:33.046200Z

I want to empty the content of model

popeye 2021-02-05T17:41:38.046400Z

like

{&lt;input&gt; #objectcom.dinesh.AbstactModel 0xe316971 &lt;AbstactCom   
{} |   &gt;]}

popeye 2021-02-05T17:41:44.046600Z

how can I achieve this

dpsutton 2021-02-05T17:47:04.049200Z

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)

dpsutton 2021-02-05T17:52:24.050Z

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

dpsutton 2021-02-05T17:53:58.050100Z

classic example, a mutable java hashmap

~/p/clojure ❯❯❯ clj
Clojure 1.10.2
user=&gt; (def x (java.util.HashMap.))
#'user/x
user=&gt; x
{}
user=&gt; (.put x 1 2)
nil
user=&gt; x
{1 2}
user=&gt;

2021-02-05T17:56:23.050700Z

@popeyepwr an atom is only a container, what is an AbstactModel?

popeye 2021-02-05T17:57:38.051100Z

it is the object returned from java methd

2021-02-05T17:57:58.051300Z

why is it in an atom?

2021-02-05T17:58:24.051900Z

anyway, "object returned from a java method" describes every value possible in clojure

2021-02-05T17:58:39.052300Z

the real answer lies in understanding the object you are trying to use

popeye 2021-02-05T19:47:27.053200Z

I am calling java method on atom object

(println " ---1---" (swap! atom-name (.removeAll Abstractclas)))

popeye 2021-02-05T19:47:39.053500Z

but it is not printing anything

popeye 2021-02-05T19:47:54.054Z

Am I wrong anything here?

dpsutton 2021-02-05T19:49:01.054400Z

swap expects a function. try (swap! sstore #(.removeAl %))

popeye 2021-02-05T19:52:21.055300Z

still it is not printing

popeye 2021-02-05T19:54:02.055900Z

atleast it should return me error... it also not returning

popeye 2021-02-05T20:07:06.056200Z

How can I call java function in

popeye 2021-02-05T20:07:12.056400Z

atom?

dpsutton 2021-02-05T20:09:53.057500Z

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))

dpsutton 2021-02-05T20:09:59.057600Z

~/p/clojure ❯❯❯ clj
Clojure 1.10.2
user=&gt; (def x (atom (java.util.HashMap.)))
#'user/x
user=&gt; (swap! x #(.put % 1 2))
nil
user=&gt; @x
nil
user=&gt; (def x (atom (java.util.HashMap.)))
#'user/x
user=&gt; (swap! x #(doto % (.put 1 2)))
{1 2}
user=&gt; @x
{1 2}
user=&gt;

dpsutton 2021-02-05T20:10:23.057800Z

put mutates the hashmap but returns nil because mutation. i imagine your removeAll does the same

2021-02-05T20:16:47.058700Z

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

2021-02-05T20:17:12.059200Z

if all you are doing is clearing state that should be OK, but it's generally a bad design choice

popeye 2021-02-05T20:38:37.061Z

when I call the method I am getting :message No matching field found: remove for class java.lang.Class

popeye 2021-02-05T20:38:56.061800Z

where as I am callinh (.remove abstract-class)

popeye 2021-02-05T20:39:25.062700Z

why it is pointing to java,lang.Class ?

2021-02-05T20:39:49.063400Z

perhaps you forgot to supply the object

2021-02-05T20:39:57.063800Z

abstract-class is an instance of class class

2021-02-05T20:40:41.065400Z

you probably wanted what you had in the original: #(.removaAll % AbstractClass) - the example @dpsutton provided left out the arg

2021-02-05T20:41:16.066300Z

(swap! a f x) is the same as (swap! a #(f % x))

2021-02-05T20:41:33.067Z

the middle arg becomes implicit, but you need it to become explicit again to call a method

Christian 2021-02-05T20:42:29.068100Z

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?

2021-02-05T20:43:25.068700Z

@christiaaan if that is true, the domain of a python program is always python's internal state machinery

2021-02-05T20:43:56.069400Z

in haskell, you can specify some new semantics (usually something close to how math would represent a problem, or attempting to be that)

2021-02-05T20:44:39.070300Z

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

2021-02-05T20:45:41.071300Z

@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"

2021-02-05T20:46:06.071800Z

the problem is that you can't write any program in an assembler that ignores that state machine

2021-02-05T20:47:08.072900Z

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)

Christian 2021-02-05T20:47:51.073600Z

Does that point to overflows and such things?

2021-02-05T20:47:56.073800Z

in clojure we can have a Long and a Double as two distinct things

2021-02-05T20:48:10.074200Z

in machine code there's no such thing - there's memory and it goes in a register

2021-02-05T20:48:29.074600Z

(the opcode using that register treats that memory as a Long or Double or whatever)

2021-02-05T20:49:46.076Z

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

2021-02-05T20:50:39.076800Z

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

Christian 2021-02-05T20:51:34.077900Z

So you are saying there is a limit to being pure. I don't get the connection to the semantics here

2021-02-05T20:51:37.078Z

and by extension, some languages provide a simpler model to build on than others

2021-02-05T20:52:17.078600Z

I'm saying that "purity" is a continuum, and that haskell's main goal as a language is to maximize purity

2021-02-05T20:52:33.079Z

(sorry everyone, I think this has gone way off topic)

👍 1
Christian 2021-02-05T20:52:36.079200Z

so some people call it academic

Christian 2021-02-05T20:54:05.079700Z

It helps me a lot to think about all the stuff I read at wikipedia, but I seme to arrive nowhere with it.

caumond 2021-02-05T21:10:25.082700Z

Interesting that said