Fork me on GitHub
#beginners
<
2020-10-05
>
Chris K06:10:49

trying to use compojure, hiccup, and cljs together but while I was able to make hiccup and clojure work together, I couldn't figure out how clojurescript would work with hiccup... I don't even know very much of how clojurescript works and can anyone forward me to some resource?

yogidevbear07:10:05

There's also #clojurescript which might be a good place to ask more specific questions related to ClojureScript

Jim Newton07:10:47

does anyone know of a clojure system named genus ? I need a clever and somewhat abstract name for a package which I intend to eventually publish. I dont want to take a name that already means something to someone. Naming is hard.

Chris K07:10:07

maybe u can search it on clojure toolbox?

3
Chris K07:10:32

@jimka.issy and no I couldn't find one named genus

Jim Newton07:10:36

I did a google search for clojure and genus and didn't find anything. I didn't specifically try clojure toolbox.

Jim Newton07:10:03

my other option is compositus not sure yet.

delaguardo08:10:45

clojure libraries often follow naming convention taken from java (e.g. org.clojure/clojure) this is the way how to make your library name unique

delaguardo08:10:19

most recent version of clojure cli even start warn developers about using unqualified lib names DEPRECATED: Libs must be qualified, change clj-http => clj-http/clj-http

andy.fingerhut08:10:29

I think if people want to be squeaky clean, and/or if you ask them how in Java and Clojure land to keep library/artifact names unique, they would agree that using reverse DNS names as a group, and a separate name as an artifact, is a good idea. There certainly are a heck of a lot of Clojure libraries that haven't bothered with the reverse DNS names, of course. I suspect that has more to do with expediency and/or lack of awareness than anyone advocating for the current state.

Jim Newton08:10:23

i suppose there are really two questions hidden in my question. 1) How do I conform to the correct semantics of naming so as to avoid name clashes? and 2) how to choose a name which is colloquially distinct? as per #2, i could certainly name my library spec with the appropriate reverse dns name. However, that would not be culturally compatible with clojure social community.

Jim Newton08:10:43

A part of DNS naming which I don't understand is where does the DNS path need to come from. If I use, for example, the name of my research institute, what should have if I change employer in the future? Would I need to fork and rename? Or do I really need to create a personal DNS independent from my location, employer etc?

Jim Newton08:10:26

a personal DNS is a bit hard to justify, being that I don't even have anything at the moment to publish

andy.fingerhut08:10:45

Yeah, spec would be a poor choice, even with the reverse DNS name as a group. Google searches for "clojure genus", or whatever project name you are interested in using, is certainly one good filter, as well as asking here if you are worried about it. Very rarely, things fall through the cracks, and someone renames a project as a result. At least, I've heard of that happening for libraries in other languages.

andy.fingerhut08:10:43

Personal DNS names are about $10/year, if I recall correctly.

andy.fingerhut08:10:55

At least, the uncontested ones are.

delaguardo08:10:06

you do not need personal DNS to name your library

andy.fingerhut08:10:52

Agreed that it isn't a requirement, but neither is it a requirement to make a group id that is different than the name of the library.

delaguardo08:10:53

for instance I can use me.delaguardo as a qualifier for my libs without actually paying for http://delaguardo.me

6
Jim Newton07:10:18

that's also unfound in clojure toolbox

Chris K07:10:52

I don't no too much but I think u can change the name afterwards? not sure tho depends on how you develop it but if it is not on google or clojure-toolbox, then I think you should be fine

Chris K07:10:52

For compojure, I am trying to use jetty webserver as I've seen in practicalli's tutorial, and when I use the default compojure lein template, it uses ring server. I want to change it to jetty, can someone help me? like a code snippet would be greatly appreciated. (I tried code myself but none of them really worked)..

practicalli-johnny09:10:40

It’s for a Leiningen project, but apart from dependencies it works the same for Clojure CLI tools. Feel free to @ mention me or use the #practicalli channel for help

Chris K10:10:41

thanks a lot 😄

practicalli-johnny10:10:45

The compojure template does hide some details, I thought it did use jetty by default but the details are probably in one of the libraries its using.

practicalli-johnny11:10:18

I notice that when running lein ring uberjar to packing up a project created with lein new compojure todo-app it downloads the ring/ring-jetty-adapter library, so it seems that project its already using jetty, it just hides that fact under a few abstractions.

Chris K11:10:12

so I should basically be fine with the default condition the template is in?

practicalli-johnny12:10:04

Fine in that it is using jetty and you are happy using the lein ring xxx commands to run the server externally. I think the compojure template included wrap-reload as part of the wrap-defaults, so when running the server with lein ring server it should automatically reload any code changes that are called from the defroutes function and in the defroutes funciton itself. And if you want to package up the application, then ensure lein ring uberjar is used to generate the jar file, otherwise the jar file will not include the code that lein ring server automatically injects. I moved away from lein ring plugin a while ago, but its convenient for getting started.

Maurice Fingher08:10:40

I just installed lein, Clojure and Cursive on Windows 10 and was able to launch REPL. All right but what I'm looking for is Clojurescript with figwheel-main.

Maurice Fingher08:10:03

I tried using the template but could not install cli and lein doesn't understand "lein fig:build". Pretty sure that somebody had thesame problem, Am I right? Any clue ? Thanks.

practicalli-johnny09:10:29

This is a simple project that uses Leiningen and figwheel-main. The readme explains how the project was created and how to use it https://github.com/practicalli/practicalli-landing-page

Shriyans09:10:52

Hi ! how can i optimize my clojure code for math operations or basically find out where type information can help ?

andy.fingerhut09:10:50

One good resource for Clojure performance in general is http://clojure-goes-fast.com/

andy.fingerhut09:10:48

If you are interested in arithmetic on Clojure on the JVM and want to use Java primitive types long and/or double wherever possible, this library might be helpful: https://github.com/ztellman/primitive-math

Shriyans10:10:49

@U0CMVHBL2 ahh primitive math looks great. but this won’t work with clojurescript right ? i forgot mentioning a key detail, this code is intended to work with both clojure and clojurescript basically this is the library https://github.com/shrynx/circle-packing i intended to use it with quil (processing wrapper) on both clj and cljs, but the same algorithm when written in javascript is quite faster. is there a way to optimise for both clj and cljs @U04V15CAJ i’ll go through the link, thank you. (set! warn-on-reflection true)`` looks pretty useful and probably what i need

borkdude10:10:51

@U7W7M34UQ Also:

(set! *unchecked-math* :warn-on-boxed) 

andy.fingerhut10:10:06

I know almost nothing about trying to optimize ClojureScript or JavaScript. You could try asking in the #clojurescript channel.

littleli10:10:42

I have a piece of code represented by class, not under my control and I want to give it a deref capability, similar to how Futures are treated in core. It seems that the only way to do it is write an adapter. There is no protocol to give it such capability adhoc. Is it a correct observation?

Alex Miller (Clojure team)12:10:21

Correct, it needs to implement IDeref

👍 3
Rameez11:10:44

Hey folks! Need a little bit of beginner help with regads to sorting. I have the following structure {[2019 10] 21, [2020 9] 17} where format of each item is "[year month] amount". How best to sort this structure such that I have the latest "month" last?

Rameez11:10:03

BTW. This how I'm forming this if it helps.

Rameez11:10:13

(->> data (map #(assoc % :grouping [(:year %) (:month %)]))
       (group-by :grouping)
       (map (fn [[g t]]
              [g (->> t (map :amount) (reduce +))]))
       (into {})))

Rameez11:10:53

I'm currently looking at sorted-map for this. Am I on the right track?

vlaaad11:10:09

(group-by (juxt :year :month)) is shorter 🙂

vlaaad11:10:31

e.g. no need for the first map

Rameez11:10:08

Thanks @U47G49KHQ. Does that help with ensuring the order in the end?

vlaaad11:10:20

what do you mean having latest month last?

vlaaad11:10:27

sort by month, then by year?

vlaaad11:10:01

you can use (into (sorted-map)) instead of (into {}) to sort by keys

Rameez11:10:08

By year then month. Sorry should have been more clear 🙂

vlaaad11:10:24

so just (into (sorted-map)) then?

Rameez11:10:01

Cool tried that earlier. Didn't seem to work unfortunatly

vlaaad11:10:15

user=> (->> data 
            (group-by (juxt :year :month)) 
            (map (juxt key #(->> % val (map :amount) (reduce +)))) 
            (into (sorted-map)))
{[2019 10] 21, [2020 9] 17}

Rameez11:10:39

hmm let me try again.

Rameez16:10:50

Ah that worked! Thanks @U47G49KHQ :) appreciate the assistance.

vlaaad16:10:27

No problem :)

Jim Newton12:10:43

In a namespace named bdd I'd like to define functions and, or, not. Externally, for users of the library, they'd :`require [clojure-rte.bdd :as bdd]` and then refer to the functions as bdd/and, bdd/or, and bdd/not . The problem is that I cannot pass a qualified name to defn it requires its first argument to be a simple symbol. What is the correct way to do this?

vlaaad12:10:27

;; given
(ns foo 
  (:refer-clojure :exclude [and or]))

(def and :and)

;; then
foo/and
=> :and

✔️ 3
vlaaad12:10:00

then you’ll need to be careful in foo ns since there and and or mean different thing

3
Jim Newton12:10:42

Yes that's really tricky. currently I've named the functions bdd-and, bdd-or, and bdd-not. And externally they're referred to as bdd/bdd-and bdd/bdd-or and bdd/bdd-not which is ugly and inconsistent

Jim Newton12:10:02

how would I refer to the clojure.core/and etc from inside my bdd file?

vlaaad12:10:45

You can do (alias 'c 'clojure.core)

vlaaad12:10:22

and then you can use c/and and c/or to use clojure’s and and or

vlaaad12:10:02

this is how clojure.spec is writtern

Jim Newton12:10:27

Thanks. that example helps

Jim Newton12:10:15

OK, so now I'm getting to a part which I wrote and it works, but I really don't understand. What about this function: does the quoted and need to be c/and or just and?

(defn dnf
  "Serialize a Bdd to dnf disjunctive normal form.
  This dnf form is cleaned up so that an (and ...) or (or ...) clause contains
  no subtype/supertype pairs.  This subtype relation is determined by
  (gns/subtype? a b (constantly false)).  
  "
  [bdd]
  (letfn [(pretty-and [args]
            (cond
              (empty? args) :sigma
              (empty? (rest args)) (first args)
              :else (cons 'and args)))
          (pretty-or [args]
            (cond
              (empty? args) :empty-set
              (empty? (rest args)) (first args)
              :else (cons 'or args)))

          ...]
 ...))

Jim Newton12:10:27

I.e., I don't really understand which symbols get name-space-ized by the reader/compiler and which ones don't

Jim Newton12:10:32

It seems the system doesn't attach a namespace to a quoted and like this.

(namespace 'and)
;; => nil

Jim Newton12:10:17

BTW this is a big difference between clojure an Common Lisp which trips me up often.

delaguardo13:10:09

'and is just a symbol not a var

Jim Newton13:10:41

@U04V4KLKC can you explain to me how I can tell. I've tried to understand this, but it keeps tripping me up.

delaguardo13:10:53

' is a quotation mark in clojure reader — https://clojure.org/reference/reader#_quote it expand into (quote foo) from documentation https://clojuredocs.org/clojure.core/quote it yields unevaluated form which is a symbol foo

Jim Newton13:10:31

yes I understand that the quotation mark reads as (quote foo) that's the same as emacs lisp and Common Lisp. The difference is that Common Lisp reads the foo into a namespace regardless of the surrounding forms. The forms are constructed after the symbol is read in Common Lisp. Somehow, in clojure, the form is constructed before the namespace is assigned, or not-assigned in this case.

Jim Newton13:10:13

For example in a top level form such as the following (def xyzzy (and or not))` in clojure the and,`or`, and not all get read into a namespace. likewise (def xyzzy (and or not))` . To prevent this I have to use ~' as follows g (def xyzzy (~'and 'or 'not))` ...

Jim Newton13:10:17

perhaps my claim "read into a namespace" is wrong. I'm not sure what the reader does, but in the end result, the value xyzzy is a list containing three symbols from clojure.core in the first case, but in no namespace in the second case.

andy.fingerhut13:10:52

Syntax-quote, i.e. backquote, in Clojure by default namespace-qualifies all symbols inside of it, unless they are also explicitly namespace qualified. As you show above, that can be prevented using ~' before such symbols inside of the syntax-quote expression.

andy.fingerhut13:10:26

The Common Lisp reader interns symbols into packages and creates value cells for them at read time. Clojure's reader does not put symbols into any package or namespace.

3
andy.fingerhut13:10:55

That is, reading a symbol does not automatically create a Clojure Var.

Jim Newton13:10:24

@U0CMVHBL2 that's a good explanation.

Jim Newton13:10:57

what does "all symbols inside it mean" ?

andy.fingerhut13:10:01

I got it, or something close to it, from Rich Hickey's 2008 talk Clojure: An Introduction for Lisp Programmers, where he makes an attempt to briefly explain this difference between Clojure and Common Lisp, and why he chose to make it different than Common Lisp. You might find it useful: https://github.com/matthiasn/talk-transcripts/blob/master/Hickey_Rich/ClojureIntroForLispProgrammers.md

Jim Newton13:10:16

for example it seems that it somehow notices quote and prunes its search for symbols at that point.

`(a back quoted list of symbols in name spaces (even these in name spaces) '(but not these))

andy.fingerhut13:10:49

all symbols inside the syntax-quote, unless they are quoted with quote, would be at least one step closer to a full explanation. [edit: if anyone is following along later, this statement is incorrect -- later messages say things that are at least closer to correct]

Jim Newton13:10:31

@U0CMVHBL2 I've watched that video a couple of times when just starting out with clojure. But you're right, it might be a good idea to watch again after becoming familiar with clojure.

andy.fingerhut13:10:49

Regarding your original question about users doing :require [clojure-rte.bdd :as bdd], and then your users would refer to functions as bdd/and, bdd/or, etc., that is exactly what will happen if inside of namespace clojure-rte.bdd, you do (defn and [ ...] ...) etc.

Jim Newton13:10:08

Very interesting that the quote prunes the name spacing, but doesn't prune the ~ interpolation

(def xyzzy 100)
;; => #'clojure-rte.core/xyzzy
`(~xyzzy)
;; => (100)
`('(~xyzzy))
;; => ('(100))

andy.fingerhut13:10:06

Inside of namespace clojure-rte.bdd 's ns form, you would want to not import clojure.core's and, or, etc. which can be done with a clause like (:refer-clojure :exclude [and or not]), to avoid a warning (or error?) that your defn's for and etc. collide with the ones in clojure.core

Jim Newton13:10:11

@U0CMVHBL2 yes that's what I'm doing now. Still running tests, but followed the model in https://github.com/clojure/spec.alpha/blob/master/src/main/clojure/clojure/spec/alpha.clj#L9-L22 suggested by @U47G49KHQ

andy.fingerhut13:10:14

After doing such a :refer-clojure clause, you can still explicitly name the and in ns clojure.core using clojure.core/and, if you need to use it from inside of a namespace that has done (:refer-clojure :exclude [and])

✔️ 3
andy.fingerhut14:10:17

Regarding your comment: "Very interesting that the quote prunes the name spacing, but doesn't prune the `~` interpolation", syntax-quote is a read-time construct, as is replacing `'expr` with `(quote expr)`. `~` also performs its effect at read time.

andy.fingerhut14:10:52

Probably "performs its effect" is a poor choice of words there -- I do not mean in the sense of mutating a thing / side effects vs. pure function.

✔️ 3
Jim Newton14:10:02

Actually, I still get different results again that I expect. Apparently the quote DOES NOT prune name spacing.

(first `('(and ~xyzzy or )))
;; => '(clojure.core/and 100 clojure.core/or)
(second (first `('(and ~xyzzy or ))))
;; => (clojure.core/and 100 clojure.core/or)
why do and and or get namespaces here?

andy.fingerhut14:10:10

My apologies, I probably said some things that were incorrect earlier. I don't do syntax-quote terribly often, and so neglected to remind myself some of the details before speaking as if I did remember.

andy.fingerhut14:10:02

user=> (def x 5)
#'user/x
user=> `(and x or)
(clojure.core/and user/x clojure.core/or)
user=> `(and ~x or)
(clojure.core/and 5 clojure.core/or)
user=> `(~'and ~x or)
(and 5 clojure.core/or)

andy.fingerhut14:10:37

This reference is accurate: https://clojure.org/reference/reader#syntax-quote. A consequence of what it says there is that you can effectively use ~'something inside of a syntax-quoted expression to mean the same thing (I think) as 'something outside of a syntax-quoted expression.

andy.fingerhut14:10:23

If you want to see one extra intermediate step that is not shown above, which is what the reader reads for a syntax-quoted expression, without Clojure's eval involved, put (quote ...) around the syntax-quoted expression at the REPL, or precede it with a ', e.g.

andy.fingerhut14:10:36

user=> (def x 5)
#'user/x
user=> `(and x or)
(clojure.core/and user/x clojure.core/or)
user=> `(and ~x or)
(clojure.core/and 5 clojure.core/or)
user=> `(~'and ~x or)
(and 5 clojure.core/or)
user=> '`(~'and ~x or)
(clojure.core/seq (clojure.core/concat (clojure.core/list (quote and)) (clojure.core/list x) (clojure.core/list (quote clojure.core/or))))

andy.fingerhut14:10:21

The last output is the result of only reading the syntax-quoted expression. The one just before that is the result of calling eval on the last output.

andy.fingerhut14:10:46

And yes, the output from just the reader can be long and nasty-looking.

Jim Newton14:10:18

So my claim earlier was wrong:

`(a back quoted list of symbols in name spaces (even these in name spaces) '(but not these)) ;; this is wrong
should be the following
`(a back quoted list of symbols in name spaces (even these in name spaces) '(and even these))

Jim Newton14:10:27

@U0CMVHBL2 so according to your last experiment, the reader DID put the symbols into namespaces. notice the clojure.core/list and clojure.core/or . it's just that reading a backquote effects/modifies/changes/modalizes the behaviour of the reader.

andy.fingerhut14:10:23

It did fully qualify the symbols with namespaces. It did not intern them into those namespaces, nor create Vars, as a side effect of reading.

andy.fingerhut14:10:11

Clojure symbols, fully qualified with a namespace or not, do not automatically have mutable state associated with them, as they do in Common Lisp.

Jim Newton14:10:14

and the reader knew to fully qualify some of the symbols but not all of them.

andy.fingerhut14:10:16

But yes, if you want to avoid a symbol becoming fully qualified within a syntax-quote expression, one way is to prefix it with ~'some-symbol

Jim Newton14:10:50

is it simply the quote followed by a symbol which tells the reader to not qualify, or it is more subtle than that?

andy.fingerhut14:10:35

It is the ~ unquote that at least approximately means "for the following sub-expression, stop syntax-quoting"

andy.fingerhut14:10:10

You can follow the ~ with something like x, and then x will be read without becoming fully-qualified by the reader, but that x will be eval'd if you then eval the read result.

Jim Newton14:10:11

it seems you are right the only and which doesn't get namespace-iced is the one after the tilde.

'`(and ~'and 'and '(and) (and) ('and))
;; =>
(clojure.core/seq
 (clojure.core/concat
  (clojure.core/list 'clojure.core/and)
  (clojure.core/list 'and)
  (clojure.core/list
   (clojure.core/seq
    (clojure.core/concat
     (clojure.core/list 'quote)
     (clojure.core/list 'clojure.core/and))))
  (clojure.core/list
   (clojure.core/seq
    (clojure.core/concat
     (clojure.core/list 'quote)
     (clojure.core/list
      (clojure.core/seq
       (clojure.core/concat
        (clojure.core/list 'clojure.core/and)))))))
  (clojure.core/list
   (clojure.core/seq
    (clojure.core/concat (clojure.core/list 'clojure.core/and))))
  (clojure.core/list
   (clojure.core/seq
    (clojure.core/concat
     (clojure.core/list
      (clojure.core/seq
       (clojure.core/concat
        (clojure.core/list 'quote)
        (clojure.core/list 'clojure.core/and)))))))))

andy.fingerhut14:10:43

It gets even harder to keep straight if you nest syntax-quoted expressions within each other, which I highly anti-recommend 🙂

andy.fingerhut14:10:52

Note that syntax-quoting is intended to be a convenience, most often when writing simple macros. You could remove syntax-quote from Clojure entirely, and still be able to write every macro that can be written today, albeit with more code.

andy.fingerhut15:10:05

e.g. the kind of code you see in your most recent comment above.

Jim Newton15:10:42

Yes, I think you are right. in clojure, backquote has been optimised for macros, thus unfortunately pessimizing it for non-macro use.

Jim Newton15:10:47

in Common Lisp it can equally usefully be used to construct lists by interpolation and splicing.

Jim Newton15:10:26

anyway, it seems the comment by @U04V4KLKC was not actually correct. Or did I misread it claiming it was related to the quote. It's actually related to the tilde.

andy.fingerhut15:10:09

I certainly made an incorrect comment earlier, related to that. Not sure which statement by delaguardo you are referring to.

Jim Newton15:10:34

besides, even if the behaviour is pessimized for list interpolation, it is still good to better understand the semantics

andy.fingerhut15:10:46

I am not clear why you say Clojure's syntax-quote is pessimized for non-macro use, but if it is because of the fully-qualifying symbols, then no argument that is a significant difference between Clojure's and Common Lisp's syntax quote, by design.

andy.fingerhut15:10:48

Certainly outside of syntax quote those statements are true. The first is true inside of syntax quote, too.

andy.fingerhut15:10:00

The second expansion from 'foo to (quote foo) is true inside of syntax-quote, but inside of syntax-quote, the syntax-quote processing can still descend into foo at read time.

Jim Newton15:10:36

Clearly macro use is by far the most common case of backquote, even in Common Lisp. So perhaps Clojure's decision to optimise for that is not such a bad decision. However, what I mean by the comment is that in CL I can use backquote to create list as if by normal quote, but just interpolate data into the otherwise quoted list using the , and ,@ (in clojure that's and @). Otherwise the behaviour of single quote and backquote are much the same. Another difference is that backquote is run-time allocating and normal quote is compile-time allocating.

andy.fingerhut15:10:24

It might be true that the only way to stop syntax quote from mucking with things is to preceded the subexpression that one wants to avoid its special behavior with ~ or ~@

Jim Newton15:10:18

in time I'll get used to ~'.

andy.fingerhut15:10:35

If it helps understand it at all (you probably already realize this), ~' has no special meaning apart from their separate meanings as ~ followed by '.

Jim Newton15:10:08

it is bizarre though that single quoted data inside a backquote has much different semantics than single quoted data outside the backquote.

(defmacro foo [x] `(~x '(and or not)))
vs
(defmacro foo [x] (list x '(and or not)))

andy.fingerhut15:10:23

Common Lisp also often requires one to make a clear distinction between read time, compile time, evaluation time, etc. This is an example where in Clojure it helps to make a clear distinction between them.

andy.fingerhut15:10:07

' prevents eval from evaluating. It doesn't stop syntax-quote from doing its read-time thing.

andy.fingerhut15:10:19

I think you can view the semantics of quote as identical in those two cases, as long as you define what ~ and ' and syntax-quote do at read time.

Jim Newton15:10:42

ah ha, just that the ~ prevents the reader from name spacing the symbols

Jim Newton15:10:45

it would be nice to have a non-namespacing backquote. 😞

Jim Newton15:10:16

I think that is something the application programmer cannot write himself. as it would require an enhancement to the parser

andy.fingerhut15:10:06

Agreed that adding such a feature would require modifying Clojure's reader implementation, written in Java.

andy.fingerhut15:10:49

And in case you are wondering, the developers of Clojure probably wouldn't want anything like that in the official Clojure release. I haven't asked them that particular question -- just my educated guess.

Jim Newton15:10:58

you're probably right, and it's a shame because interpolating lists is powerful.

Jim Newton15:10:25

BTW is there a syntax for a non-namespaced symbol? to distinguish it from a symbol whose namespace is implicit?

andy.fingerhut15:10:14

A symbol either has a namespace, or it doesn't.

Jim Newton15:10:28

exactly, but if you use the syntax such as abc/xyz it refers to a symbol in a particular namespace. and if *ns* is abc and that namespace already contains the symbol xyz, then typing xyz at the prompt refers to that symbol. So I can specify which namespace I want, but I cannot specify that I want no namespace. If I understand correctly

andy.fingerhut15:10:40

syntax-quote adds a namespace at read time to most symbols inside of it, unless unquoted.

andy.fingerhut15:10:42

resolve takes a symbol, which might have no namespace, a namespace alias, or a fully qualified namespace, and figures out which fully qualified namespace it should refer to, but resolve is not called on symbols when used only as data (i.e. when the symbol is not used in code).

andy.fingerhut15:10:37

Outside of syntax-quote, and when used as data that is not compiled, symbol abc/xyz is the symbol abc/xyz, with no changes.

Jim Newton15:10:26

oh really, abc/xyz is the symbol whose print-name has 7 characters? I wouldn't have guessed that

andy.fingerhut15:10:14

user=> (require '[ :as io])
nil
user=> io/resource
#object[$resource 0x736caf7a "$resource@736caf7a"]
user=> (println 'io/resource)
io/resource
nil

andy.fingerhut15:10:36

The last occurrence of io/resource is just data, with no reason to resolve it.

Jim Newton15:10:20

but the namespace function says its namespace is "io"

andy.fingerhut15:10:12

There are calls you can make to ask for its 'namespace' part and its 'name' part, but that doesn't imply that there is a namespace named io

andy.fingerhut15:10:27

namespace and name are just getters for those two parts of a symbol.

Jim Newton15:10:37

now anyone must admit that that is confusing, if namespace can return the name of a non-existent namespace.

Jim Newton15:10:09

especially if the symbol has a slot for namespace-name rather than a slot for namespace.

andy.fingerhut15:10:55

I agree it can be confusing.

Jim Newton16:10:43

doesn't sound very rich-like.

andy.fingerhut17:10:53

Rich has been on record as saying something that I will paraphrase here, because I do not have a quote handy at the moment: It is OK to design programming languages intended for expert users, even if sometimes that means they are more difficult to learn.

oly13:10:28

anyone know how to run codox from deps.edn clojure command line ?

Max Rothman16:10:20

What’s the idiomatic way to map a function into a nested collection? For example, in Haskell I’d do:

=> (map . map) (+ 1) [[1, 2], [3, 4]]
[[2, 3], [4, 5]]
The best I could come up with in clojure was:
user=> (((comp #(partial map %) #(partial map %)) inc) [[1 2][3 4]])
but that seems pretty ugly

schmee16:10:13

I reach for Specter for these kind of things: (transform [ALL ALL] your-fn your-coll)

Alex Miller (Clojure team)17:10:26

clojure.walk/post-replace is probably the best core option

Max Rothman17:10:22

How would you use that to apply a function to every element? AFAICT postwalk-replace only does value replacements

Alex Miller (Clojure team)17:10:13

oh, you might need postwalk if you're applying a function, sorry if that's what you were asking

Alex Miller (Clojure team)17:10:15

like (clojure.walk/postwalk #(if (number? %) (inc %) %) the-data)

Max Rothman18:10:22

aha, that does it

Malik Kennedy19:10:22

http://java.io.FileNotFoundException: I thought I knew how to load project-local .clj namespaces, but the errors tell me I'm missing something. https://pastebin.com/raw/s8ZLQEaM (It was ~40 lines, IDK etiqutte about posting long posts vs pastebin)

dpsutton20:10:00

what are you doing when hitting this error?

Malik Kennedy20:10:36

lein ring server

Malik Kennedy20:10:39

Weird part to me is in REPL evaluating (auth.views.login/login-view) gives me the map I want. But running as server it claims to not know where it is, either in a ns :require or as a fully qualified ns/fn

dpsutton20:10:17

what's the entry of :source-paths in your project.clj?

seancorfield20:10:43

(GET "/login" []
	(auth.views.login/login))  
It is not good practice to reference namespaces without requiring them. Depending on the path through the code, you may end up trying to use that symbol reference before the ns it lives in has been loaded.

seancorfield20:10:16

(I didn't see auth.views.login in the :require in auth.token -- although you did omit some of that from the paste)

dpsutton20:10:18

your error message complained about looking for views/login.clj. How are you requiring that ns?

Malik Kennedy20:10:56

Required in ns declaration like so

(:require
   [auth.views.login :as login] ...) 
when I eval (ns ...) in repl I get
1. Unhandled java.io.FileNotFoundException
   Could not locate auth/views/login__init.class, auth/views/login.clj
   or auth/views/login.cljc on classpath.
whilst lein ring server errors out and points to line containing (auth.views.login/login) or (login/login)`
Syntax error (FileNotFoundException) compiling at (/tmp/form-init7302222187445651419.clj:1:73).
Could not locate auth/token__init.class, auth/token.clj or auth/token.cljc on classpath.

dpsutton20:10:52

avoid lein ringer server for now and just start a repl. then at the repl try (require '[auth.views.login :as login]) this would keep it as simple as possible. if that works you should be good to go. if not, then lein ring server will be just more machinery obscuring what is going on

dpsutton20:10:38

and can you tell me how you're starting the repl and from what directory?

Malik Kennedy20:10:33

$PROJECT_DIR/src/auth is where I'm running lein ring server and I start the repl from inside emacs daeomon with cider-jack-in

dpsutton20:10:19

run it from the root directory

dpsutton20:10:51

when using cider-jack-in did you try (at a fresh repl) (require '[auth.views.login :as login])?

Malik Kennedy20:10:16

Yes.

(require '[auth.views.login :as login])            
1. Unhandled java.io.FileNotFoundException
   Could not locate auth/views/login__init.class, auth/views/login.clj
   or auth/views/login.cljc on classpath.

Malik Kennedy20:10:31

Run at $PROJECT_DIR has no difference afaict

Could not locate auth/token__init.class, auth/token.clj or auth/token.cljc on classpath.

Full report at:
/tmp/clojure-5505124517661228879.edn
Subprocess failed (exit code: 1)

dpsutton20:10:19

the the login.clj file is located at PROJECT_ROOT/src/auth/views/login.clj?