Fork me on GitHub
#clojurescript
<
2018-10-16
>
rplevy00:10:02

Odd bug in the reader in [org.clojure/clojurescript "1.10.339"]

(rdr/read-string "01") ; valid
...
(rdr/read-string "07") ; valid
(rdr/read-string "08") ; error
(rdr/read-string "09") ; error

rplevy00:10:55

only "08" and "09" cause an invalid number error

rplevy00:10:38

that rdr is cljs.reader

rplevy00:10:59

And as expected I see this also when entering 08 or 09 vs 01 etc in the cljs repl

rplevy00:10:55

I've narrowed it down to cljs.tools.reader.impl.commons/match-number

cljs.tools.reader.impl.commons=> (match-number "09")
nil
cljs.tools.reader.impl.commons=> (match-number "07")
7

thheller00:10:57

@rplevy not a bug, same behaviour in clj. number starting with 0 is read as octal

rplevy00:10:13

oh! interesting

rplevy00:10:18

I never new that

rplevy17:10:53

I wonder why the choice was made to support both the ^0 (eg. 023) and ^Nr (eg. 8r23) convention for octal? It seems like the general Nr one would have been enough.

andy.fingerhut18:10:48

Octal with a leading 0 is a common syntactic convention in many programming languages, e.g. C/C++, probably Java, too. The "<number>r" notation in Clojure lets you specify any base from 2 up to 36. Once you have that, it would be weird to leave out bases 8 and 16 as exceptions

rplevy18:10:02

It wouldn't make sense to leave them out from the generalized one, but it maybe would have made sense to not include the specialized one.

rplevy18:10:12

Too late now of course.

andy.fingerhut18:10:25

Leading '0' for octal, and leading '0x' for hex, are very common in many programming languages.

andy.fingerhut18:10:51

I mean, a the very base, it is Rich's language, and we get to use it, so all "why" questions are really not anyone else's to answer. Just giving my perspective on why he probably chose to keep the leading 0 syntax for octal -- common usage.

rplevy18:10:18

You're right about it being common, of course that is not the most compelling argument in favor of it. I'm more sympathetic to 0x.

rplevy18:10:54

I think you're going too far with bowing to Rich there, I don't think Rich would even want that level of deference.

andy.fingerhut18:10:34

I'm not bowing (although I do thank him mightily for creating Clojure). Just explaining that if you ask "why" for a human-designed thing, the authoritative answer is the one who created it.

rplevy18:10:51

I think Rich usually has a good reason for what he does, but you as a user should ask why and understand. You are doing no one any favors by being against asking why.

andy.fingerhut18:10:39

I don't know how you got that I am against asking why. I am 110% for asking why. The best answers I can give you for your "why" question are "here is my guess as to why".

šŸ‘ 4
rplevy18:10:46

If you can't articulate why decisions make sense, and be realistic about where Clojure has made trade-offs, then you'll just look like a zealot to potential new users evaluating potential use.

rplevy18:10:58

Ok, maybe I misunderstood when you invoked Rich Hickey's argument against entitlement, that it's Rich's language, and questions about why are questions about Rich's preferences.

andy.fingerhut18:10:37

If a human makes a design decision, and someone else tries to answer "why did they do that?", you either go by your best guess, or what they have said. I'm not aware he has answered this particular "why" question before for Clojure, although he has answered many many others.

grav07:10:29

How do I get the data back from a js/Error? It looks like data in the REPL, but it comes back as a string when using .-message

cljs.user=> (js/Error. {:foo 42})
#object[Error Error: {:foo 42}]
cljs.user=> (.-message *1)
"{:foo 42}"

thheller07:10:51

@grav use (throw (ex-info "msg" {:foo 42})) and ex-data

thheller07:10:09

js/Error will call .toString and does not support data

grav07:10:44

Thatā€™s what Iā€™m using now - just seems a bit tedious. Ok. How does the repl display it as data? Does it just guess that it might be clj data?

grav07:10:30

Or maybe it is just how it displays strings ā€¦ thatā€™s probably what threw me off

thheller07:10:43

nah just seems buggy printer for error given that the Error: isn't a string either

grav07:10:52

cljs.user=> (js/Error. "hello")
#object[Error Error: hello]

octahedrion07:10:09

is (enable-console-print!) needed these days ?

mfikes11:10:45

(`enable-console-print!` became unnecessary with 1.10 when cljs.main was introduced)

Brendan Cannell11:10:26

I'm looking for a library for nested data manipulation, and I saw a recommendation from a couple years ago of specter. Has anything changed since then, i.e., better alternatives that I should learn instead?

dominicm11:10:13

Specter is still the most recomended thing I see outside of using core functions.

grav11:10:48

Iā€™d really like something like jq but for edn šŸ™‚

šŸ˜ 4
šŸ‘ 4
rlj07:10:51

I wrote a haskell(!) thing a while back which converts streams of edn to streams of json, so that I could use jq on edn logs: https://github.com/uswitch/ej

rlj07:10:38

I later discovered I could do the same thing with a lot less hassle with the aid of joker https://github.com/candid82/joker

rlj07:10:52

#!/usr/bin/env bash

while read line
do
    echo $line | joker --hashmap-threshold -1 -e "(-> (read) joker.json/write-string println)" | jq .
done

rlj08:10:00

a lot slower, though

Zor12:10:26

Greetings! I've been browsing the last couple hours, trying to find out how I'd like to proceed with building a side-project webapp using mostly Clojurescript. I come from the Rails world. I couldn't find anything based on the plain old template-file architecture, i.e. the 20 years old approach of serving slightly tweaked HTML documents, possibly with a sprinkling of Javascript to enhance UX. I'm now under the impression that should I want to commit to Clojurescript for my side-project webapp, I better embrace either Om, Reframe, or some other Reacty thing, just to publish a bunch of largely static pages. Is that impression correct ?

eval202013:10:37

For static sites thereā€™s https://www.staticgen.com/

eval202013:10:50

3 options for Clojure

zalky13:10:25

@zor: you can definitely render some simple static documents without om, reframe or react. We generate some simple static pages on the server using https://github.com/weavejester/hiccup

Zor13:10:18

I see your point, if it's mostly static, just don't do a backend (staticgen). Or plain hiccup to generate the static pages, appropriate caching strategies left as an exercise to the reader.

Zor13:10:41

Are there alternative templating systems to Hiccup, using archaic architecture, (like erb, smarty, moustache, ...). I imagine usage would run like (render-template template_string bindings). (I won't answer the "Why would you want that?" question until someone asks for it šŸ˜‰ )

Zor13:10:10

:thumbsup: Thanks for the pointer! It is indeed what I was looking for!

āœ”ļø 4
Zor13:10:39

Now the beer_value_in_cents question is : anyone know of cljstache alternatives (outside hiccup, and that doesn't aim at building SPAs) ? šŸ™‚

valtteri13:10:09

@zor check section ā€œHTML Generationā€ https://www.clojure-toolbox.com/

valtteri13:10:04

And also ā€œTemplate Languagesā€ section

Zor13:10:28

amazing! thanks a lot valtteri

valtteri14:10:26

No problem! As you can see most of the static generators seem to be for clj. Itā€™s more common to build backend with clj and frontend with cljs. Code can be shared between the two, which is a huge benefit. If you donā€™t find a cljs or clj lib suitable for your needs,you can use libraries from node/js and jvm ecosystems via interop.

rplevy17:10:53
replied to a thread:I never new that

I wonder why the choice was made to support both the ^0 (eg. 023) and ^Nr (eg. 8r23) convention for octal? It seems like the general Nr one would have been enough.

rlj07:10:51

I wrote a haskell(!) thing a while back which converts streams of edn to streams of json, so that I could use jq on edn logs: https://github.com/uswitch/ej