Fork me on GitHub
#clojure
<
2020-08-10
>
borkdude09:08:10

Why does clojure.datafy/nav take a v(alue)? Why would I return a value, instead of just navigating into a data structure (similar to get-in)?

Jim Newton10:08:52

question about lazy sequences. tree-seq and distinct are both documented to return lazy sequences.

(let [all-nodes (distinct (tree-seq (fn [node]
                                              (not (member node '(true false))))
                                            (fn [bdd]
                                              (for [child '(:positive :negative)
                                                    :when (or draw-false-leaf
                                                              (child bdd))]
                                                (child bdd)))
                                            bdd))
              apex-node (first all-nodes)
              leaf-nodes (intersection '(true false) all-nodes)
              internal-nodes (difference all-nodes leaf-node)
              (group-by :label internal-nodes)]
           ...)
how many times is tree-seq called here? Is it called everytime someone tries to iterate across all-nodes? For example, to compute apex-node, leaf-nodes, and internal-nodes? What should I do to assure that tree-seq and distinct are called no more than once?

Jim Newton10:08:57

Is there a function like map or mapcat which does the following? (doseq [n leaf-nodes] (write-leaf n)), in common lisp the function is named mapc . it is the equivalent of map but does not construct a list of output values of the given function, rather it just returns its sequence argument.

Jim Newton13:08:07

What is the convention with README.md files in a project directory? my project has several name spaces which could conceivably be thought of as stand-alone, although their primary purpose is to support the main application. I don't really want to write a HUGE readme file which includes all the namespaces. I'd rather have the main README.md just document the high level summaries and interfaces, and have other files which the README.md links to.

Jim Newton13:08:37

I've made the mistake in the past of filling up REAME.md files with lots of relative links, but that confuses engines which like to copy the .md file elsewhere, and thus breaking the links.

Jim Newton13:08:06

- - - Completely different question: is there a way to make macros behave will with the compiler? For example, I'm writing a macro which has similar semantics to case/cond, and the macro is able to discover unreachable clauses. The macro could at this point emit a warning telling the user about the unreachable code, because presumably it is not what the user intended.

Jim Newton13:08:41

using the sbcl Common Lisp compiler, if a macro calls (warn ...) then those warnings are handled by the compiler, and correlated with the line of code which emitted the warning.

Joe Lane13:08:59

@jimka.issy You can use namespace doc strings instead of nested readme's or readme's with a table of contents. https://stuartsierra.com/2016/clojure-how-to-ns.html#docstring

Justin Roche15:08:31

Hi, does anybody know why lein repl would make my terminal prompt disappear? If I quit the repl I can't use shell commands anywhere.

dpsutton15:08:37

how are you quitting the repl?

dpsutton15:08:19

are you running the terminal in emacs?

Justin Roche15:08:25

yes in shell mode

dpsutton15:08:49

and to exit lein repl you are deleting the buffer?

Justin Roche15:08:30

yes, but after that the prompt is also missing on the OSX terminal as well as emacs shell

dpsutton15:08:06

can you reproduce this without lein? start a different program, kill the buffer and then see if you observe the same behavior?

Justin Roche15:08:13

I kill java and angular builds all the time, but it doesn't have this effect

Justin Roche15:08:59

I can check to see if it does this if I kill it with a regular terminal outside of emacs

Justin Roche15:08:30

I am using the chestnut template

andy.fingerhut15:08:05

This issue sounds like it might be fairly specific to the #emacs channel, at least as far as Clojure is concerned.

Justin Roche15:08:08

if I do it outside of emacs it still works...

Justin Roche15:08:40

ok I will ask there

vemv16:08:42

Anyone recalls a severe, surprising difference between clojure.data.json, cheshire and jsonista? Be it in encoding or decoding. e.g. anything that could cause a production issue, maybe a subtle one. Doing some quick testing I found that c.d.j doesn't support types such as dates/bytes/chars (at least OOTB), and also that it drops the namespace out of qualified keywords. Other than that they seemed equivalent (which I checked by piggy backing into cheshire and jsonista unit tests), although I have yet to code a comprehensive test

Jim Newton16:08:30

what is the correct way to print the content of a lazy seq? format %s prints something like clojure.lang.LazySeq@f105783a

noisesmith16:08:16

@jimka.issy use pr-str inside other things that expect strings, or prn itself if the lazy seq is the only thing ot print

noisesmith16:08:35

so (format "%s" (pr-str ls)) or (prn ls)

noisesmith16:08:34

in general, pr-str and prn give you the output you'd expect at the repl, which uses the same code by default

Jim Newton16:08:54

Hm, interesting if you use cl-format rather than format, the contents of the sequence are printed 🙂

Jim Newton16:08:24

(cl-format false "label ~A appears ~D times in transitions of ~A: transitions=~A"
           label freq q (:transitions q))

Jim Newton16:08:42

~A means print aesthetically

noisesmith16:08:05

I'd be surprised if the formatter for ~A wasn't calling pr-str, or some of the same implementation code pr-str uses

Jim Newton16:08:36

~A is sort of a do-what-i-mean printer.