lumo

:lumo: Standalone ClojureScript environment. Currently at version 1.9.0
moxaj 2017-06-13T14:55:39.092717Z

in self hosted clojurescript, is it possible to resolve a symbol to a function/var (at compile time, if that matters)? With lumo, I reckon it would be possible with the new eval, or by having access to the underlying compiler state (and perhaps rolling your own eval), but ideally it should be independent from the environment (= whether it's lumo, planck, klipse, whatever)

mfikes 2017-06-13T15:08:42.455044Z

@moxaj Yes. Planck has an ns-resolve that sits atop eval like this:

(defn ns-resolve
  [ns sym]
  (eval `(~'var ~sym) ns))

mfikes 2017-06-13T15:09:24.473970Z

Additionally, ClojureScript itself is introducing a (compile-time) resolve macro.

moxaj 2017-06-13T15:10:27.502975Z

@mfikes took at look at the new resolve, but the symbol wouldn't be available at compile time

moxaj 2017-06-13T15:10:55.515282Z

for the resolve call, I mean

mfikes 2017-06-13T15:11:17.525015Z

You have a case where the symbol is calculated at runtime?

moxaj 2017-06-13T15:11:57.543050Z

well, the symbol is an input to a macro, which would use resolve during its macroexpansion

mfikes 2017-06-13T15:12:49.565826Z

Right. If your symbol is known at compile time, you can use ClojureScript’s new resolve macro. If not, in self-hosted you can use eval to do things at runtime.

mfikes 2017-06-13T15:14:57.622814Z

cljs.user=> (def abc 3)
#'cljs.user/abc
cljs.user=> (resolve 'abc)
#'cljs.user/abc
cljs.user=> (resolve (symbol "abc"))
            ^
Doesn't support namespace: abc at line 1
cljs.user=> (require '[planck.core :refer [resolve]])
nil
cljs.user=> (planck.core/resolve (symbol "abc"))
#'cljs.user/abc

mfikes 2017-06-13T15:15:05.626425Z

^ concrete example

moxaj 2017-06-13T15:16:28.663962Z

hm, I suspected that was the case ... But for my use case, it would have to be independent from the env (library code), so that got me thinking: what if there was a default compiler state defined in cljs.js, which all self hosted environments used? That wouldn't be that big of a change - theoretically - I believe

mfikes 2017-06-13T15:17:27.690540Z

Ahh, understood. You want to write a library that depends on compiler state.

moxaj 2017-06-13T15:17:31.692802Z

yep

moxaj 2017-06-13T15:17:57.703974Z

in clojure and jvm clojurescript, it's easy, since I have require and resolve

metametadata 2017-06-13T15:18:15.712357Z

Hello. So I'm trying to port a Bash script to Lumo and wonder how to port this line: cd "${BASH_SOURCE%/*}" I.e. I want to change the working directory to the folder in which my Lumo script resides. It looks like Node's __dirname does not work in Lumo. I kinda managed to get script path via (.-argv js/process) but I doubt it's going to be reliable enough as it returns smt. like [/usr/local/Cellar/lumo/1.5.0/bin/lumo nexe.js ./subfolder/script.cljs other args] on my machine.

mfikes 2017-06-13T15:19:40.750740Z

Hmm. Your Lumo script might actually be inside a JAR file.

mfikes 2017-06-13T15:20:00.759389Z

I guess in your case the script is on disk.

2017-06-13T15:20:34.775197Z

cljs.user=> js/__dirname
"."

metametadata 2017-06-13T15:20:38.776938Z

yes, the idea is that it will always be on disk and invoked like ./subfolder/script.cljs or ./script.cljs

metametadata 2017-06-13T15:21:12.792231Z

@hlolli right, but I would expect it to return /subfolder or the absolute path

2017-06-13T15:21:20.796054Z

🙂 not sure if that's expected, just wanted to point out the js/ prefix

metametadata 2017-06-13T15:21:29.799780Z

okay 🙂

mfikes 2017-06-13T15:23:50.862335Z

@metametadata We added :file info to self-hosted at one point, and it might be the reason this works:

cljs.user=> (require 'foo.core)
nil
cljs.user=> (:file (meta #'foo.core/x))
"/Users/mfikes/src/foo/core.cljs"

🆒 1
mfikes 2017-06-13T15:25:32.908629Z

Oh, wait. Sorry, that’s depending on a Planck-specific feature to ensure the file is fully qualified. In Lumo it behaves differently.

2017-06-13T15:29:33.018080Z

(.cwd js/process)

metametadata 2017-06-13T15:31:06.062573Z

yes, I tried that, it returns the folder of my current shell, not the folder of the script

anmonteiro 2017-06-13T15:32:23.097650Z

@metametadata __dirname should work if you run a script

anmonteiro 2017-06-13T15:32:34.102667Z

Just like in Node

anmonteiro 2017-06-13T15:33:09.118731Z

If you type __dirname at the Node REPL you also won't get anything meaningfull

anmonteiro 2017-06-13T15:33:29.128176Z

Let me know if that's not the case

metametadata 2017-06-13T15:35:10.173188Z

alright, one moment

anmonteiro 2017-06-13T15:35:29.182061Z

I'll try in like 20min

metametadata 2017-06-13T15:35:56.193681Z

~/dev/foo ᐅ tree
.
└── bar
    └── script.cljs

1 directory, 1 file
~/dev/foo ᐅ cat bar/script.cljs
#!/usr/bin/env lumo
(ns core.script)

(println js/__dirname)
~/dev/foo ᐅ ./bar/script.cljs
.

metametadata 2017-06-13T15:36:12.200750Z

it looks like it always returns .

metametadata 2017-06-13T15:36:27.207157Z

ᐅ lumo             
Lumo 1.5.0
ClojureScript 1.9.542
Node.js v7.10.0

anmonteiro 2017-06-13T15:58:19.787561Z

@metametadata looking into it

metametadata 2017-06-13T16:03:26.925819Z

anmonteiro: thank you! I have to leave now but when I'm back to keyboard I can file a GitHub issue if it turns out to be something to be fixed in the future releases.

anmonteiro 2017-06-13T16:10:40.110278Z

@metametadata definitely a bug

anmonteiro 2017-06-13T16:10:44.111885Z

please file a ticket

moxaj 2017-06-13T16:12:23.154314Z

@anmonteiro I'd be interested to hear your thoughts of my 'suggestion' above (see the conversation between me and @mfikes)

anmonteiro 2017-06-13T16:13:18.177061Z

@moxaj there’s lumo.repl/resolve-var

anmonteiro 2017-06-13T16:13:29.181410Z

would that work for your use case?

moxaj 2017-06-13T16:14:45.212466Z

> But for my use case, it would have to be independent from the env (library code), so that got me thinking: what if there was a default compiler state defined in cljs.js, which all self hosted environments used? That wouldn't be that big of a change - theoretically - I believe this one, to be specific 🙂

anmonteiro 2017-06-13T16:16:55.264617Z

@moxaj hrm can’t you use cljs.env/*compiler*?

👍 1
moxaj 2017-06-13T16:17:13.271718Z

would that be equal to your st?

anmonteiro 2017-06-13T16:17:14.271834Z

isn’t it bound during your script?

anmonteiro 2017-06-13T16:17:18.273472Z

yeah

anmonteiro 2017-06-13T16:17:35.279845Z

not equal. the same

moxaj 2017-06-13T16:17:57.290289Z

that'd be awesome! I'll report when I get to test it

anmonteiro 2017-06-13T16:18:05.293450Z

👍

anmonteiro 2017-06-13T16:59:38.284Z

@dominicm you had a nested require bug a while ago, remember that?

anmonteiro 2017-06-13T16:59:46.287194Z

I wanna fix something but make sure I don’t break that 🙂

anmonteiro 2017-06-13T16:59:55.291176Z

but I don’t remember how to repro

dominicm 2017-06-13T18:00:01.732477Z

You mean requiring node modules?

dominicm 2017-06-13T18:00:12.738030Z

No. Can't be that.

dominicm 2017-06-13T18:00:22.742561Z

Don't remember right now

anmonteiro 2017-06-13T18:01:37.775393Z

yeah

anmonteiro 2017-06-13T18:01:55.782681Z

@dominicm something about preserving paths when requiring node modules

anmonteiro 2017-06-13T18:25:59.361884Z

@moxaj let me know if tagged literals is something you’d like to work on

dominicm 2017-06-13T18:26:06.364566Z

Shebang relative requires?

moxaj 2017-06-13T18:26:07.364999Z

I did

anmonteiro 2017-06-13T18:26:14.368044Z

happy to coach you along the way

dominicm 2017-06-13T18:26:18.369710Z

I have a convenient repo located on my GitHub

moxaj 2017-06-13T18:26:19.370100Z

shall I comment here? or on the issue

anmonteiro 2017-06-13T18:26:46.381515Z

if it’s something you think deserves to be saved in history, GitHub please 🙂

anmonteiro 2017-06-13T18:26:50.383214Z

@dominicm might be

moxaj 2017-06-13T18:26:51.383829Z

alright

anmonteiro 2017-06-13T18:33:25.550586Z

@moxaj what do you wanna achieve with data readers?

moxaj 2017-06-13T18:34:42.582182Z

the same thing I'm now going to achieve with accessing the compiler state instead 😄

moxaj 2017-06-13T18:34:49.584710Z

evaluating user input at compile time

anmonteiro 2017-06-13T18:34:56.587862Z

your fork is a good start but there’s some things that need to be ironed out

moxaj 2017-06-13T18:34:58.588414Z

data readers were my first attempt, but that smells like a hack

anmonteiro 2017-06-13T18:35:24.599116Z

I’d love to have it implemented but we should make it work for the REPL / scripts first

anmonteiro 2017-06-13T18:35:29.601141Z

and then use that in the closure namespace

moxaj 2017-06-13T18:35:42.606014Z

what I have now seems to work in the repl

anmonteiro 2017-06-13T18:35:52.609896Z

how come

moxaj 2017-06-13T18:36:05.614989Z

well, not the full story

moxaj 2017-06-13T18:36:23.621852Z

just what I've mentioned at the issue

moxaj 2017-06-13T18:36:30.624306Z

the data readers get loaded

anmonteiro 2017-06-13T18:36:35.626137Z

right

moxaj 2017-06-13T18:36:51.633189Z

I might be very far from the full solution, I have no idea

anmonteiro 2017-06-13T18:36:53.634202Z

so here’s what I had thought before

anmonteiro 2017-06-13T18:37:18.643823Z

just like we look for every deps.cljs file in JARs

anmonteiro 2017-06-13T18:37:32.649873Z

we should also look for data reader files and load them

anmonteiro 2017-06-13T18:38:58.684410Z

also just found a bug related to loading deps.cljs 😄 https://github.com/anmonteiro/lumo/issues/184

moxaj 2017-06-13T18:39:18.692019Z

as far as I can tell, that's what I'm doing - checking for data_readers.clj(s|c|) in the classpath directories and jars, and loading them

anmonteiro 2017-06-13T18:39:52.705040Z

yeah, which is why I said it’s a good start

anmonteiro 2017-06-13T18:40:13.713130Z

the problem is that you’re doing it in lumo.closure

anmonteiro 2017-06-13T18:40:18.715118Z

and that’s not loaded when the REPL starts or when scripts execute

anmonteiro 2017-06-13T18:40:39.724390Z

also we shouldn’t be checking for data_readers.clj

anmonteiro 2017-06-13T18:40:48.727792Z

^ that’s reserved for Clojure

moxaj 2017-06-13T18:40:54.730485Z

noted

anmonteiro 2017-06-13T18:41:04.734624Z

also unsure about data_readers.cljs, but it’s OK to punt on that for now

anmonteiro 2017-06-13T18:44:55.827939Z

@moxaj was I clear or do you still have some questions?

anmonteiro 2017-06-13T18:45:27.841721Z

do let me know if I’m not explaining the problem well enough

moxaj 2017-06-13T18:47:56.902646Z

@anmonteiro it's still somewhat unclear. Which files exactly are available when the scripts execute? What should I hook into after loading the readers?

anmonteiro 2017-06-13T18:49:04.929052Z

@moxaj when a script executes or the REPL starts we should have all the classpath paths

anmonteiro 2017-06-13T18:49:33.941229Z

after loading the readers I don’t really recall right now where we should hook into

anmonteiro 2017-06-13T18:49:49.947315Z

I’m stepping into a meeting right now but I’ll do a little bit or research later

moxaj 2017-06-13T18:50:03.952748Z

alright, thanks!