@dominicm thanks - got it to work:
{
mach/constant {msg "World"}
hello (println (str "Hello " #ref [mach/constant msg]))
}
# $ mach hello
# => Hello World
# $ mach --constant '{msg "Mars"}'
# => Hello Mars
Great!
@dominicm coming back to our earlier conversation of pondering making this kind of thing nicer: ((js/require "request") "<http://google.com>" callback)
, one might imagine a literal to assist (#js ...)
#js
is already a literal
I'd never use require inline like that. I'd always def it as request first.
I think the context is different in Mach to building usual CLJS programs
but yeah. I'm just bouncing ideas around
so many node libraries require one of these forms:
(def r (js/require "request"))
(def r ((js/require "request")))
(def r (.request (js/require "request")))
Making one pretty & not the others in a consistent way is confusing to use.{mach/npm [["left-pad" "1.1.3"]]
pad-foo (println ((js/require "left-pad") "foo" 5))}
That just doesn't bother me, oddly enough.
I don't really have a strong motivation - just revisiting this area
but it occurs you could also mess with the mach/npm directive, to add a symbol there you want to def
the lib to
Hmm, also a case fraught with peril given e.g. require('material-components-web/dist/material-components-web')
is a part of the material-components-web
module.
fair enough
I concede
we currently have this to tidy up also:
{mach/npm [["left-pad" "1.1.3"]]
mach/init (def lp (js/require "left-pad"))
pad-foo (println (lp "foo" 5))}
for those left-pad zealots out there
That syntax obviously works quite consistently. Not opposed to something like:
mach/constants {lp (js/require "left-pad")}
pad-foo (println (lp "foo" 5))
Anything that can create a body of bindings for you.{mach/npm [["left-pad" "1.1.3"]]
mach/props [lp (js/require "left-pad")]
pad-foo (println (lp "foo" 5))}
We need to ratify constants and props
yes. agreed.