Fork me on GitHub
#clojurescript
<
2017-03-16
>
seantempesta04:03:22

How do you set an environment variable for a cljs project that will be picked up by this definition? (defn get-sys-val [id] (or (System/getProperty id) (System/getenv id)))

seantempesta04:03:06

Because those look like java methods. Which I guess the cljs compiler is running. I setting the variable in :closure-defines and it didn’t work.

noisesmith04:03:56

seantempesta you need to ensure that code is run by the java cljs compiler, and not the cljs runtime, which I think would mean putting the code in a macro, not a function

noisesmith04:03:37

I compile environment constants into my shell.html via my server side rendering function

seantempesta04:03:21

Yeah, it’s a macro that’s evaluating it. But how do I set the environmental variable in a lein project?

noisesmith04:03:21

System/setProperty or use the specific non-portable version of setting an environment variable that works on your jvm/host combination

noisesmith04:03:17

the environ library is pretty simple but sets up some good default ways to do this stuff

seantempesta04:03:17

@noisesmith: Cool. I’ll check it out. Thanks.

qqq07:03:32

docs says clj substring is O(1); is cljs substring also O(1) ? (writing a parser, trying to figure out if I can use subs or if I need to use a reader of some sort)

thheller07:03:15

@qqq no idea about that but CLJ and CLJS both use the host String implementation. So I would look into what the JS String impl has to say about that, each JS-VM might even have a different implementation.

qqq13:03:42

I don't know if subs in cljs is O(1) or not. Now, I want to check s :: js string i :: integer r :: js regexp I'm interested in: is regexp r matchable in string s starting at location i ? I know of String.match -- but that checks anywhere; I want to enforce it to start the match at location i, where "^" in the regexp would match location i of the string.

mathpunk16:03:13

hey so.... I want to write scripts & servers in node.js, using cljs

mathpunk16:03:23

but i'm a little fuzzy on setting up for that -- I'm going to read up on lein-cljsbuild and figwheel for node, but I anticipate getting confused by which handles what

mathpunk16:03:27

figwheel + node is so that you automatically run the compiled-to-js code when you make changes, but it's cljsbuild that sets options for that compilation?

mobileink17:03:40

is there any way to suppress namespace expansion of kws in macros? if my macro is passed ::foo, I need to get that instead of :my.namespace/foo. i don’t suppose there’s any easy way to do that?

thheller17:03:13

@mobileink (keyword (name kw)) oops .. not what you asked ... you can look at *ns* and fake it, but no.

tbaldridge17:03:57

@mobileink you can't do that since ::foo expansion is a reader-level construct

tbaldridge17:03:08

see for example (read-string "::foo")

tbaldridge17:03:43

same with #(), #_ or any other reader macros

mobileink17:03:33

that's what i thought. 😦 but this is an opportunity for a dastardly post processing hack!

mobileink17:03:22

fwiw the task is to embed cljs in clojure, then emit the cljs to a file. is there a known way to do this?

samscript18:03:33

Hey, is there any way you can just drop a cljs onto a script file and run it in the browser, like with babel and es6?

qqq18:03:35

cljs.js ?

samscript18:03:20

I mean I wanna use it right in the browser without using lein at all, is that possible?

noisesmith18:03:42

cljs can self host, yes

noisesmith18:03:58

I mean lein is just a build tool, you can also use cljs.jar directly with java, but there's a cljs.js, as qqq mentions

mobileink18:03:02

possible, yes. "just drop" it in, not so much, afaik.

qqq18:03:06

eval-soup makes it pretty easy

qqq18:03:15

it's 2 lines of code to eval cljs exprs in the browser with eval-soup

mobileink18:03:49

@samscript you mean sth like <script>(defn f [x] (println (str "hello, " x)</script>?

mobileink18:03:18

i mean, <script type="application/x-clojurescript">...

mobileink19:03:21

what do you mean by "script file"?

mobileink19:03:23

@qqq eval-soup looks very useful, but it looks like it evals strings, not clj code.

qqq19:03:15

@mobileink: how is that a problem? (eval-soup (with-out-str (pprint ...)))

qqq19:03:07

also, see http://oakes.github.io/paren-soup/ <-- this is evidence you can just write code inside a div, then have eval-soup eval it for you

mobileink19:03:34

i didn't say it was a problem. just 2 different things.

samscript19:03:32

is that possible?

samscript19:03:58

I meant like just <script src="your-cloujure-stuff"></script>

samscript19:03:17

I wanna use it for work but I can't introduce a build step

samscript19:03:43

not until I can justify it first

mobileink19:03:02

@qqq i don't see any <div> in that code. it looks like a bunch of clj/cljs code. where's the html integration?

shaun-mahood19:03:16

@samscript: Self hosted clojurescript would probably be the way to go - though you will want the compile step in there before you bring it to production. What kind of thing are you trying to build with it?

mobileink19:03:12

@samscript working thru sth similar myself, you've been warned. 2 options: if you're using src="foo" in your script tag, you might as well precompile your cljs and pull in the resulting js. but if you want to support inlined/embedded cljs, you could (i think) run an in-browser cljs compiler and write js code to compile whatever is in your <script> elements. not tested, but makes sense to me! simple_smile

samscript19:03:04

@shaun-mahood : I'm currently making a SPA that's a wizard that lets you buy stuff. I want to do it with cljs

samscript19:03:00

@mobileink: I think precompiling might not be a problem. I would assume it would be impossible to use reagent or other libraries the second way right?

samscript19:03:10

@shaun-mahood I might start out real simple, re writing the carousel with cljs

noisesmith19:03:12

just using cljs.jar and compiling to js for the browser is going to be easier than self hosting the compilation in the browser

shaun-mahood19:03:08

@samscript: It seems odd to me that you can switch languages without a problem but the compilation step is a complete blocker. It really does a lot to reduce the size of your gzipped production file - so you'll probably be a lot happier if you can get that sorted out before you go live with anything.

shaun-mahood19:03:53

But I'm also lucky enough that I don't have to worry much about language or tool politics - some companies seem to have some extremely stringent and not exactly logical rules.

samscript19:03:57

@shaun-mahood: Well actually no, you can't really switch languages, that's why the compilation step is a blocker. That being said, everyone's smaller projects are their own, so if I have something that runs in the browser, it's not really a problem.

samscript19:03:44

It's hard to explain the exact atmosphere, but if at the end of the day I can deliver without alerting everyone i'm doing a new language, that's idea

mobileink19:03:37

samscript: you sneaky dog you!

mobileink19:03:01

@samscript yeah, i think that's right. precompile gives you all the global optimization grooviness of the closure compiler. but i still think there's a place for inline cljs, if only for convenience and expressivity.

samscript19:03:35

cljs.jar + cljs-watch should work

samscript19:03:32

@mobileink I learnt that from the functional-tv guy. He recommended just getting the clojure jar files and sneaking it into the next build, since no one would likely notice one more jar file

macrobartfast19:03:28

I have a general architectural question: supposing you have, say, a car reservation system that needs to check three things (say, the nearest rental place to a user, car availability there, and discounts that may apply to the user) before returning a response to the client: how is that handled in a system like om next? It seems like a common om next style approach (although things like Falcor seem similar at first glance) is to have the same ball of state on the server and a subset of that in the client, kept in sync. But I'm used to firing off a request, having a sequence of things happen in succession with various outcomes, and returning that outcome to the client, which is updated. What do I need to think about to grok this properly?

mobileink19:03:37

then there's the third way, which is that you put cljs in your script tags in your html page, and then "compile" the page to generate and compile cljs files, and remove tbe script tags. this is what i'm doing.

mobileink19:03:28

it's a little complicated. 😉 but it works.

mobileink20:03:05

@samscript do let us know what you come up with, please.

mobileink20:03:25

another question: are you writing html, or using a clojure lib like hiccup to generate html? i guess either way the recommendation from @qqq, paren-soup, looks pretty promising.

qqq20:03:09

does anyone have a guide for scripting atom in cljs ? I don't want to write my own editor from scratch; but I can't find how to script atom

shaun-mahood20:03:51

@qqq: Might be something useful in either https://github.com/jasongilman/proto-repl or http://flight-manual.atom.io/hacking-atom/ - I think at least some of proto-repl is written in CLJS

darwin20:03:06

@qqq atom is scriptable in js (they prefer to write their code in coffeescript), I ended up with a thin coffeescript glue code layer[1] and rest in cljs[2]: [1] https://github.com/darwin/plastic/tree/master/lib [2] https://github.com/darwin/plastic/tree/master/src/onion-atom/plastic/onion (at least this is how it worked 2 years ago)

qqq22:03:44

I suspect I'm not the only person who wants an Atom where the ~/.emacs.d/init.el is written in cljs instead of elisp. However, this has not been done yet. Thus I'm guessing there must be some technical obstacle to this. Any one know what the limitation to "being able to use a 'cljs-Emacs' where elisp => cljs, and Emacs Gui => Atom" is?

darwin22:03:19

your assumption is wrong, you are THE first person

qqq22:03:09

what's wrong with the rest of you? 🙂

darwin22:03:42

nothing necessarily, there is just a few thousand active cljs devs in the whole world I guess, so it is pretty plausible that nobody tackled this before, somebody has to be first (by definition)

qqq23:03:05

I'm currently learning forth. If no one does this by the time I finish learning forth, I'll consider scripting it in forth. 🙂