Fork me on GitHub
#clojure-dev
<
2022-12-12
>
mfikes00:12:06

Perhaps this is also undefined behavior:

Clojure 1.11.1
user=> (nthnext (seq "abc") -1)
(\a \b \c)
vs.
Clojure 1.12.0-alpha1
user=> (nthnext (seq "abc") -1)
Error printing return value (StringIndexOutOfBoundsException) at java.lang.String/charAt (String.java:658).
String index out of range: -1

Alex Miller (Clojure team)00:12:03

what do you think that could even mean

Alex Miller (Clojure team)00:12:21

(so yes, that seems undefined to me)

👍 1
Alex Miller (Clojure team)00:12:48

I actually have a ticket about nthnext though for other circumstances

mfikes00:12:45

Some of these I'm finding using Coal Mine (https://github.com/mfikes/coal-mine) which usually reflects new users getting lucky with some undefined behavior, and only rarely catches regressions in core functions as they evolve.

👍 1
mfikes00:12:13

The way I'd argue nthnext makes no sense for negative arguments is that acts like a facility for applying next n times.

Noah Bogart20:12:29

My apologies if this is not the right channel for this request: Would it be possible to get a version of the install-clojure script (referenced https://clojure.org/guides/install_clojure as linux-install-1.11.1.1200.sh) that downloads a "latest" version automatically, so I don't have to go to the website and download/chmod/execute the latest version of the script?

seancorfield20:12:19

You could pull this file to get the current stable version: https://github.com/clojure/brew-install/blob/1.11.1/VERSION -- you need the branch version in there to ensure you're not going to suddenly get a different version of Clojure as the default.

Noah Bogart20:12:44

Oh that's cool

lispyclouds20:12:39

https://download.clojure.org/install/linux-install.sh should work as well i think? ive been using it for a while now

☝️ 1
seancorfield21:12:36

Oh, totally forgot about that! Thank you!

borkdude21:12:26

and there is also https://download.clojure.org/install/posix-install.sh for cross-platform *nix (mac + linux)

Noah Bogart21:12:41

oh that's great. Maybe the site should be updated to highlight it?

Noah Bogart20:12:08

My situation is that my company uses clojure from within docker, specifically leiningen, and it makes certain aspects of development much harder than necessary. I'm hoping to 1) move us to only putting our database/etc in docker while leaving clojure local, and then 2) move us to deps.edn from leiningen. The first hurdle of 1) is being able to say to the entire team: "run this script to install clojure", and then whenever there's a new release, I can ping the team and say "execute the same script you have on your machine to update automatically", instead of everyone having to perform the "download and chmod and execute" trio of steps

mfikes21:12:30

Is dropping negative numbers undefined? The reason I ask is that the IDrop interface chooses to mention this case (`If n is <= 0, return this.`), various bits of code is checking for this, etc. But the behavior goes sideways with (drop -1 {:a 1}).

Alex Miller (Clojure team)21:12:00

There’s a fix in master around this I think

mfikes21:12:16

The thinking is that drop with a negative argument would behave much like (drop 0 coll) I suppose.

Alex Miller (Clojure team)21:12:54

I’d still say dropping a negative number has no semantic meaning :)

mfikes21:12:14

One odd twist is that (drop -1 [1 2 3]) returns the vector where (drop 0 [1 2 3]) returns what looks like a list / seq

mfikes21:12:08

Yeah, I was leaning towards "it's undefined", but the IDrop stuff surrounding <= 0 made me question my thinking.

Noah Bogart21:12:22

Should it throw if given a negative number?

mfikes21:12:55

Well, it is OK if undefined behavior doesn't result in a throw... that precedent is well established.

👍 1
mfikes21:12:40

(Sometimes the desired checks catching undefined behavior are too expensive.)

mfikes22:12:52

Currently the ClojureScript port is doing what some might argue drop ing negative means : Undropping something

cljs.user=> (drop -3 {:a 1, :b 2})
([nil nil] [nil nil] [nil nil] [:a 1] [:b 2])

mfikes22:12:44

If undefined, will leave that alone. Clojure 12 alpha derails in this case. Either is OK for undefined.