Fork me on GitHub
#clojurescript
<
2018-06-21
>
justinlee02:06:06

is there a way to pipe console output back to the repl?

justinlee02:06:12

the X/Y of this is: certain libraries like schema and, it appears, spell-spec, output TTY codes that assume a terminal environment. this renders the console output virtually unusable

bhauman02:06:22

@lee.justin.m spell-spec doesn't assume tty console

justinlee02:06:46

@bhauman but presumably it looks a hell of a lot nicer if you have it (?)

justinlee02:06:12

it is possible to produce colors in the console but i’d be very impressed if you’d done that

bhauman02:06:15

yes expound does

bhauman02:06:45

expound doesn't produce colors in console

bhauman02:06:57

expound is what does the coloring

justinlee02:06:04

hm maybe i just need to give up on the console and rely on a repl

justinlee02:06:24

shadow-cljs turns on console print by default. i just need to figure out how to turn that off.

bhauman02:06:58

yeah figwheel.main redirects printed output back to the repl

bhauman02:06:30

and you choose console or repl. but I'd assume that shadow allows that as well

justinlee02:06:55

part of me wonders if it wouldn’t be easier and better to just redirect the console to another webpage

justinlee02:06:18

i don’t think it would be that hard and then you could do devtools-like things

justinlee02:06:41

anyway. getting off track. all i want is readable error messages for when i do type checking. lol

Hukka07:06:27

@hiskennyness I get that exact warning pretty often when putting some dev tools in my global lein profile

kennytilton13:06:55

It turned out to be pretty simple. Surprised I have not run ito it before. Maybe it is just figwheel, which I do not usually use. Anyway, the deal is I needed to require the package. The only reaon it worked is that something else did require the package. So I just added the require and figwheel stopped whining. Thanks for the input!

the-kenny09:06:38

I seem to have some problems with inferred externs using :foreign-libs with my own bundle.js in combination with :global-exports to be able to require the exported stuff. Clojurescript correctly infers type-hinted methods when using a tag like js/foo.Object but not when using ^foo.Object or ^foo/Object when foo is correctly required. Is this expected behavior, and how am I supposed to use foreign-libs with a webpack-built bundle.js?

thheller09:06:19

@the-kenny typehints are currently not resolved at all and its fine to just use ^js as a hint

the-kenny09:06:31

@thheller thanks! That's good to know. I think I'll just skip the global-exports part for now then to avoid confusion

andreasklein13:06:10

I am trying to build my application along the om-next-demo repository. When loading application state from remote It is not normalized into om-nexts default database format by the default merge function. Is this expected or am I using it wrong?

JH14:06:05

Has anybody used the doo test runner with nashorn? I keep getting the error 'Exception in thread "main" java.lang.AssertionError: Assert failed: Nashorn doesn't support :optimizations :none (not= :none optimization),' when I run 'lein doo nashorn test once'

tungsten15:06:39

yeah you need to set the optimizations to simple or something

tungsten15:06:40

then it works

zallin15:06:18

can someone explain me the logic behind cljs.string/blank?. In jvm if i call that function with non-string value it gives classcastexception and i expect and understand that because I call type-specific function explicitly and assume no coercion to happen. in clojurescript though it uses goog.string/isEmptyOrWhitespaceSafe (which is aliased by goog.string/isEmptySafe) which makes implicit conversion of argument to string in makeSafe() function. so even for empty object I get goog.string.makeSafe({}) => "[object Object]" and the overall result is false. From where i am standing this behaviour makes no sense so it should either return exception (as it does in jvm implementation) or present some adequate result for non-string object

dpsutton16:06:58

> True if s is nil, empty, or contains only whitespace. Honestly that matches the docstring pretty well

mikerod16:06:49

hm, an empty object is false, so I don’t see how it matches the doc string. however, the doc string is just meant to be about strings I’d say.

dpsutton16:06:08

i'm taking empty to mean empty string there

mikerod16:06:30

yes, and to answer @zallin the fact that clj fails with a class cast is more of an impl detail than anything I’d think

zallin16:06:42

if argument is not a string it is meaningless

mikerod16:06:44

clj didn’t make any explicit attempt to give you something useful, it just fails at the JVM interop

zallin16:06:35

and for me it is 100% okay because passing map to this function is unexpected

zallin16:06:54

i mean i assume it should be error if i accidentally do this

zallin16:06:12

it is not generic predicate that is defined on a handful of types

mikerod16:06:51

I’m not really saying what is right or wrong, just the CLJ/CLJS “philosophy” behind it

mikerod16:06:08

you can only rely on what is documented and the implicit assumptions around it being a clojure.string thing so expecting strings

mikerod16:06:23

CLJ has no error checking in that regard, it doesn’t do an “instance of String” check etc

mikerod16:06:39

You are just getting a runtime exception trying to call a String method that doesn’t exist on some non-string object

mikerod16:06:01

it is different than coercion in the CLJS case, but in either case, neither fn’s make any real attempt to handle non-strings, you just get something arbitrary impl depenedent

mikerod16:06:21

and you shouldn’t except to see cross-platform compatible code when you are relying on undocumented assumptions

mikerod16:06:55

I’m not always super happy about how this plays out (no errors and implicit coercion can be annoying and make it hard to know what is going on). just explaining the general mindset I think is in play here.

mikerod16:06:37

There have been arguments made at times that checking for all the negative cases can add measurable performance degradation etc, also maybe just adding too much code bloat. Those are the main things I’ve seen discussed on these sorts of topics

zallin16:06:48

yes and from my point of view it should not anyhow handle non-strings, as you said, it is not a part of its contract

dpsutton16:06:04

handling non-strings seems to match the docstring

dpsutton16:06:32

it returns true on nil, empty, and whitespace strings. all else is false

mikerod16:06:40

if the doc string is all about strings (which it is), then yes, it leaves a huge open space for what it does when not true

dpsutton16:06:58

so not barfing on other types is right in line with that docstring

mikerod16:06:59

> it returns true on nil, empty, and whitespace strings. all else is false no, CLJ throws exceptions

dpsutton16:06:08

but i'm reading the docstring

mikerod16:06:09

but it only says when it returns true hah

mikerod16:06:10

nothing else

mikerod16:06:16

which I always find these docs fun

dpsutton16:06:19

we're talking about cljs implementation

dpsutton16:06:27

and it does exactly what that docstring says

dpsutton16:06:31

no exceptions no weirdness

mikerod16:06:38

it’s very easy to do what that doc string says though, which is fun

dpsutton16:06:38

it returns true on the certain cases and else is false

mikerod16:06:10

I think you have to read doc strings and also understand this background philosophy of not often checking invalid types/values in clj/cljs

mikerod16:06:40

I could write (defn blank? [s] true) and comply with that doc string hah

mikerod16:06:01

I’m not making an argument against what it does or says though, just saying the interpretation involves more than the doc string alone I think

zallin16:06:14

yes and this is what i am frustrated with

mikerod16:06:41

I think it’s just a part of clj/cljs. It’s a bit hard to get used to, but once you are used to it, doesn’t really tend to be a big issue

mikerod16:06:07

If I have more vague places in code where I use clojure.string/blank? for example, I defend with (and (string? s) (blank? s))

zallin16:06:08

i personally do not think that behaviour on everything else is an undocumented assumption

mikerod16:06:18

if I’m not in a place of certainty about value types for whatever reason

mikerod16:06:44

> i personally do not think that behaviour on everything else is an undocumented assumption I don’t understand what you are saying here

zallin16:06:12

i think it should be handled with some sort of convention and be consistent across platforms

mikerod16:06:57

to handle negative scenarios consistently would be a big undertaking. I can see some of the reason why it isn’t done

mikerod16:06:07

and also, this sort of thing is fairly typical in manynamic languages

mikerod16:06:24

JavaScript is exceptionally terrible at allowing anything to do something without failing

mikerod16:06:52

clj/cljs are most brittle on this subject (in my opinion) in libs like clojure.set and clojure.string

mikerod16:06:03

e.g. clojure.string has a lot of places that throw null pointer exceptions

mikerod16:06:13

when a lot of clj/cljs is pretty nil-friendly

mikerod16:06:34

( blank? is actually an exception to this since it deals with nil explicitly)

mikerod16:06:49

You can have some fun in clojure.set when you don’t give sets as arguments

mikerod16:06:11

sometimes things work as you expect, sometimes it depends on which “set-or-not-set-coll” is passed to which argument to

mikerod16:06:31

but in general, it isn’t safe to call clojure.set fn (unless explicitly allowed) with non-set coll’s

mikerod16:06:04

I’ve had to do a bunch of code reviews of clj code before and have had to be on the hunt for clojure.set and clojure.string misuse or dangerous use. So I am familiar with the subtlety

zallin16:06:32

I understand your reasoning but these platform-specific logic can make life much harder

mikerod16:06:59

yes, I work in both clj/cljs pretty heavily now

zallin16:06:01

for instance I ve encountered what we discussed in .cljc file which is compiled to both envs

mikerod16:06:02

I know the pain

mikerod16:06:12

Yep, I write lots of cljc too

mikerod16:06:38

it can be a bit of a trick indeed, have to be careful on these topics I guess is my only advice. Know the “clojure way” and try to work with it hah

dpsutton16:06:59

the (and (string? x) (blank? x)) is a good portable solution and you don't have to deal with exception throwing.

mikerod16:06:03

I still prefer the clj/cljs cross-platform stack to alternatives 😛

zallin16:06:17

yeah me too

zallin16:06:46

so i guess that s it thanks

dpsutton16:06:00

not really. all this predicate promises is to recognize blank strings. which is does pretty well

mikerod16:06:46

if it is a string fn that expects strings, the only contract is its behavior on strings. this is true in clj and cljs. You can’t rely on undocumented arbitrary impl detail behavior to be consistent across platforms

mikerod16:06:07

similar things apply to clojure.set

mikerod16:06:52

but the particulars of how Google closure ends up handling it (a) I don’t really know why (b) coercion is a very dominate thing in JS, not so much in JVM

dnolen16:06:35

@zallin I think we could get some mileage out of spec here to get both runtime failure and compile time checking

dnolen16:06:30

I’d like to have a naming convention for spec files such that we can use them as type information for Google Closure Compiler

wizard 8
dnolen16:06:20

I don’t know when I’ll have time to work on this - but I have rough idea of how I want it to work - #cljs-dev is the place to talk about that if anyone is interested

henryw37417:06:36

Hi all. Does anyone know why the equivalent of clojure.core/extend is not in cljs? And could it be etc? Sorry if this question has come up before... I failed to Google it. Also, I do realize a similar fn extend-type is in cljs.core. Thanks

dnolen17:06:58

it could probably be made to work? but it’s just not a priority

henryw37417:06:17

ok thanks. Just wondering about a making a patch then... I submitted a patch for something else a while ago and not got any feedback on it https://dev.clojure.org/jira/browse/CLJS-2589. I appreciate reviewers time is short etc... but so is mine 😉 Is there any way to know when/if patches get looked at? should I try to get votes for the issue for example?

dnolen17:06:12

@henryw374 right thanks, yeah no one’s got around to look at one - looks ok - feel free to chime in on Fridays in #cljs-dev on stuff you want me to look at / apply

dnolen17:06:45

assume if it hasn’t been looked at there was just more pressing stuff in the queue

henryw37417:06:29

Ok thanks, will do