Fork me on GitHub
#clojurescript
<
2021-12-23
>
metehan09:12:05

how can I (js/console.log (. js/window -myvar)) I couldn't find the scope of the variable I created from console.

thheller09:12:06

variables created in the console are only accessible in the console

metehan09:12:45

oh thank you

thheller09:12:22

you can assign window.myvar directly and that would be accessible but local let or const only exist in the console

metehan09:12:37

normally I use window.myvar but I just got curious about console vars 🙂

Adam Kalisz17:12:24

I upgraded to openjdk-17 on my Debian Testing today and it seems there is some problem with shadow-cljs:

[:failed-to-compare "^16.14.0" "16.13.0" #error {
 :cause "Cannot invoke \"Object.getClass()\" because \"target\" is null"
 :via
 [{:type java.lang.NullPointerException
   :message "Cannot invoke \"Object.getClass()\" because \"target\" is null"
   :at [clojure.lang.Reflector invokeInstanceMethod "Reflector.java" 97]}]
 :trace
 [[clojure.lang.Reflector invokeInstanceMethod "Reflector.java" 97]
  [shadow.cljs.devtools.server.npm_deps$make_engine invokeStatic "npm_deps.clj" 39]
  [shadow.cljs.devtools.server.npm_deps$make_engine invoke "npm_deps.clj" 32]
  [shadow.cljs.devtools.server.npm_deps$fn__15534$fn__15535 invoke "npm_deps.clj" 46]
  [clojure.lang.Delay deref "Delay.java" 42]
  [clojure.core$deref invokeStatic "core.clj" 2320]
  [clojure.core$deref invoke "core.clj" 2306]
  [shadow.cljs.devtools.server.npm_deps$fn__15534$fn__15537 invoke "npm_deps.clj" 52]
  [shadow.cljs.devtools.server.npm_deps$is_installed_QMARK_ invokeStatic "npm_deps.clj" 207]
  [shadow.cljs.devtools.server.npm_deps$is_installed_QMARK_ invoke "npm_deps.clj" 201]
  [shadow.cljs.devtools.server.npm_deps$main$fn__15622 invoke "npm_deps.clj" 223]
  [clojure.core$complement$fn__5669 invoke "core.clj" 1441]
  [clojure.core$filter$fn__5893 invoke "core.clj" 2821]
  [clojure.lang.LazySeq sval "LazySeq.java" 42]
  [clojure.lang.LazySeq seq "LazySeq.java" 51]
  [clojure.lang.RT seq "RT.java" 535]
  [clojure.core$seq__5402 invokeStatic "core.clj" 137]
  [clojure.core$seq__5402 invoke "core.clj" 137]
  [shadow.cljs.devtools.server.npm_deps$main invokeStatic "npm_deps.clj" 225]
  [shadow.cljs.devtools.server.npm_deps$main invoke "npm_deps.clj" 216]
  [shadow.cljs.devtools.cli$main invokeStatic "cli.clj" 143]
  [shadow.cljs.devtools.cli$main doInvoke "cli.clj" 134]
  [clojure.lang.RestFn applyTo "RestFn.java" 137]
  [clojure.core$apply invokeStatic "core.clj" 669]
  [clojure.core$apply invoke "core.clj" 660]
  [shadow.cljs.devtools.cli$_main invokeStatic "cli.clj" 221]
  [shadow.cljs.devtools.cli$_main doInvoke "cli.clj" 219]
  [clojure.lang.RestFn applyTo "RestFn.java" 137]
  [clojure.lang.Var applyTo "Var.java" 705]
  [clojure.core$apply invokeStatic "core.clj" 665]
  [clojure.main$main_opt invokeStatic "main.clj" 514]
  [clojure.main$main_opt invoke "main.clj" 510]
  [clojure.main$main invokeStatic "main.clj" 664]
  [clojure.main$main doInvoke "main.clj" 616]
  [clojure.lang.RestFn applyTo "RestFn.java" 137]
  [clojure.lang.Var applyTo "Var.java" 705]
  [clojure.main main "main.java" 40]]}]
[:failed-to-compare "^16.14.0" "16.13.0" #error {
 :cause "Cannot invoke \"Object.getClass()\" because \"target\" is null"
 :via
 [{:type java.lang.NullPointerException
   :message "Cannot invoke \"Object.getClass()\" because \"target\" is null"
   :at [clojure.lang.Reflector invokeInstanceMethod "Reflector.java" 97]}]
 :trace
 [[clojure.lang.Reflector invokeInstanceMethod "Reflector.java" 97]
  [shadow.cljs.devtools.server.npm_deps$make_engine invokeStatic "npm_deps.clj" 39]
  [shadow.cljs.devtools.server.npm_deps$make_engine invoke "npm_deps.clj" 32]
  [shadow.cljs.devtools.server.npm_deps$fn__15534$fn__15535 invoke "npm_deps.clj" 46]
  [clojure.lang.Delay deref "Delay.java" 42]
  [clojure.core$deref invokeStatic "core.clj" 2320]
  [clojure.core$deref invoke "core.clj" 2306]
  [shadow.cljs.devtools.server.npm_deps$fn__15534$fn__15537 invoke "npm_deps.clj" 52]
  [shadow.cljs.devtools.server.npm_deps$is_installed_QMARK_ invokeStatic "npm_deps.clj" 207]
  [shadow.cljs.devtools.server.npm_deps$is_installed_QMARK_ invoke "npm_deps.clj" 201]
  [shadow.cljs.devtools.server.npm_deps$main$fn__15622 invoke "npm_deps.clj" 223]
  [clojure.core$complement$fn__5669 invoke "core.clj" 1441]
  [clojure.core$filter$fn__5893 invoke "core.clj" 2821]
  [clojure.lang.LazySeq sval "LazySeq.java" 42]
  [clojure.lang.LazySeq seq "LazySeq.java" 51]
  [clojure.lang.RT seq "RT.java" 535]
  [clojure.core$seq__5402 invokeStatic "core.clj" 137]
  [clojure.core$seq__5402 invoke "core.clj" 137]
  [shadow.cljs.devtools.server.npm_deps$main invokeStatic "npm_deps.clj" 225]
  [shadow.cljs.devtools.server.npm_deps$main invoke "npm_deps.clj" 216]
  [shadow.cljs.devtools.cli$main invokeStatic "cli.clj" 143]
  [shadow.cljs.devtools.cli$main doInvoke "cli.clj" 134]
  [clojure.lang.RestFn applyTo "RestFn.java" 137]
  [clojure.core$apply invokeStatic "core.clj" 669]
  [clojure.core$apply invoke "core.clj" 660]
  [shadow.cljs.devtools.cli$_main invokeStatic "cli.clj" 221]
  [shadow.cljs.devtools.cli$_main doInvoke "cli.clj" 219]
  [clojure.lang.RestFn applyTo "RestFn.java" 137]
  [clojure.lang.Var applyTo "Var.java" 705]
  [clojure.core$apply invokeStatic "core.clj" 665]
  [clojure.main$main_opt invokeStatic "main.clj" 514]
  [clojure.main$main_opt invoke "main.clj" 510]
  [clojure.main$main invokeStatic "main.clj" 664]
  [clojure.main$main doInvoke "main.clj" 616]
  [clojure.lang.RestFn applyTo "RestFn.java" 137]
  [clojure.lang.Var applyTo "Var.java" 705]
  [clojure.main main "main.java" 40]]}]
The shadow-cljs versions I tried are 2.15.3 and 2.16.9. I have found a similar issue here: https://clojurians-log.clojureverse.org/shadow-cljs/2021-03-26 but didn't understand, whether it is still something Nashorn JS related that shadow-cljs perhaps isn't handling? Should I go back to openjdk-11 or is there some workaround/ fix @thheller?

p-himik17:12:24

Just a meta-comment. Code blocks should be surrounded with triple backticks on their own lines - not single backticks on the same line. Huge blocks are better suited for attachments (then interested people can expand them and the whole window is not blocked for all the rest). Finally, there's #shadow-cljs

Adam Kalisz17:12:05

Thank you for the heads up, I fixed it. Slack isn't very smart with its GUI and multi-line selection unfortunately.

👍 1
p-himik17:12:31

I didn't even know that such a thing can be created via UI. :) Have never used it for code blocks.

thheller17:12:11

I'm guessing you are using project.clj or deps.edn to manage your dependencies and didnt update there?

thheller17:12:03

the eroir you get usually when using a rather old shadow-cljs version with jdk 15+

Alex Miller (Clojure team)17:12:55

@U2FRKM4TW @U01BXSTEB2S even better, if you click the lightning bolt icon you can create a text snippet that will apply code formatting and fold to be even less intrusive in the conversation

👍 1
p-himik18:12:08

Yeah, that's what I meant by attachments, although now I realize that word is not in the UI and hence ambiguous.

Adam Kalisz13:12:42

@U064X3EF3 I will keep that in mind next time. I am not able to edit the message to apply the formatting. @thhellerhttp://y.es, it is project.clj and I actually updated there as well. I will try to update during the week again and triple check everything. If in general shadow-cljs should be ready for OpenJDK 17, I am sure I will make it work without issues.

thheller14:12:20

not aware of any issues with jdk17. using it myself without issues so far. I guess you could be excluding the graal js-engine which would also lead to your error?

Adam Kalisz09:03:24

Seems to work with the current Shadow-cljs version (those stack traces are still there, but it runs/ compiles). Still Debian, openjdk-17.

thheller10:03:13

the answer is still the same. this looks like you are using a really old shadow-cljs version

thheller10:03:31

that is easy to verify. run npx shadow-cljs clj-repl. it should print the version it is using on startup

thheller10:03:17

if it says connected to server then you still have shadow-cljs running somewhere. which also should have printed the version

Adam Kalisz09:04:12

Thank you for your patience. I fixed this. The problem was somewhere between these: I had some old Clojure installed system-wide using apt, also I had another shadow-cljs installed globally, which was quite old. I don't think that was in use but not great anyway. I still used shadow-cljs without npx, so that was using something from /usr/local/bin/shadow-cljs I've stopped everything, bumped even further to 2.18.0 using npm and in the leiningen project. Leiningen installed the package, npm as well. Now it all seems to run properly without any issues. Also the reported Clojure version in the REPL is 1.10.3 as it should be instead of the previous 1.10.1. (Btw. do you think about upgrading to 1.11.0?) I am still getting to know this environment. It is really new to me but I love what you are doing. 🙂

thheller09:04:35

I'll upgrade to 1.11 once 1.11.1 is out. 1.11 seems to cause some trouble for some people

thheller09:04:32

if you use leinigen anyways you can specify whichever version you want

leif19:12:09

When I run the following code in bootstrapped/self-hosted clojurescript:

(defn munge-res [a & b]
  (println a)
  (println b)
  42)

(println (munge-res 1 2))
I get the following error:
Error: .slice requires 2 arguments
	* Line 318: in (anonymous function)
	* Line 17: in cljs$user$munge_res
	* Line 39: in (anonymous function)
Runtime Stack:
Error: .slice requires 2 arguments
    at Array.funExpr9 [as slice] ()
    at cljs$user$munge_res (eval at evalCompiled (?), <anonymous>:1:3347)
    at funExpr0 (eval at evalCompiled (?), <anonymous>:1:7761)
    at LazyRuntime.abstractRun ()
    at LazyRuntime.runtime ()
    at Runner.evalCompiled ()
    at run ()
    at Worker.<anonymous> ()

leif19:12:05

This seems like valid clojurescript code to me, are variable arity functions currently a limitation in bootstrapped clojurescript?

leif19:12:16

It looks like the generated javascript is:

VM8948 react_devtools_backend.js:4045 cljs.user.munge_res = (function cljs$user$munge_res(var_args){
var args__41777__auto__ = [];
var len__41774__auto___927 = arguments.length;
var i__41775__auto___928 = (0);
while(true){
if((i__41775__auto___928 < len__41774__auto___927)){
args__41777__auto__.push((arguments[i__41775__auto___928]));

var G__929 = (i__41775__auto___928 + (1));
i__41775__auto___928 = G__929;
continue;
} else {
}
break;
}

var argseq__41778__auto__ = ((((1) < args__41777__auto__.length))?(new cljs.core.IndexedSeq(args__41777__auto__.slice((1)),(0),null)):null);
return cljs.user.munge_res.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__41778__auto__);
});

(cljs.user.munge_res.cljs$core$IFn$_invoke$arity$variadic = (function (a,b){
visr.core.println.call(null,a);

visr.core.println.call(null,b);

return (42);
}));

(cljs.user.munge_res.cljs$lang$maxFixedArity = (1));

/** @this {Function} */
(cljs.user.munge_res.cljs$lang$applyTo = (function (seq925){
var G__926 = cljs.core.first.call(null,seq925);
var seq925__$1 = cljs.core.next.call(null,seq925);
var self__41765__auto__ = this;
return self__41765__auto__.cljs$core$IFn$_invoke$arity$variadic(G__926,seq925__$1);
}));

visr.core.println.call(null,cljs.user.munge_res.call(null,(1),(2)));

leif19:12:43

When I run the code in the repl I get the result I would expect:

cljs.user=> (defn munge-res [a & b]
       #_=>   (println a)
       #_=>   (println b)
       #_=>   42)
#'cljs.user/munge-res
cljs.user=> (munge-res 1 2)
1
(2)
42

leif19:12:10

Hmm...the only instance of slide I see provides 3 arguments.

cljs.core.IndexedSeq(args__41777__auto__.slice((1)),(0),null)):null);

thheller06:12:16

I'm unsure why slice is called with 3 args but in general JS engines don't care and just ignore extra args

thheller06:12:31

but you seem to be running the code through some other compiler which is maybe more picky?

thheller06:12:11

hmm no wait, got confused by the parens. this is only calling slice with one arg. the rest is arguments to the IndexedSeq new call

thheller06:12:27

so I'm guessing your rewriting compiler only supports 2 args?

leif20:12:50

Ah, I see, I had also miscounted parens.

leif20:12:10

But ya, I'm evaluating the code in typescript.

leif21:12:20

Yup, you're right. I was using a polyfill that expected slice to be passed exactly 2 arguments.