Fork me on GitHub
#clojurescript
<
2018-11-05
>
souenzzo00:11:57

I'm porting an script to cljs and I see that (map int "abc") returns non-sense in cljs (expected: (97 98 99) actual: (0 0 0) ) It should be a ticket on jira?

(defn int
  "Coerce to int by stripping decimal places."
  [x]
  (cond
    (char? x) (.charCodeAt x 0))
    :else (bit-or x 0))

didibus01:11:33

Looks like it to me.

jaawerth02:11:06

in the meantime you can do (map #(.charCodeAt % 0) "abc")

dominicm08:11:25

fwiw, the cljs implementation:

(defn int
  "Coerce to int by stripping decimal places."
  [x]
  (bit-or x 0))
Definitely looks different 🙂

littleli11:11:43

Hi guys, how would you approach error tracking software like http://sentry.io in your clojurescript (browser) project?

borkdude11:11:07

Question / bug, not sure:

;; run with:

;; clj -Srepro -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.439"} org.clojure/test.check {:mvn/version "RELEASE"}}}' -m cljs.main -re node -i node_exit.cljs

(ns node-exit
  (:require
   [clojure.test.check]
   [clojure.spec.alpha :as s]
   [clojure.spec.test.alpha :as stest]
   [clojure.test :as t]
   ))

(defmethod cljs.test/report [::t/default :end-run-tests] [m]
  (if-not (cljs.test/successful? m)
    (.exit js/process 1)
    (.exit js/process 0)))

(t/deftest some-test
  (t/is false))

(t/run-tests)
(println "done, exiting")
What’s the proper way of exiting the process with the correct exit code here? Now the process hangs. It doesn’t hang without the defmethod.

borkdude11:11:27

@ales.najmann we use the js client that sentry provides

👍 4
thheller11:11:34

@borkdude you probably just want to compile the node script and then run it separately via node. if you let cljs.main run it you'll just kill the node process its managing but the JVM process will stay alive

borkdude11:11:40

@thheller shouldn’t there be a supported way for returning the correct exit code in a script ran by -i?

thheller11:11:07

no idea what cljs.main does or should do. it might make sense yes but given that its pretty much only a node thing its probably best to just separate compiling and running

thheller11:11:43

clj -m ... && node out/tests.js

mccraigmccraig11:11:25

@ales.najmann we just bundle the sentry js client (raven.js iirc) in our cljs app

👍 4
littleli11:11:01

Thank you guys 🙂

carocad12:11:19

hey guys, does anybody know how to require node.js modules with the @ character through the ns :require form; like

(ns hive.components.foreigns.expo
  (:require [expo :as Expo]
            ["@expo/vector-icon"s :as VectorIcons] ;; <-- this fails :(
            [hive.foreigns :as fl]))

thheller12:11:43

["@expo/vector-icon"s :as VectorIcons] the s seems misplaced?

carocad12:11:21

@thheller I tried it but figwheel complains about not being able to read the message

carocad13:11:27

and after some time it just times out in the repl

aisamu12:11:16

Are you using npm-deps, figwheel's npm or manually populated foreign-lib entries?

carocad13:11:53

Nope, but I do have target node js. I'm not sure if Clojure does automatically scan the npm node modules though.

aisamu14:11:04

It did, but the default was recently changed to false IIRC.

carocad16:11:06

do you know in which version ? or where can I find more info about it?

aisamu18:11:09

You don't necessarily have to change your cljs version, just explicitly set it to what you want. I think I read the announcement on #cljs-dev

thheller13:11:31

its supposed to work that way but :npm-deps has issues with @ I believe. Not sure if that was fixed or still ongoing

borkdude13:11:03

@mfikes cool! I’m using the regular compile now that @thheller suggested in speculative

skrat17:11:39

Can't take value of macro ... in a .cljc file http://ix.io/1r3N

skrat17:11:45

have you seen anything like this before?

skrat17:11:51

@borkdude yeah that would be useful if I would be unquoting something, like returning a list from the macro that contains some symbols that I need to mask with auto-gen-sym (`foo#`)

skrat17:11:44

no it's not cljs code, that's why the macro is enclosed in reader conditional, but it can be used from both clj and cljs during compile time

borkdude17:11:51

FWIW, this compiles in a .cljc file for me:

#?(:clj
   (defmacro list-posts []
     (vec
      (for [f [1 2 3]
            :when (even? f)]
        f))))


(def posts
  (list-posts))

skrat17:11:59

does cljs compiler compile that without error? thanks for trying it

borkdude17:11:17

ah cljs compiler, no.

borkdude17:11:05

@skrat with macrovich I can get it to work

borkdude17:11:39

(ns dre.foo
  (:require
   #?(:clj [net.cgrand.macrovich :as macros]))
  #?(:cljs
     (:require-macros
      [net.cgrand.macrovich :as macros]
      [dre.foo :refer [list-posts]])))

#?(:clj
   (defmacro list-posts []
     (vec
      (for [f# [1 2 3]
            :when (even? f#)]
        f#))))

(def posts
  (list-posts))

borkdude17:11:37

without macrovich you would probably need an extra .cljs file that imports the macro from the .cljc file

skrat17:11:27

@borkdude awesome! it actually works without macrovich too, I just need that #?(:cljs (:require-macros... form

skrat17:11:33

thank you

skrat17:11:34

I tried something similar before, but I did reader conditional inside (:require form, with :refer-macros, and that didn't work

lilactown19:11:35

when given a fn, is it possible to look up the metadata that is associated with it in a defn without a macro?

lilactown19:11:35

e.g.:

(defn ^:foo example [] "bar")

(defn is-foo? [f]
  ;; read metadata associated with `f` to see if `:foo` is true
)

dnolen19:11:43

(actually not true)

dnolen19:11:48

sorry, you can do this with vars

dnolen19:11:01

but you should be careful since the semantics are different from Clojure

dnolen19:11:15

this is not dynamic lookup

dnolen19:11:31

we just dump compiler info

dnolen19:11:34

into the source

lilactown19:11:48

so I’d have to pass in example like (is-foo (var example))?

dnolen19:11:16

yes but there's no runtime "passing"

dnolen19:11:20

you can't parameterize

dnolen19:11:28

it has to be a statically known var

lilactown19:11:39

yeah that’s what I’m really after

borkdude19:11:56

is maria.cloud built on self-hosted cljs?