clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
akond 2021-01-31T14:24:17.041300Z

i have

(def cli-options
	[["-i" "--input-directory DIR" "Source file directory"
	  :validate [#(fs/exists? %) "File must exist."]]])
for clojure.tools.cli/parse-opts, but i don't get any errors when there are no command line arguments. is that supposed to work this way?

borkdude 2021-01-31T14:27:22.042Z

@akond I think so. Often what happens, if no options are given, a tool decides to print help, for example. But this is on the tool.

akond 2021-01-31T14:28:32.042200Z

i see

akond 2021-01-31T14:36:49.043800Z

[["-i" "--input-directory INPUT" "Input file directory"
	  :validate [#(fs/directory? %) "Input directory must exist."]]
	 ["-o" "--output-directory OUTPUT" "Output file directory"
	  :validate [#(fs/directory? %) "Output directory must exist."]]]
strangely, if i provide -i, there is no error for missing -o. am i missing anything?

borkdude 2021-01-31T14:40:24.044600Z

@akond the parse-opts function only parses options. You can then process this information and do additional validation on combinations of required things, etc.

akond 2021-01-31T14:43:28.045700Z

it's strange, because the doc mentions "required argument", so i though it should work out of the box

borkdude 2021-01-31T14:44:52.046600Z

@akond required argument means: if you expect --args thing but the thing is missing.

✅ 1
borkdude 2021-01-31T14:45:15.047Z

unless I'm missing some feature in tools.cli I've never known about

akond 2021-01-31T14:47:37.047200Z

interesting

2021-01-31T16:30:05.047500Z

"Scheme (and Racket) effectively implement recursion as loops wherever possible. And not only that, the Scheme standard requires it. This feature, called tail call optimization (or TCO), has been around for a few decades and it is a sad commentary on the state of our programming languages that none of the modern languages support it. This is especially a problem with the JVM as newer languages have emerged trying to target the JVM as a runtime architecture. The JVM does not support it, and consequently the languages built on top of the JVM have to jump through hoops to provide some semblance of a sometimes applicable TCO. So, I always view any functional language targeting the JVM with great suspicion. It's also the reason I have not become a fan of Clojure." https://mendhekar.medium.com/why-i-still-lisp-and-you-should-too-18a2ae36bd8

Claudio Ferreira 2021-01-31T16:31:55.048200Z

Did someone here solved all the exercises at http://4clojure.com? Was it worth spending your time? Did u developed your clojure habilities?

👍 1
2021-02-01T16:24:16.067400Z

the old clojure version is intentional (the site maintainer thinks it would be unfair to past participants to introduce a clojure version that wasn't available to them) - but very little that you learn about clojure 1.4 doesn't apply to today's version

2021-02-01T16:24:50.067600Z

I learned a lot about clojure from 4clojure (though many of the answers that others submit, if you compare your answers, are written for code golf and not quality)

p-himik 2021-02-01T17:29:13.090300Z

Transducers are a significant chunk of Clojure that's missing from 4Clojure. I remember encountering some other issues where the documentation clearly states that something is possible but 4Clojure doesn't work with it - alas, I don't remember the details. @noisesmith Do you have a reference to that statement about an update being unfair (which, IMO, is not a good argument all by itself)? I know only of this comment that explains that the update hasn't been done only because of clojail: https://github.com/4clojure/4clojure/issues/303#issuecomment-509882098

2021-02-01T17:43:12.090600Z

@p-himik this is the explanation that amalloy gave when I asked about updating the version, he still hangs out on #clojure freenode IRC, though he isn't active in clojure dev any longer

👍 1
2021-02-01T17:45:03.090900Z

yeah, clojail is a hack, a modern redo of 4clojure would likely be better off using a self hosted cljs in browser

2021-02-01T17:45:52.091100Z

though that leaves an opening for exploits where a "solution" does something unexpected when run in your browser

2021-02-01T18:21:58.091300Z

I mean, if someone wanted to make http://5clojure.com , I doubt anyone at http://4clojure.com is going to complain 🙂

2021-02-01T18:29:52.091500Z

since 4clojure uses clojure 1.4, maybe we are due for 11clojure

dharrigan 2021-01-31T17:02:01.048300Z

It's my understanding that as part of Project Loom, Tail Call Elimination is on the table for implementation.

dharrigan 2021-01-31T17:02:47.048600Z

<https://wiki.openjdk.java.net/display/loom/Main>

ghadi 2021-01-31T17:09:14.048900Z

yawn

💯 1
Mike 2021-01-31T17:34:12.049500Z

Scheme is nice. Currently doing, slowly, SICP with scheme. But I don't think it's used in the industry. Whereas clojure is used, and being a JVM language surely has its advantages.

p-himik 2021-01-31T17:43:09.049700Z

Note that that website hasn't been maintained for years. Apart from just having broken links, it also uses a quite old Clojure version so some of the things you know will not be useful. And conversely, some of the things you will learn with the website will be outdated.

beders 2021-01-31T17:54:05.051600Z

Can someone stop me from doing this thing?

(defn export [var var-fn]
  (alter-meta! var assoc :doc (:doc (meta var-fn)))
  (alter-var-root var (constantly var-fn)))
This can be used for forward fns defined in some other namespace and keep the doc around.: (declare myfn) (export #'myfn #'otherns/myfn) Please stop me, it feels wrong. (vs. a much saner (defn myfn [] (otherns/myfn []) )

beders 2021-02-06T02:58:29.267400Z

thanks a lot guys

dpsutton 2021-01-31T17:55:28.052400Z

you could look at potemkin from ztellman. it has a "pull" type rather than a "push" type like you've got here. there's also a watch on each of them i believe to keep them in sync which you might like

2021-01-31T18:33:07.052700Z

Clojure lets you do manual tail call elimination using recur if you want. Using it is not built into the compiler, but as long as you know this, I have rarely seen programs where Scheme's automatic tail call optimization makes a huge difference. Seems like a pretty minor objection to Clojure to me, personally, relative to other differences, e.g. Clojure's built-in default implementations of immutable collections.

☝️ 4
2021-01-31T18:34:41.052900Z

Different people have different judgements for how important technical language differences are to them.

2021-01-31T18:37:45.053100Z

several of the exercises focus on problems like "if a function like foo did not exist in Clojure, how can you implement it using other built-in functions?", to get you to think about other ways to do it. Such exercises can result in a better understanding of how those built-in functions work under the hood, and that there is pretty much always more than one way to do things, which can be a useful mind set to have. I wouldn't call those particular exercises useful when writing production code -- in production coding situations you would use the built in functions that let you do the job in the most developer-time-effective way you know.

👍 1
2021-01-31T18:41:03.053400Z

If you like programming, and like solving "logic puzzle" types of problems, 4clojure can be interesting and you can learn a few things from it. Many people have found it useful in helping to improve their understanding of Clojure as a language beginner. The easier and medium problems can typically be solved in a short amount of time. I wouldn't say "If you haven't done 4clojure problems, you aren't a real programmer" or anything like that.

2021-01-31T21:56:59.054300Z

this is not wrong as an idea, but a bit smelly because of alter-var-root using. Have a look at this macro — https://github.com/ptaoussanis/encore/blob/master/src/taoensso/encore.cljc#L406-L431

👍 1
chepprey 2021-01-31T21:57:16.054600Z

Do Scheme/Racket feature homoiconic maps, vectors, and sets? (I know it has lists covered 😆) Are its collections immutable?

chepprey 2021-01-31T22:02:01.054800Z

I always view any functional language with non-homoiconic, mutable-by-default collections with great suspicion.

2021-01-31T23:29:24.055100Z

I am less knowledgeable about Racket, and could not answer for it, but Scheme definitely has mutable cons cells and set! .