Fork me on GitHub
#clojurescript
<
2019-07-04
>
maxp00:07:13

@dnolen could you advise me how to report clojurescript bugs like that?

cljs.user=> (for [x [1]] :a :b)
(:a)

Crispin03:07:34

That works for me

cljs.user> (for [x [1]] :a)
(:a)
cljs.user> (for [x [1]] :a :b)
Unexpected error (ArityException) compiling at (<cljs repl>:1:1).
Wrong number of args (3) passed to: cljs.core/for
I'm using [org.clojure/clojurescript "1.10.520"]

maxp04:07:45

What kind of REPL do you use? I've tried Planck and Lumo with the same result.

Crispin07:07:54

:dependencies => [nrepl "0.6.0"] [cider/piggieback "0.4.0"]

Crispin07:07:06

:plugins [cider/cider-nrepl "0.21.1"]

Crispin07:07:37

Im using emacs + cider 0.21 and this is what it adds to my project.clj environment when it jacks in

Crispin07:07:07

I have cider autostart figwheel. and those versions are: :plugins -> [lein-figwheel "0.5.19"] :dependencies -> [figwheel-sidecar "0.5.19"]

Crispin07:07:54

so to clarify, those figwheel deps are in my project.clj for any environment, and when I jack-in from cider, it adds the ones above (cider + nrepl)

Crispin07:07:43

so just tested without cider. Have just the two figwheels in the project:

Prompt will show when Figwheel connects to your application
[Rebel readline] Type :repl/help for online help info
ClojureScript 1.10.520
dev:cljs.user=> (for [x [1]] :a :b)
----  Could not Analyze  <cljs form>   line:1  column:1  ----

  Wrong number of args (3) passed to: cljs.core/for

  1  (for [x [1]] :a :b)
     ^--- 

----  Analysis Error  ----

Crispin07:07:57

you can get to this with

Crispin07:07:07

lein new figwheel tempapp

Crispin07:07:17

cd into tempapp and go lein figwheel

Crispin07:07:06

it may be figwheel catching that problem! :thinking_face:

maxp08:07:52

I tried Planck, as I understand it is nodejs based not java

Crispin12:07:09

figwheel says it works with nodejs. I've never used it with node though.

Crispin12:07:01

says it hotloads into node. compiler might need to be running on java though still.

dnolen00:07:11

File a ticket in JIRA

maxp00:07:10

there is a problem - <mailto:[email protected]|[email protected]> doesn't have access to http://clojure.atlassian.net when I press "Request access" button I got 404: Oops, you've found a dead link.

alexmiller00:07:02

If you don’t have a jira, file it in the support portal

alexmiller00:07:58

No acct needed. I’ll move it to the right place from there

maxp01:07:41

thank you.

Abhinav Sharma03:07:24

Hello everyone! I’m trying to call in Phaser (https://github.com/photonstorm/phaser#changelog) in a ClojureScript project here (https://github.com/abhi18av/rum-tavern). I’ve tried the npm-deps as well as cljsjs version of phaser but it seems there are problems while importing the phaser library. I am trying out this snippet in the associated cljs repl

(ns rum-tavern.phaser
  (:require [phaser :refer (Phaser)]))
 
And here’s the output
#object[Error Error: Assert failed: No more than 1024 pending puts are allowed on a single channel. Consider using a windowed buffer.
(< (.-length puts) impl/MAX-QUEUE-SIZE)]
   cljs.core.async.impl.channels.ManyToManyChannel.prototype.cljs$core$async$impl$protocols$WritePort$put_BANG_$arity$3 (jar:file:/Users/eklavya/.m2/repository/org/clojure/core.async/0.4.500/core.async-0.4.500.jar!/cljs/core/async/impl/channels.cljs:86:19)
   cljs.core.async.impl.protocols/put! (jar:file:/Users/eklavya/.m2/repository/org/clojure/core.async/0.4.500/core.async-0.4.500.jar!/cljs/core/async/impl/protocols.cljs:17:10)
   cljs.core.async.put_BANG_.cljs$core$IFn$_invoke$arity$2 (jar:file:/Users/eklavya/.m2/repository/org/clojure/core.async/0.4.500/core.async-0.4.500.jar!/cljs/core/async.cljs:122:20)
   cljs.core.async/put! (jar:file:/Users/eklavya/.m2/repository/org/clojure/core.async/0.4.500/core.async-0.4.500.jar!/cljs/core/async.cljs:116:1)
   figwheel.client.file_reloading.queued_file_reload.cljs$core$IFn$_invoke$arity$2 (jar:file:/Users/eklavya/.m2/repository/figwheel/figwheel/0.5.19/figwheel-0.5.19.jar!/figwheel/client/file_reloading.cljs:320:27)
   figwheel$client$file_reloading$queued_file_reload (jar:file:/Users/eklavya/.m2/repository/figwheel/figwheel/0.5.19/figwheel-0.5.19.jar!/figwheel/client/file_reloading.cljs:318:1)
   figwheel$client$file_reloading$figwheel_require (jar:file:/Users/eklavya/.m2/repository/figwheel/figwheel/0.5.19/figwheel-0.5.19.jar!/figwheel/client/file_reloading.cljs:178:30)
Can anyone point me to the right direction here please?

Abhinav Sharma12:07:08

So, i’ve solved it by switching to shadow-cljs which makes things a bit faster as well. https://github.com/PhaserGameDev/phaser-cljs-playground

Michaël Salihi11:07:14

Hi ! I'm developing a Reagent/React Native app and I'm stuck for concatening ratom state which contains a JS object. I would doing like this in ES6 JS : movies: [ ...this.state.movies, ...data.results ] or the equivalent movies: this.state.movies.concat(data.results). Any clue ? Should I use goog.object/extend ? thx

roman01la11:07:04

@admin055

(let [state (atom {:movies #js [1 2]})]
  (swap! state update :movies #(.concat % #js [3 4])))

roman01la11:07:57

updated with js array

grav18:07:42

Wondered about this implementation

(defn keyword-identical?
  "Efficient test to determine that two keywords are identical."
  [x y]
  (if (identical? x y)
    true
    (if (and (keyword? x) (keyword? y))
      (identical? (.-fqn x) (.-fqn y))
      false)))
vs
(or
  (identical? x y)
  (and
    (keyword? x)
    (keyword? y) 
    (identical? (.-fqn x) (.-fqn y)))

grav18:07:32

Isn’t the last one more idiomatic? Or is there a semantical difference I do not see?

andy.fingerhut18:07:02

I am hesitant to reply here, because my ClojureScript implementation knowledge is much much lower than my Clojure/Java implementation knowledge, but at least with Clojure/Java, if two keywords "look the same" when printed, i.e. same namespace and name, they always return true for identical?. In ClojureScript have you found two such keywords where identical? returns false?

jthibaudeau18:07:46

did a quick test in my cljs repl and (identical? :k1 :k1) returns false

andy.fingerhut18:07:07

OK, today I learned something. In Clojure/Java having all keywords that 'look the same' also be identical is a source of some efficiency when using them as map keys.

grav18:07:55

Well, keyword-identical? is an optimization that is apparently sometimes necessary. But my question was more about the coding style of the function.

mfikes19:07:58

There is an optimization in ClojureScript where constants like keywords are pooled (this is the default under :advanced) and in that situation identical? starts to be more useful

lilactown18:07:05

@andy.fingerhut keywords are not guaranteed to be indentical? according to the ClojureScript “Differences”

lilactown18:07:05

@grav I don’t think either one is more idiomatic than the other. The first is probably much easier for the analyzer to infer types and therefore could end up with more efficient output, though

andy.fingerhut18:07:04

@grav I do not see a behavior difference between those two ways of writing it, because identical? always returns true or false. If you do an or where one of the functions can return a non-nil non-false value that short-circuits the or, you will get back that as the value of the or.

lilactown18:07:40

the generated code looks about the same tbh

lilactown18:07:51

/**
 * Efficient test to determine that two keywords are identical.
 */
cljs.user.keyword_identical_QMARK_ = (function cljs$user$keyword_identical_QMARK_(x,y){
  if((x === y)){
    return true;
  } else {
    if((((x instanceof cljs.core.Keyword)) && ((y instanceof cljs.core.Keyword)))){
      return (x.fqn === y.fqn);
    } else {
      return false;
    }
  }
});
cljs.user.keyword_identical_SINGLEQUOTE_ = (function cljs$user$keyword_identical_SINGLEQUOTE_(x,y){
  return (((x === y)) || ((((x instanceof cljs.core.Keyword)) && ((y instanceof cljs.core.Keyword)) && ((x.fqn === y.fqn)))));
});

mfikes19:07:37

@U4YGF4NGM @grav Of historical interest: when keyword-identical? was written, ClojureScript was still using Clojure's or macro, so, even though Mikkel has a side point regarding whether the code is idiomatic, it may have actually produced nearly the same code back then. What we have now is nicer and and or implementations that spit out && and || like in your second example generated from Mikkel's proposed variant.

👍 4
Schmoho19:07:33

Is there a straightforward way to see the html a hiccup-like-form will be translated to by reagent?

lilactown19:07:34

at a REPL you can do: (require ‘[reagent.dom.server :as rds]) and then (rds/render-to-string [:div “foo”])

Schmoho19:07:42

just trying to get accustomed to all things web-designy

Schmoho20:07:40

in the re-frame todomvc tutorial there is a part of a hiccup-returning function that goes

[:ul 
  (for [todo visible-todos]
  ^{:key (:id todo)} [todo-item todo])]
with todo-item being a function taking no arguments that returns a function taking one argument and rendering some hiccup. now I am somewhat confused by the magic here - first, is this translating meta-data to html-attributes (I presume) canonical hiccup? Also, how is this function-call-like syntax there supposed to go? Is it always higher-order functions?

lilactown20:07:02

there’s really no such thing as canonical hiccup. libraries implement it in various ways

lilactown20:07:11

there’s a few things happening here

lilactown20:07:49

1. Reagent (and some other libraries) extend hiccup to allow a “component” to exist in the first position, just like a keyword :div. The component will be called with the rest of the hiccup vector as “props”. 2. The metadata used here won’t get converted to html attributes, but is used to signal to React the “key” to use when rendering a dynamic list. It won’t appear in the actual HTML. See https://reactjs.org/docs/lists-and-keys.html for more info 3. The todo-item implementation that you’re talking about sounds like a “form-2” component and is a way of defining a reagent component. take a look at https://github.com/reagent-project/reagent/blob/master/doc/CreatingReagentComponents.md for the 3 ways of creating Reagent components

lilactown20:07:46

I would suggest reading and consuming the reagent docs and trying out reagent by itself before diving into re-frame. re-frame assumes familiarity with Reagent

Schmoho14:07:47

Indeed, that turned out to be very necessary. Thanks a lot for the clarifications though.