beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
Chris K 2020-10-05T06:46:49.242500Z

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?

yogidevbear 2020-10-05T07:20:05.246700Z

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

Jim Newton 2020-10-05T06:51:55.242600Z

Thanks @andy.fingerhut for the useful commentary. I'm taking a look at all the uses of resolve in my program. There seem to be two cases. 1) where I'm trying to determine whether a given symbol names a class, and 2) where the given symbol names a type predicate such as list? . I've refactored these two cases into their own functions. find-class and callable-designator? ... this means if I discover later that I have a subtle bug in the either semantic, I can refactor it in one single place.

yogidevbear 2020-10-05T06:56:18.243200Z

Have you looked through the official reference docs and guides yet? https://clojurescript.org/reference/documentation https://clojurescript.org/guides/quick-start

Jim Newton 2020-10-05T07:00:47.244600Z

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 K 2020-10-05T07:03:07.244900Z

maybe u can search it on clojure toolbox?

1
Chris K 2020-10-05T07:03:32.245200Z

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

Jim Newton 2020-10-05T07:04:36.245700Z

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

Jim Newton 2020-10-05T07:06:03.246200Z

my other option is compositus not sure yet.

Jim Newton 2020-10-05T07:06:18.246500Z

that's also unfound in clojure toolbox

Chris K 2020-10-05T07:49:52.247800Z

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 K 2020-10-05T07:55:52.249600Z

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)..

2020-10-05T08:00:45.249700Z

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

2020-10-05T08:03:19.249900Z

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

2020-10-05T08:03:29.250100Z

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 Newton 2020-10-05T08:06:23.250500Z

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 Newton 2020-10-05T08:08:43.250700Z

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 Newton 2020-10-05T08:09:26.250900Z

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

2020-10-05T08:09:45.251100Z

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.

2020-10-05T08:10:43.251400Z

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

2020-10-05T08:10:55.251600Z

At least, the uncontested ones are.

2020-10-05T08:11:06.251800Z

you do not need personal DNS to name your library

2020-10-05T08:11:52.252Z

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.

2020-10-05T08:11:53.252200Z

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

2
Maurice Fingher 2020-10-05T08:39:40.255Z

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 Fingher 2020-10-05T08:44:03.257900Z

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.

2020-10-05T08:46:16.258100Z

https://github.com/clojure/tools.deps.alpha/wiki/clj-on-Windows for clojure cli you could try this guide and take a look at known issues here β€” https://clojure.atlassian.net/jira/software/c/projects/TDEPS/issues

2020-10-05T09:17:52.259800Z

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

2020-10-05T09:25:50.259900Z

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

2020-10-05T09:26:48.260200Z

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

practicalli-john 2020-10-05T09:47:29.262800Z

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

practicalli-john 2020-10-05T09:50:20.263800Z

Here is an example of using jetty as a web server https://practicalli.github.io/clojure-webapps/projects/leiningen/todo-app/create-a-webserver-with-ring/add-a-jetty-webserver.html

practicalli-john 2020-10-05T09:51:40.266Z

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 K 2020-10-05T10:04:41.266400Z

thanks a lot πŸ˜„

2020-10-05T10:10:49.266700Z

@andy.fingerhut 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 @borkdude i’ll go through the link, thank you. (set! warn-on-reflection true)`` looks pretty useful and probably what i need

practicalli-john 2020-10-05T10:18:45.267100Z

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.

borkdude 2020-10-05T10:24:51.268600Z

@shriyansbhatnagar Also:

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

littleli 2020-10-05T10:26:42.270700Z

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?

2020-10-05T10:57:06.271100Z

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

practicalli-john 2020-10-05T11:00:18.271300Z

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.

Rameez 2020-10-05T11:08:44.274600Z

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?

Rameez 2020-10-05T11:09:03.274700Z

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

Rameez 2020-10-05T11:09:13.274900Z

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

Rameez 2020-10-05T11:09:53.275100Z

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

vlaaad 2020-10-05T11:10:09.275300Z

(group-by (juxt :year :month)) is shorter πŸ™‚

vlaaad 2020-10-05T11:10:31.275500Z

e.g. no need for the first map

Rameez 2020-10-05T11:14:08.275800Z

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

vlaaad 2020-10-05T11:21:05.276Z

Nope πŸ˜…

vlaaad 2020-10-05T11:25:20.276200Z

what do you mean having latest month last?

vlaaad 2020-10-05T11:25:27.276400Z

sort by month, then by year?

vlaaad 2020-10-05T11:26:01.276600Z

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

Rameez 2020-10-05T11:26:08.276800Z

By year then month. Sorry should have been more clear πŸ™‚

vlaaad 2020-10-05T11:26:24.277Z

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

Rameez 2020-10-05T11:27:01.277200Z

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

vlaaad 2020-10-05T11:27:06.277400Z

how so?

vlaaad 2020-10-05T11:27:15.277600Z

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

Rameez 2020-10-05T11:27:39.277800Z

hmm let me try again.

Chris K 2020-10-05T11:46:12.278100Z

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

Jim Newton 2020-10-05T12:02:43.281Z

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?

vlaaad 2020-10-05T12:18:27.281100Z

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

(def and :and)

;; then
foo/and
=> :and

βœ”οΈ 1
vlaaad 2020-10-05T12:19:00.281300Z

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

1
Jim Newton 2020-10-05T12:31:42.281600Z

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 Newton 2020-10-05T12:33:02.281800Z

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

vlaaad 2020-10-05T12:35:45.282200Z

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

vlaaad 2020-10-05T12:36:22.282400Z

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

vlaaad 2020-10-05T12:37:02.282600Z

this is how clojure.spec is writtern

Jim Newton 2020-10-05T12:44:27.283300Z

Thanks. that example helps

Jim Newton 2020-10-05T12:51:15.283500Z

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)))

          ...]
 ...))

practicalli-john 2020-10-05T12:52:04.283700Z

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.

Jim Newton 2020-10-05T12:52:27.283900Z

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

alexmiller 2020-10-05T12:53:21.284700Z

Correct, it needs to implement IDeref

πŸ‘ 1
Jim Newton 2020-10-05T12:53:32.284900Z

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

(namespace 'and)
;; => nil

Jim Newton 2020-10-05T12:54:17.285100Z

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

2020-10-05T13:08:09.285300Z

'and is just a symbol not a var

Jim Newton 2020-10-05T13:12:41.285500Z

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

2020-10-05T13:18:53.285700Z

' 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 Newton 2020-10-05T13:35:31.285900Z

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 Newton 2020-10-05T13:39:13.286100Z

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 Newton 2020-10-05T13:40:17.286300Z

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.

2020-10-05T13:45:52.286600Z

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.

2020-10-05T13:46:26.286800Z

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.

1
2020-10-05T13:46:55.287100Z

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

Jim Newton 2020-10-05T13:47:24.287300Z

@andy.fingerhut that's a good explanation.

Jim Newton 2020-10-05T13:47:57.287500Z

what does "all symbols inside it mean" ?

2020-10-05T13:49:01.287700Z

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 Newton 2020-10-05T13:49:16.288200Z

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))

2020-10-05T13:49:49.288400Z

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 Newton 2020-10-05T13:50:31.288700Z

@andy.fingerhut 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.

2020-10-05T13:52:49.288900Z

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 Newton 2020-10-05T13:53:08.289100Z

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))

oly 2020-10-05T13:54:28.289700Z

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

2020-10-05T13:56:06.289800Z

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 Newton 2020-10-05T13:57:11.290Z

@andy.fingerhut 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 @vlaaad

2020-10-05T13:57:14.290200Z

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])

βœ”οΈ 1
2020-10-05T14:03:17.290600Z

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.

2020-10-05T14:04:52.290800Z

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.

βœ”οΈ 1
Jim Newton 2020-10-05T14:07:02.291Z

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?

2020-10-05T14:33:10.291400Z

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.

2020-10-05T14:34:02.291600Z

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)

2020-10-05T14:37:37.291800Z

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.

2020-10-05T14:39:23.292Z

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.

2020-10-05T14:39:36.292200Z

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))))

2020-10-05T14:40:21.292400Z

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.

2020-10-05T14:40:46.292600Z

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

Jim Newton 2020-10-05T14:42:18.292800Z

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 Newton 2020-10-05T14:48:27.293200Z

@andy.fingerhut 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.

2020-10-05T14:49:23.293500Z

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.

2020-10-05T14:50:11.293700Z

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 Newton 2020-10-05T14:51:14.293900Z

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

2020-10-05T14:51:16.294100Z

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 Newton 2020-10-05T14:51:50.294300Z

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

2020-10-05T14:52:35.294500Z

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

2020-10-05T14:54:10.294700Z

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 Newton 2020-10-05T14:54:11.294900Z

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)))))))))

2020-10-05T14:56:43.295100Z

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

2020-10-05T14:59:52.295300Z

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.

2020-10-05T15:01:05.295500Z

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

Jim Newton 2020-10-05T15:14:42.295900Z

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

Jim Newton 2020-10-05T15:15:47.296100Z

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

Jim Newton 2020-10-05T15:16:26.296400Z

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

2020-10-05T15:18:09.296600Z

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

Jim Newton 2020-10-05T15:18:34.296800Z

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

2020-10-05T15:19:46.297Z

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.

2020-10-05T15:20:48.297500Z

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

2020-10-05T15:22:00.297700Z

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 Newton 2020-10-05T15:22:36.297900Z

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.

2020-10-05T15:23:24.298100Z

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 Newton 2020-10-05T15:24:18.298300Z

in time I'll get used to ~'.

2020-10-05T15:26:35.298500Z

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 Newton 2020-10-05T15:27:08.298700Z

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)))

2020-10-05T15:28:23.298900Z

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.

2020-10-05T15:30:07.299100Z

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

2020-10-05T15:30:19.299300Z

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 Newton 2020-10-05T15:32:42.299500Z

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

Jim Newton 2020-10-05T15:32:45.299700Z

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

Jim Newton 2020-10-05T15:33:16.300Z

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

2020-10-05T15:34:06.300300Z

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

Jim Newton 2020-10-05T15:38:21.300500Z

aaakkkkk

2020-10-05T15:39:49.300700Z

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 Newton 2020-10-05T15:43:58.300900Z

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

Jim Newton 2020-10-05T15:44:25.301100Z

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

2020-10-05T15:45:14.301300Z

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

Jim Newton 2020-10-05T15:47:28.301500Z

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

2020-10-05T15:47:40.301700Z

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

2020-10-05T15:47:42.301900Z

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).

2020-10-05T15:48:37.302100Z

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 Newton 2020-10-05T15:49:26.302300Z

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

2020-10-05T15:50:14.302500Z

user=&gt; (require '[<http://clojure.java.io|clojure.java.io> :as io])
nil
user=&gt; io/resource
#object[<http://clojure.java.io|clojure.java.io>$resource 0x736caf7a "<http://clojure.java.io|clojure.java.io>$resource@736caf7a"]
user=&gt; (println 'io/resource)
io/resource
nil

2020-10-05T15:50:36.302700Z

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

Jim Newton 2020-10-05T15:51:20.302900Z

but the namespace function says its namespace is "io"

2020-10-05T15:52:12.303100Z

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

2020-10-05T15:52:27.303300Z

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

Jim Newton 2020-10-05T15:55:37.303900Z

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

Jim Newton 2020-10-05T15:57:09.304100Z

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

2020-10-05T15:58:55.304300Z

I agree it can be confusing.

Jim Newton 2020-10-05T16:03:43.304500Z

doesn't sound very rich-like.

Rameez 2020-10-05T16:20:50.305300Z

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

vlaaad 2020-10-05T16:22:27.305500Z

No problem :)

Max Rothman 2020-10-05T16:46:20.308500Z

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

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

schmee 2020-10-05T16:48:13.309100Z

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

schmee 2020-10-05T16:48:16.309300Z

https://github.com/redplanetlabs/specter

alexmiller 2020-10-05T17:00:26.309700Z

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

2020-10-05T17:03:53.309800Z

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.

Max Rothman 2020-10-05T17:05:22.310100Z

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

2020-10-05T17:06:05.310300Z

If you want actual quotes of things he said, he goes into that in this talk: https://github.com/matthiasn/talk-transcripts/blob/master/Hickey_Rich/DesignCompositionPerformance-mostly-text.md

alexmiller 2020-10-05T17:09:31.310700Z

it walks every element

alexmiller 2020-10-05T17:09:40.310900Z

that's the whole point

alexmiller 2020-10-05T17:11:13.311100Z

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

alexmiller 2020-10-05T17:12:15.311300Z

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

Max Rothman 2020-10-05T18:44:22.312500Z

aha, that does it

Malik Kennedy 2020-10-05T19:45:22.314200Z

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)

dpsutton 2020-10-05T20:03:00.314600Z

what are you doing when hitting this error?

Malik Kennedy 2020-10-05T20:06:36.314800Z

lein ring server

Malik Kennedy 2020-10-05T20:07:39.315900Z

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

dpsutton 2020-10-05T20:08:17.316200Z

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

Malik Kennedy 2020-10-05T20:08:35.316400Z

Not present

seancorfield 2020-10-05T20:09:43.317600Z

(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.

seancorfield 2020-10-05T20:10:16.318800Z

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

dpsutton 2020-10-05T20:10:18.318900Z

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

Malik Kennedy 2020-10-05T20:14:56.322300Z

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.

dpsutton 2020-10-05T20:17:52.323700Z

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

dpsutton 2020-10-05T20:19:38.324Z

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

Malik Kennedy 2020-10-05T20:20:33.324900Z

$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

dpsutton 2020-10-05T20:21:19.325200Z

run it from the root directory

dpsutton 2020-10-05T20:21:51.325900Z

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

Malik Kennedy 2020-10-05T20:22:16.326100Z

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 Kennedy 2020-10-05T20:23:31.327200Z

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)

dpsutton 2020-10-05T20:27:19.327800Z

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

Malik Kennedy 2020-10-05T20:42:32.328800Z

yes exactly

dpsutton 2020-10-05T20:50:46.329Z

is this public?

Malik Kennedy 2020-10-05T20:51:04.329200Z

I will make it so, brb

Malik Kennedy 2020-10-05T21:06:03.329900Z

Uhh... In an effort to extract out the contentious parts I accidently fixed it. Dunno how. Thanks so much though!\

dpsutton 2020-10-05T21:07:21.330100Z

that's a good description of debugging

πŸ‘ 1