Fork me on GitHub
#beginners
<
2021-01-07
>
hiredman00:01:49

no, I doubt anyone is using logic programming for that, I don't think it is a good fit

hiredman00:01:50

it sounds like you want to model a process over time, which, I think the gold standard for is still a finite state machine

hiredman00:01:06

e.g. if you are in state S0 you can do E1, E2, or E3, if you do E1 or E2 you move to state S1 where you can do E4, and if you do E3 you move to S2 where you can do E5 or E6, etc

hiredman00:01:59

what are describing is very similar to something like session types as well, which are usually built on a fsm

hiredman00:01:29

one way to describe that kind of thing would be for each state give a set of valid json-schemas, and what state to transition to given a schema match

hiredman00:01:40

ubf's schema language is kind of an example of that, but doesn't use json schema (https://ubf.github.io/ubf/ubf-user-guide.en.html)

dgb2300:01:44

Right. I’m half embarrassed that I never thought of this. I use FSMs for all sorts of things in GUIs already….

dgb2300:01:16

A visualized FSM would be super easy to communicate with as well

hiredman00:01:29

I dunno, specifying process behavior vs. just specifying messages processes exchange still seems very bleeding edge.

hiredman00:01:37

it is an area of interest, but I haven't seen a lot of it used in practice

hiredman00:01:09

I think maybe because most exposed public apis tend to be "stateless" rest things

dgb2300:01:36

fulcro has a story about state machines, but I didn’t find the time to study the framework in full so far

dgb2300:01:44

(a UI framework for clojure)

hiredman00:01:31

once you have a finite state machine as data, that is a kind of relational thing, so there might be interesting things you can do querying the fsm with something like core.logic

dgb2300:01:36

Dammit I wanted so sleep early tonight. But thanks a lot @hiredman!❤️

zackteo01:01:21

Hi Everyone, I've been trying to look for a good way to parse KML (XML for GIS) into dataframe format or to export as a CSV Am considering on making my own library for this. I understand there is data.zip and data.xml. Are there any good examples for the usage of these libraries? And does making my own library to do this make sense? Or is the best/own way to make use of data.xml/zip and modify it accordingly to parameters of the kml?

raspasov02:01:14

Converting XML to CSV is very straightforward in Clojure, you can definitely use existing libraries. About “dataframes”: in Clojure those are generally unnecessary as the language itself provides plenty of simple abstractions to process data that exceeds available memory. But if you need to interop with other tools that require them, then that’s another case. Curious to know more details and we can discuss further.

zackteo02:01:12

Hmmm am doing a data science project with my friends. And for their sake am trying to convert KML into CSV so it is easily for them to manipulate it from there. (They are using python.) Usually people use a command line tool called ogr2ogr for this. But the description (one of the columns) is left as an xml string. Was trying to see if I can do the processing for them within clojyee

raspasov02:01:57

Do you have an example of the XML you’re trying to convert to CSV? Is it 2 dimensional?

zackteo02:01:28

Was using this as a test example https://data.gov.sg/dataset/dengue-cases it is a zip file with 5 datasets of the same format

zackteo02:01:42

I believe it is 2-dimensional(?)

raspasov02:01:26

(ns scratch
  (:require [clojure.data.xml :refer :all :as x])
  (:import ( StringReader)))



(let [input-xml (StringReader. (slurp "/Users/raspasov/Downloads/dengue-cases/dengue-cases-central-kml.kml"))]
  (x/parse input-xml))
From here on, you can extract whatever you need from the XML data tree.

raspasov02:01:16

Via regular Clojure functions like map, filter, get-in, etc

zackteo02:01:51

I did exactly that actually. Guess I need to manually explore the data hahaha. The hierarchical nature of the xml can be quite daunting

zackteo03:01:03

Thanks for your help though :)

raspasov03:01:00

Yea… I was just looking at it, it looks messy this one, if the xml has some sort of a data spec or fields listed, that can help

zackteo03:01:04

I'm not sure if I just picked a horribly confusing dataset or if that's just kml specifications in general

zackteo03:01:27

Thats why I was considering a wrapper to skip some of that

raspasov03:01:38

Yea if there’s anything like that, perhaps worth a look; but it does look confusing (especially if it lacks explanation/specification)

raspasov03:01:57

I even see HTML tables in there! Doesn’t look very clean 🙂

zackteo03:01:02

Ahhhh okay thats html and not xml right right

zackteo03:01:28

Yeahhhh ... the government datasets are not very clean ...

raspasov04:01:04

It is XML, but there were some HTML strings I saw

zackteo08:01:46

Right the HTML is part of the specification https://docs.fileformat.com/gis/kml/

FHE06:01:08

I'm trying to follow the guide for installing Clojure CLI tools on a WSL2 Ubuntu-20.04 VM (Linux within Windows): https://clojure.org/guides/getting_started Right away I'm seeing Java, but the command sudo apt-get install openjdk-8-jre specified here for Ubuntu does not work https://openjdk.java.net/install/ Not sure what's wrong with the suggested command. May also need help with the rest of the installations.

seancorfield06:01:12

Well, Java 8 is ancient. Install 14 at least.

seancorfield06:01:20

(11 if you must)

noisesmith06:01:18

apt-get may not be there by default, newer ubuntu versions tend to use apt install

seancorfield06:01:31

I posted a link in that long thread that basically said: sudo apt install default-jdk which I would assume would install a more modern version.

seancorfield06:01:36

(personally, I go to the Adopt OpenJDK site and install specific versions from there -- and I usually have three or four JDK versions installed)

noisesmith06:01:43

also you probably don't need a full jdk (a jvm works fine until you are writing java code) and the default jvm (at one point at least) is a headless one with no gui or image processing classes included, you might not want that either

seancorfield06:01:23

Hmm, I hadn't even thought about that. I've always installed a JDK rather than a JRE for years... maybe even for decades...

noisesmith06:01:35

once upon a time it was a popular way to make a server leaner, nowadays space is cheaper haha

noisesmith06:01:20

(both using a jre rather than jdk, and using a jre that doesn't include any gui or graphics code are in that category of "optimization" I think)

FHE06:01:50

I'm sure I came across something about using Java 8. 😕

FHE06:01:58

...but if 11 is LTS then maybe OK?

seancorfield06:01:21

LTS only matters for the Oracle JVM.

seancorfield06:01:52

We use 11 on QA/production but 14 or 15 on dev. We're close to using 16 at thing point.

seancorfield06:01:08

The next (Oracle) LTS is 17.

FHE06:01:01

OK. I'll try sudo apt install default-jdk ...thought I just installed 8 on Windows a couple of weeks ago, before I knew I was going to do it all over again in Linux. lol

FHE06:01:46

Wait...will that command install the open-jdk or the oracle one?

noisesmith06:01:10

apt won't have any proprietary packages unless you configure / add them

seancorfield06:01:13

8 was EOL'd years ago, right?

FHE06:01:34

I tried installing one of the other dependencies, rlwrap, using 'sudo apt install' earlier and it did not work, by the way.

FHE06:01:38

$ rlwrap Command 'rlwrap' not found, but can be installed with: sudo apt install rlwrap $ sudo apt install rlwrap Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package rlwrap

seancorfield06:01:28

@factorhengineering are you sure you are doing this on Ubuntu 20.x?

seancorfield06:01:00

[email protected]:~/oss$ sudo apt install rlwrap
[sudo] password for seanc:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
  gvfs-bin
Use 'sudo apt autoremove' to remove it.
The following NEW packages will be installed:
  rlwrap
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 98.2 kB of archives.
After this operation, 309 kB of additional disk space will be used.
Get:1  focal/universe amd64 rlwrap amd64 0.43-1build3 [98.2 kB]
Fetched 98.2 kB in 1s (113 kB/s)
Selecting previously unselected package rlwrap.
(Reading database ... 80478 files and directories currently installed.)
Preparing to unpack .../rlwrap_0.43-1build3_amd64.deb ...
Unpacking rlwrap (0.43-1build3) ...
Setting up rlwrap (0.43-1build3) ...
update-alternatives: using /usr/bin/rlwrap to provide /usr/bin/readline-editor (readline-editor) in auto mode
Processing triggers for man-db (2.9.1-1) ...
[email protected]:~/oss$

seancorfield06:01:29

Have you done sudo apt update?

FHE06:01:19

no. I had just tried running commands for each of the 4 dependencies listed.

FHE06:01:49

Now I did that and it did a lot. 39 'Get' lines and it reports 154 things can be upgraded

FHE06:01:45

....and this time the rlwrap installation worked. I'm not sure how I ever would have guessed that.

FHE06:01:06

I mean not guessed, but found out about.

FHE06:01:22

Thank you.

seancorfield06:01:27

I dunno. It's hard to know what beginners don't know. I don't remember where I learned sudo apt update but it was a long time ago 😐

seancorfield06:01:24

I guess I thought the system told you to run that command sometimes...

FHE06:01:00

I have minimal linux command line experience. I know it uses 'ls' instead of 'dir', and I made a script once for scraping all the filenames from each of a series of inserted optical disks and appending them to a file. That's about it.

seancorfield06:01:01

At least now you should be able to install brew for Linux and then the Clojure CLI 🙂

FHE06:01:15

I'm not there yet....

seancorfield06:01:21

I started with Unix back in... 1979 I guess?

FHE06:01:43

I aborted the java install because I want to double check. This looks a bit much: $ sudo apt install default-jdk Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: at-spi2-core ca-certificates-java default-jdk-headless default-jre default-jre-headless fonts-dejavu-extra java-common libatk-bridge2.0-0 libatk-wrapper-java libatk-wrapper-java-jni libatk1.0-0 libatk1.0-data libatspi2.0-0 libavahi-client3 libavahi-common-data libavahi-common3 libcups2 libgif7 libice-dev libjpeg-turbo8 libjpeg8 liblcms2-2 libnspr4 libnss3 libpcsclite1 libpthread-stubs0-dev libsm-dev libx11-dev libxau-dev libxcb1-dev libxdmcp-dev libxt-dev openjdk-11-jdk openjdk-11-jdk-headless openjdk-11-jre openjdk-11-jre-headless x11proto-core-dev x11proto-dev xorg-sgml-doctools xtrans-dev Suggested packages: cups-common libice-doc liblcms2-utils pcscd libsm-doc libx11-doc libxcb-doc libxt-doc openjdk-11-demo openjdk-11-source visualvm libnss-mdns fonts-ipafont-gothic fonts-ipafont-mincho fonts-wqy-microhei | fonts-wqy-zenhei fonts-indic The following NEW packages will be installed: at-spi2-core ca-certificates-java default-jdk default-jdk-headless default-jre default-jre-headless fonts-dejavu-extra java-common libatk-bridge2.0-0 libatk-wrapper-java libatk-wrapper-java-jni libatk1.0-0 libatk1.0-data libatspi2.0-0 libavahi-client3 libavahi-common-data libavahi-common3 libcups2 libgif7 libice-dev libjpeg-turbo8 libjpeg8 liblcms2-2 libnspr4 libnss3 libpcsclite1 libpthread-stubs0-dev libsm-dev libx11-dev libxau-dev libxcb1-dev libxdmcp-dev libxt-dev openjdk-11-jdk openjdk-11-jdk-headless openjdk-11-jre openjdk-11-jre-headless x11proto-core-dev x11proto-dev xorg-sgml-doctools xtrans-dev 0 upgraded, 41 newly installed, 0 to remove and 0 not upgraded. Need to get 266 MB of archives. After this operation, 426 MB of additional disk space will be used. Do you want to continue? [Y/n] n Abort.

seancorfield06:01:10

Huh? Looks fine to me.

seancorfield06:01:33

You have a new system. It's missing a lot of stuff you need for development work.

FHE06:01:01

OK. Something about having multiple 'jre' and multiple 'jdk' and multiple 'headless' looked fishy.

FHE06:01:45

No great reason...just seemed excessive. Ha ha.

seancorfield06:01:50

This all looks like perfectly reasonable dependencies to me...

FHE06:01:15

I notice it's V11, by the way. Older than you were hoping for?

seancorfield06:01:09

You can install 14 or 15 later.

seancorfield06:01:47

As long as you're past 9 you're mostly fine 🙂

FHE06:01:23

The installation guide only refers to 'brew' for mac, not linux.

FHE06:01:58

Under Linux the next step it lists is: To install with the Linux script installer: 1. Ensure that the following dependencies are installed: bash, curl, rlwrap, and Java. 2. Use the linux-install script to download and run the install, which will create the executables /usr/local/bin/clj, /usr/local/bin/clojure, and the directory /usr/local/lib/clojure:

curl -O 
chmod +x linux-install-1.10.1.763.sh
sudo ./linux-install-1.10.1.763.sh

seancorfield06:01:58

So what? Once you have brew installed on Linux, you're golden.

FHE06:01:51

Why would it list two different ways if the same way can be used for both OSs? Not disputing you, just wondering why they would complicate things like that.

seancorfield06:01:11

Because they didn't think to list brew as a way to do it on Linux.

FHE06:01:48

$ sudo apt install brew Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package brew ;?

seancorfield06:01:58

The Linux instructions mean every single update is manual and you have to repeat the process for every new version.

FHE06:01:53

and I don't get what the text of step 2 means. Does it just mean run the 3 commands listed under it, or is it a separate command I'm supposed to know how to piece together from the text?

seancorfield06:01:11

What are you talking about? What's "step 2"

FHE06:01:51

"Use the linux-install script to download and run the install, which will create the executables.........

FHE06:01:02

Just curious

seancorfield06:01:09

Stop following those instructions. Read https://docs.brew.sh/Homebrew-on-Linux

FHE06:01:16

So for the brew method, I need to run:

/bin/bash -c "$(curl -fsSL )"
?

seancorfield06:01:33

What? That's not on the page I posted is it?

FHE06:01:02

From that page: "Install Instructions for a supported install of Homebrew on Linux are on the https://brew.sh."

FHE06:01:42

....then on that page: "Install Homebrew

/bin/bash -c "$(curl -fsSL )"
Paste that in a macOS Terminal or Linux shell prompt."

seancorfield06:01:30

I don't remember. I installed this stuff so long ago. Just do whatever it says.

seancorfield06:01:53

It's all a one-off. Once you're done with this, keeping stuff up to date is easy.

seancorfield06:01:21

(which is why no one remembers exactly what steps are involved -- we do this once per system and forget it!)

👍 3
FHE06:01:50

While I wait for this to install, I'm marvelling again at the sheer number of steps it takes to get going with clojure/clojurescript. At this point I'm not even letting it bother me, and just laughing at it.

pavlosmelissinos06:01:55

It's not fair to clojure to conflate different things together. WSL, brew, emacs, the linux shell in general have nothing to do with clojure in particular, they're just tools that might make you more productive with it. After all, for most of us it all builds up organically. I don't think many try to do it all at once like you did. First you become accustomed to the linux shell Then you start playing with clojure Finally you consider switching to a different editor In no particular order. This process might even span years.

☝️ 3
seancorfield07:01:27

Agreed. I started with a system that was already setup for Java development: Clojure was almost nothing on top of that.

👍 3
FHE06:01:02

Now that the effort put into setting up the VM is getting higher, I should ask: What, if anything, would cause it to be wiped?

FHE06:01:22

'exit' and 'shutdown' are safe, but is there anything to be wary of?

FHE06:01:54

Wow this is a huge installation...5 minutes and counting I think.

lassemaatta07:01:59

Let me tell you about that time when I tried installing Gentoo Linux on a 85 MHz Sparcstation 5. After 7 straight days (iirc) of compiling the bootstrap environment the hardware finally gave up 🙂

😂 3
3
FHE07:01:52

How does HW give up? Blue smoke?

lassemaatta07:01:24

I think it was the SCSI controller on the motherboard that broke. Wouldn't access the disk anymore 😢

caumond06:01:43

Honestly I did 2 full install last month. From blank system to clojurescript reframe running. It was 2 hours on mac book. Full install with word and nas setup... dont feel it heavy

FHE07:01:14

brew installed. noticed this error: Warning: /home/linuxbrew/.linuxbrew/bin is not in your PATH.

seancorfield07:01:39

@factorhengineering right, follow the instructions on the link I provided to adjust your path based on whatever shell you're using.

seancorfield07:01:26

Again, I don't remember this because it was a one-off ages ago and you never have to worry about it again.

seancorfield07:01:13

I don't think this is a "sheer number of steps" because it's just getting a bare system to a baseline that you can do anything useful with it. Neither Windows, nor macOS, nor Linux come setup to do JVM-based development.

seancorfield07:01:04

Systems aren't designed for developers, they're designed for consumers. Developers always have to go through a setup process.

FHE07:01:08

I just got through the main installation and running all the suggested commands at the end of it. (4 more commands, for installing build-essential, for setting the path suggested, and for installing gcc)

seancorfield07:01:41

When you can do clojure -Sdescribe you'll be done 🙂

FHE07:01:44

And now I've finished running

brew install clojure/tools/clojure

FHE07:01:53

I just ran 'clojure' expecting a short message describing options or something. Instead it did a bunch of downloads and I'm into what looks like a REPL

FHE07:01:59

Do I need to mess with the path, like you were mentioning?

seancorfield07:01:06

(! 532)-> clojure -Sdescribe
{:version "1.10.1.763"
 :config-files ["/usr/local/Cellar/[email protected]/1.10.1.763/deps.edn" "/Users/sean/.clojure/deps.edn" ]
 :config-user "/Users/sean/.clojure/deps.edn"
 :config-project "deps.edn"
 :install-dir "/usr/local/Cellar/[email protected]/1.10.1.763"
 :config-dir "/Users/sean/.clojure"
 :cache-dir "/Users/sean/.clojure/.cpcache"
 :force false
 :repro false
 :main-aliases ""
 :repl-aliases ""}

FHE07:01:09

...or I guess brew's defaults were fine?

seancorfield07:01:16

If that works, apparently not.

FHE07:01:43

How do I get out of the REPL? I'm sure 'exit' worked in Windows

FHE07:01:11

That would have been my 117th guess. 😕

seancorfield07:01:15

(that's end of file in everything -- except Windows where it is control-z for some bizarre reason)

seancorfield07:01:40

Windows breaks everything 😞

FHE07:01:06

I did try Ctrl-c

FHE07:01:28

Here's my Sdescribe: $ clojure -Sdescribe {:version "1.10.1.763" :config-files ["/home/linuxbrew/.linuxbrew/Cellar/clojure/1.10.1.763/deps.edn" "/home/a/.clojure/deps.edn" ] :config-user "/home/a/.clojure/deps.edn" :config-project "deps.edn" :install-dir "/home/linuxbrew/.linuxbrew/Cellar/clojure/1.10.1.763" :config-dir "/home/a/.clojure" :cache-dir "/home/a/.clojure/.cpcache" :force false :repro false :main-aliases "" :repl-aliases ""}

seancorfield07:01:01

Welcome to Clojure!

FHE07:01:26

Well, the kids will be up in 3 hours, so this seems like a good pausing point for a couple of reasons!

FHE07:01:38

Thanks again for the help, Sean et al.

seancorfield07:01:56

Glad to get you this far. Sorry it's been a painful process.

FHE07:01:07

Oh...again. Anything that would make my VM forget all this installations? ...things I should avoid?

seancorfield07:01:19

Don't worry about it.

FHE07:01:45

Ok. Will restart my computer with abandon going forward.

FHE07:01:57

Have a good night!

seancorfield07:01:58

Seriously, I've been developing this way for months, rebooting my laptop whenever it needs it. It's fine.

FHE07:01:25

I always pictures VMs as ephemeral. Shows what I know...

seancorfield07:01:31

I don't know where people get that idea?

FHE07:01:10

I think I picture a RAMdisk actually.

seancorfield07:01:59

Really? That feels so... '90s... to me 🙂

seancorfield07:01:40

(which is kinda weird since I've been doing "this" since the very early '80s)

seancorfield07:01:53

These days I just sort of expect the "cloud" to stay around until I delete it...

FHE07:01:11

A virtual reality headset comes off easily?

seancorfield07:01:28

I'm too old for VR 🙂

FHE07:01:11

and I'm never continuing a game when I put it back on? I'm always starting a new one. It would feel kind of weird to 'pause' a VR game, but maybe that's just because all the ones I have are short-burst ones.

FHE07:01:20

No no no. Try it!

FHE07:01:37

Beat Saber is amazing, fun, and good for you!! Not many other places in life you can get that deal.

seancorfield07:01:17

I'm 58. I've never played video games or computer games. Except Myst for a while.

seancorfield07:01:50

(I even bought Myst for my iPhone at one point -- such a beautiful game!)

FHE07:01:51

We'll have to talk about that another time. I haven't seen that one. Goodnight!

roelof08:01:50

then im not the oldest person here. IM 53 🙂

caumond08:01:55

I feel clojurian are older than on other language. Do we have statistics ?

caumond08:01:24

When I say older, I say wiser, experimented !!

Tim Robinson10:01:07

I'm 54. I've just started clojure and I think I'm now a better programmer than I've ever been

👍 9
👏 3
roelof10:01:21

LIke I said im 53 and tried several times clojure and I hope it will click this time

Tim Robinson10:01:20

Anyway I came here to ask a real question: in c# or JavaScript if I want to say if (widget != null && widget.InStock) I can abbreviate it to if (widget?.InStock. - c# calls it "null conditional" and js calls it "optional chaining". In clojure I'm doing (if (and widget (widget :in-stock))) . is there any shorter way of expressing that?

lispyclouds10:01:05

Maybe can do (get widget :in-stock)? works with nil.

Max Deineko11:01:46

There's also some-> and some->> .

lispyclouds11:01:03

or even (if-let [foo (get widget :in-stock)] foo-is-there foo-isnt-there)

alpox11:01:17

I believe just (if (:in-stock widget) would work too? (widget :in-stock) throws when widget is nil but the other way round you get nil on a nil map (same as with get)

lispyclouds11:01:31

yes if you just want to check the existence (:in-stock widget) would be the shortest, if you'd like to do something with the result, can use if-let. As you noticed, you cannot call a nil value, the other way is fine. using get just makes it consistent and safer 🙂

Tim Robinson11:01:42

wow thanks. As always there are several different ways of expressing the same thing 🙂 As a beginner I find I usually start by writing something that works but is bulky using the methods I know, then learn new ways to express it better

lispyclouds11:01:00

May the REPL be with you 🙏:skin-tone-3:

Pavel Klavík16:01:10

I am assuming that widget is suppose to be a map or nil. Then the following works:

(if (:in-stock widget)
 ...)

Pavel Klavík16:01:43

I am always using the form (:key m) instead of (m :key) since the latter fails when m is nil. But the former just returns nil.

Pavel Klavík16:01:09

Ok, actually posted above already 🙂 didn't notice before.

gibi17:01:35

Hi, I come from Java and I have learnt a little bit of Clojure reading “Living Clojure” book. I would like to study the web stack now, in order to get chance to be hired as Clojure dev. I was thinking to buy this book, do you think it’s a good idea? Thanks https://pragprog.com/titles/dswdcloj3/web-development-with-clojure-third-edition/

👍 3
Jorge Tovar17:01:07

Hello, there is a way un clojure to get the key looking up by the value?

alexmiller17:01:12

quickly, no. you can walk through the map entries to find a match, or use something like https://clojuredocs.org/clojure.set/map-invert to invert the map then do the lookup (probably better if you're going to do that more than once)

👍 3
noisesmith18:01:03

I bet somebody has a bimap implementation if you need to go both ways throughout the lifetime of the collection (if not guava has one https://guava.dev/releases/19.0/api/docs/com/google/common/collect/BiMap.html )

alexmiller18:01:56

Guava's is of course mutable

hiredman18:01:51

a bimap is a sign you want a structure indexed by more than one field, less like a map, more like a database

ryan echternacht19:01:38

If I have 2 lists, and want to combine them like below, what's the best way to do it?

(1 2) + (3 4) => (1 2 3 4)
The best I've found is (into (vec list-1) list-2) which seems convoluted. I don't really care about the final collection type (it's getting serialized to json) I guess I should add, for my use case, the ordering is important, and that's what Im trying to avoid spoiling

R.A. Porter19:01:34

(concat l1 l2) should give you what you want.

ryan echternacht19:01:08

thanks. i can't believe i forgot about concat. i guess i've been playing with transducers and using into too much 😕

ryan echternacht19:01:24

forgot about concat

raspasov20:01:01

(into [1 2 3] [4 5 6])

raspasov20:01:10

[1 2 3 4 5 6]

raspasov20:01:09

Into probably better than concat... assuming this still stands https://stuartsierra.com/2015/04/26/clojure-donts-concat

alexmiller20:01:14

this still stands, it's just contextual to how you're using concat. definitely something to be aware of in a loop but as a single thing, no worries

alexmiller20:01:59

concat is totally fine for the original case (and what I would prefer there)

alexmiller20:01:58

user=> (time (dotimes [_ 10000] (concat '(1 2 3) '(4 5 6))))
"Elapsed time: 1.036309 msecs"
user=> (time (dotimes [_ 10000] (into [1 2 3] [4 5 6])))
"Elapsed time: 5.810941 msecs"

alexmiller20:01:38

things to note - into uses conj and conj on lists prepends, so (into '(1 2 3) '(4 5 6)) is not the same. and secondly, the timings here depend on laziness of concat.

yiorgos20:01:06

Is there a way to print all the aliases that a project has, using Clojure cli?

seancorfield20:01:25

Since deps.edn is "just" an EDN file, you can slurp it in, run clojure.edn/read-string on it and get a hash map, and then select :aliases from that and print the keys of that.

seancorfield20:01:22

But bear in mind that any running program started from the CLI could actually have been started with any aliases from either the system deps.edn file or the user deps.edn file.

yiorgos20:01:22

Sweet, thanks!

seancorfield20:01:36

If you want to also get at the content of those, you're going to need to use tools.deps.alpha as a library to compute the full project basis. Take a look at how depstar does it: https://github.com/seancorfield/depstar/blob/develop/src/hf/depstar/uberjar.clj#L305-L328

seancorfield20:01:01

(you would only need the t/find-edn-maps and t/merge-edns parts)

yiorgos21:01:23

Thank you very much for taking the time answering all these stuff!

seancorfield21:01:46

Commas are whitespace in Clojure and the comma here just causes my editor's paren management plugin to leave the ) on that line instead of "correcting" it to the end of the line above, which makes it easier to put the cursor at the end of the form on the previous line so it is easier to eval to the REPL.

seancorfield21:01:05

Otherwise I'd have to either put my cursor at the start of the form or ensure it was placed correctly relative to what would be )) at the end of the form (to ensure the nested form was eval'd and not the enclosing comment form which would produce nil instead).

yiorgos21:01:24

Oh I see, that’s a good tip. Thanks!

Dimitar Uzunov20:01:46

hi, this is probably trivial: Its more convenient for me to evaluate (clojure.repl/doc seq?) with C-c C-c from a file/buffer than to type it in the REPL, but I only get nil in the buffer with the file and I don’t want to keep another buffer open just for the outputs (I prefer to use a single small screen right). How do you do it? Are there other users that like repl driven development but not have an actual repl buffer open all the time?

yiorgos20:01:34

I use lispy with Emacs and it shows the result of the evaluation inline

yiorgos20:01:11

I think to make it work using C-c C-c you should wrap your form in a comment form

Dimitar Uzunov20:01:58

hmm for me (comment (clojure.repl/doc seq?) )

dpsutton20:01:57

C-c C-d d will bring up the docs

parrot 6
seancorfield21:01:47

Nearly all editor integrations for Clojure provide a way to get the docs for the symbol your cursor is on, without needing to actually eval a clojure.repl/doc form.

👏 6
seancorfield21:01:22

Most editor integrations also have a similar way to get the source for a symbol.

Dimitar Uzunov21:01:37

just for reference I set Cider Prompt For Symbol to be dwim so I don’t have to confirm

dpsutton20:01:47

if you eval (source source) you'll see that it prints the source. this causes a side effect of printing and returns nil

dpsutton20:01:41

(as an aside, i love recommending (source source) or (doc doc))

Dimitar Uzunov20:01:54

sure, but the side effect is not displayed inline in cider.. maybe I should have started with that

dpsutton20:01:08

yes. output will end up in the repl. there are several commands inside the cider-doc menu. C-c C-d and then c for clojuredocs, d for the docstring, a for apropos, e for apropos documentation, j for javadoc

Dimitar Uzunov20:01:07

whoa I forgot how many features CIDER has

dpsutton20:01:24

yeah there's a ton. and they are quite nice

dpsutton20:01:33

there's also #cider for cider specific questions in the future

Dimitar Uzunov20:01:35

I really like the convert the thread-first

dpsutton20:01:40

happy to help you explore the other features

🙏 3
Dimitar Uzunov20:01:49

I have to check it out

Ralph Greaves20:01:52

Hey, gang--Ralph here! I just wanted to thank you all for providing this Slack as an avenue for those with only a few months' experience with Clojure under their belts (Me.). PS: This is my first time ever using Slack; I hope this is an alright spot to send along my personal introduction. 😅

👍 15
caumond20:01:50

You're welcome here I guess. I am pretty new here and in clojure. But it seems to be a quiet place to discuss with polite people. I must confess I did not introduce as you did ! Welcome, guys are more than helpful here !

raspasov21:01:40

Welcome! 🙂

Thomas Tay22:01:19

Hi Ralph! I too have barely 3 months of time with Clojure, and what a fun few months it's been!

Claudio Ferreira23:01:03

Hello everyone, Lets supose i have this var: (def m {:username "sally" :profile {:name "Sally Clojurian" :address {:city "Austin" :state "TX"}}}) Why when i try to evaluate the following function doesn't return "TX"? (:state (:adress (:profile m))) => nil Thanks

caumond23:01:56

Hi Maybe the mispell of adress / address ?

👍 9
caumond23:01:08

Yes I ve just copy paste in repl in case I miss something. But no, its working with good spelling

Aaron Bell00:01:26

boop.core> (def m {:username "sally" :profile {:name "Sally Clojurian" :address {:city "Austin" :state "TX"}}}

boop.core> (get-in m [:profile :address :state])
"TX"
boop.core> (:state (:address (:profile m)))
"TX"

Aaron Bell00:01:08

You have everything right except 'adress'. It's likely, as @U018QDQGZ9Q says, the spelling.

sP0re23:01:30

Hi guys! I don't know if it's the right section to write this but, I d like to learn Clojure. I'm a Java developer and I'm going to try a functional language. I had to chose between elixir and Clojure and I think that as Java Dev could have sense to try Clojure. I will start to read "Clojure for the brave and true", is it a good book to start? And what about web development (frameworks, libraries...) and the future of clojure in the industry? Thank you very much

didibus23:01:52

I heard good things about Getting Clojure, Programming Clojure and Elements of Clojure. I also think they complement each other, from what I heard. Getting Clojure is more introduction, Programming Clojure goes in more details, and Elements of Clojure is more phylosophical (design/structure of code). That said haven’t read them. I do personally recommend Clojure, The Essential Reference. It might not be best to learn Clojure at first, but once you know it somewhat, it’s great for deep diving further into every aspect of the core language. I also really recommend at some point you read through the official Clojure overview, reference and guides: https://clojure.org/about/rationale https://clojure.org/reference/reader https://clojure.org/guides/getting_started And as a super quick intro like I want to get going in 30 minutes, I recommend the following small blog series: https://aphyr.com/tags/Clojure-from-the-ground-up https://kimh.github.io/clojure-by-example/#about

👍 3
paul.legato00:01:22

Great list. I’ll add “Joy of Clojure” - one of my favorites. https://www.manning.com/books/the-joy-of-clojure-second-edition

practicalli-john01:01:25

Keep asking questions, the Clojure community is one of the biggest advantages to learning Clojure https://practicalli.github.io/blog/posts/cloure-community-getting-help/

💯 3
Rowan Barnard09:01:58

I am a beginner with Clojure and have read Getting Clojure and am much of the way through Living Clojure - both great introductory books to Clojure. I think Getting Clojure does a great job of helping you understand the 'essence' of Clojure and each of it's individual 'features'. Living Clojure is a bit out of date now - the chapter on web dev with clojurescript doesn't really work any more - that was the only chapter that hasn't worked for me though - the rest all still works and it provides you with a training program to get better at clojure programming which I thought is interesting and cool, though if you are confident you can easily build your own training program.

seancorfield23:01:51

@mircoporetti Welcome! Lots of questions there so let's try to answer them all one at a time... since you're used to the JVM, Clojure makes sense: you can even use it from your existing Java apps (we introduced Clojure at work a decade ago and initially used it as a "library" and wrote lots of new code in Clojure but used it from our legacy apps -- and gradually Clojure has taken over). That said, the mental shift from Java's OOP model, based on mutable state, to Clojure's pure immutable data can be a long haul -- so expect to get frustrated and confused and be prepared to spend quite a long time learning "functional thinking" (or, perhaps, unlearning OOP thinking)...

👍 3
seancorfield23:01:04

I think a lot of people start off with Brave/True but it may make sense for you to continue with your existing editor, if it has a good Clojure integration, rather than trying to learn Emacs (which is what Brave/True suggests). What editor/IDE are you using for Java?

sP0re08:01:55

Thanks Sean for your suggestions 🙂. I have another question. I already bought the book Brave/true and I would try to read it because it's here on my desk. Can I do it using Intellij or does this book oblige you to use Emacs? If you tell me that this book is not good to start I will sell it and I will buy Living Clojure or another. Thanks

seancorfield18:01:37

It's a perfectly good book and I'm sure you can just ignore the Emacs stuff and follow along and do the exercises in Cursive/IntelliJ. There's a #cursive channel if you need help with that.

sP0re19:01:19

Thank you! I'll start soon

seancorfield23:01:19

Clojure from the Ground Up is another online resource you might like. Good books to get started include Living Clojure and Getting Clojure. There are lots of good "second books" once you start to find your feet.

👍 3
yogidevbear08:01:26

@mircoporetti here is the link to Clojure from the Ground Up: https://aphyr.com/tags/Clojure-from-the-ground-up

👍 3
seancorfield23:01:05

As far as web development, Clojure mostly eschews frameworks in favor of composing libraries. Almost all server-side web apps are built, ultimately, on top of Ring. There are several options for routing libraries (mapping URLs to handler functions) with the most popular being Compojure and Reitit I think. For HTML page generation, folks mostly either go with Hiccup (you write your HTML as Clojure data structures and Hiccup transforms them to actual HTML text) or Selmer (you write your HTML as Django-style templates and Selmer substitutes variables and handles conditionals and loops in the templates).

👍 3
sP0re08:01:50

I would prefer to start using it only server side returning JSON like I usually do with Spring. So I imagine that exists also a library like Jackson for java?

seancorfield18:01:29

@mircoporetti org.clojure/data.json, Cheshire, jsonista are the three that come to mind. The former is pure Clojure, the latter two both wrap Jackson.

👍 3
seancorfield23:01:08

I tend to point beginners at https://github.com/seancorfield/usermanager-example as an example of a handful of simple libraries composed together to produce a small web app that uses a database and generates HTML server-side.

👍 3
seancorfield23:01:57

There's a whole separate world of front end development with ClojureScript (that I can't comment on much yet, but I'm started to learn that side now -- after using Clojure on the JVM for a decade 🙂 ).

seancorfield23:01:58

As for Clojure's future, it is and will always be a niche language. But it has seen slow, steady growth ever since its introduction and it is extremely stable, and changes are made in a very conservative, careful fashion.

practicalli-john01:01:48

I believe it has been said that C++, python, Java, JavaScript, Haskell and Julia were niche languages at different points in time Certainly languages like Java, JavaScript and C++ are used by a greater number of developers commercially. The last decade has seen more people reaching out for different languages, so it's very hard to predict the future (it seems even APL is coming back). I agree that steady adoption of Clojure has been a big advantage for the language and has lead to a supportive and welcoming community.

👍 3
didibus01:01:18

I think most languages are niche, until one of three things happen: * A killer app in the language blows up: for example Rails put Ruby on the map. Spark put Scala on the map. Numpy put Python on the map. * A large company becomes the shepherd of the language. Google most famously pushed Python and Go. Mozilla pushed Rust. Twitter pushed Scala. Microsoft pushed TypeScript. * A platform forces its use. Swift and ObjectiveC for Apple. C for linux. JavaScript for browsers. Java/Koltin for Android. C# for Windows and Unity.

practicalli-john01:01:42

All very good points. JavaScript is a particular good example. I don't think JavaScript was considered a serious language for a long time. Then jQuery came along (which still seems the most used library). Then more business got behind the language (even Microsoft) and of course every companies started using JavaScript for front end websites. Then node and mom came along... Although there are no guarantees that a language grows even with a 'killer app` or company support (i.e Dart from Google) or enviable platform changes. I am enjoying the diversity in languages we have experienced, even though it can add a burden to keep up. This diversity does encourage developers to thing differently about the software they write. This thinking is beneficial to Clojure as there are many subtle and important differences to discover

👍 3
sP0re08:01:50

and.. does Phoenix put Elixir on the map?

didibus17:01:13

Elixir seems pretty niche to me.

didibus17:01:13

StackOverFlow 2019 survey had Elixir and Clojure usage on par: Elixir 1.4% Clojure 1.4%

didibus17:01:00

I don't know how much of that small usage is driven by Phoenix or not. And maybe Phoenix could push Elixir past Clojure in the future, that's really hard to predict

sP0re19:01:29

Clear, I hope that clojure will grow on 2021, I'm waiting for official statistics

practicalli-john19:01:40

Given that most of the Clojure community uses either Zulip or Slack instead of StackOverflow, you have to wonder how representative the Stack Overflow survey is for Clojure. It would be useful to get stats from Maven central and Clojars to see how often jars are downloaded. For myself, the question is never about popularity or usage, but is the language sustainable? As far as London is concerned, Clojure is certainly sustainable in terms of jobs and community. As we've all gone online then that easily extends to the whole of the UK. And there seems to be a regular stream of new companies advertising in the jobs channel. I started looking on Tuesday for a new job and found 6 Clojure roles straight away (I may have just been lucky). There seems to be more and more communities around the world too, especially over the last few years. So Clojure is still growing. We have also seen a big boost in numbers in the London Clojurians, over 2,000 members now. There are only 7,000 in the London Java Community, so there is certainly a lot of enthusiasm for Clojure.

👍 3
seancorfield20:01:19

That's a good point about the user groups -- I was surprised to see one pop up in Provo, Utah and it's pretty active (it's done well since we all went online and it can get speakers and attendees from all over the place). I've attended that a couple of times now, and the Los Angeles group. And both San Francisco and Seattle are trying to get themselves restarted as online meetups.

didibus21:01:25

Jar downloads for clojure itself could be an interesting stat to plot. If somehow it could even unique over IPs 😅

didibus21:01:40

As for me, I agree with others, I don't really need Clojure to be more popular as long as it continues to be well maintained and supported. The ecosystem is healthy now, there's nothing really that I'm "in need of" or "missing". I have all the tooling and libraries/framework I need. And the language already has more features then I even know what to do with haha.

didibus21:01:26

The only exception I'd say is job prospects. I would like to see it grow there. The more opportunity to work in Clojure at more places on more varied applications the better chance I can use my favorite language at work for the foreseeable future.

sP0re09:01:25

Thanks guys, I will start today to read something of Brain/True. I'm happy to see that all Clojurians are enthusiastic and positive about the growth of the language. I think that it will be for me a good experience to start programming with a different approach. About jobs, we will see 🙂 I believe in functional languages and their communities

practicalli-john09:01:49

All the companies I taked to this week are looking to hire more Clojure engineers this year. Location is still somewhat a factor, although mostly due to the pandemic that location is now more about the same country or economic region rather than city. There are not the same numbers of jobs as say Java or JavaScript, but the jobs I have seen in Clojure tend to be more engaging and slightly better paid.

👍 3
seancorfield23:01:59

@mircoporetti You will also probably find this site very useful as a learning resource: https://practicalli.github.io/clojure/

seancorfield23:01:51

I think @jr0cket is also developing material about web development but I don't have a link handy for that.

practicalli-john00:01:37

All the books can be found here https://practicalli.github.io/

👍 3
seancorfield00:01:52

Ah I didn't see it as a title in that big cluster of graphics! Yes, here's the web apps link directly for @mircoporetti https://practicalli.github.io/clojure-webapps/

👍 3
practicalli-john01:01:48

I believe it has been said that C++, python, Java, JavaScript, Haskell and Julia were niche languages at different points in time Certainly languages like Java, JavaScript and C++ are used by a greater number of developers commercially. The last decade has seen more people reaching out for different languages, so it's very hard to predict the future (it seems even APL is coming back). I agree that steady adoption of Clojure has been a big advantage for the language and has lead to a supportive and welcoming community.

👍 3