Fork me on GitHub
#clojurescript
<
2016-05-30
>
vikeri07:05:16

What is the fastest and or most appropriate way to parse strings to integers in cljs? cljs.reader/read-string or js/parseInt?

pesterhazy07:05:21

(defn parse-int [x]
  (let [n (js/parseInt x)]
    (if (js/isNaN n) nil n)))

vikeri07:05:48

@pesterhazy: Thanks! Any rationale?

pesterhazy07:05:23

well that uses the function provided by the runtime, which is written in C++ presumably

savelichalex07:05:42

(js/parseInt x 10) - is better

savelichalex08:05:13

when I write on js I’m use unary plus)

pesterhazy08:05:19

these two should really be added to the cljs stdlib:

(defn parse-int [x]
  (let [n (js/parseInt x 10)]
    (if (js/isNaN n) nil n)))

(defn parse-date [d]
  (let [date (js/Date.parse d)]
    (if (js/isNaN date) nil (js/Date. date))))

pesterhazy08:05:07

I'm pretty sure every cljs developers has written a version of these before

turbopape08:05:19

you could write it with if-let to eliminate some code...

turbopape08:05:38

(if-let [date (js…)] date nil)

turbopape08:05:04

I i’ve seen isNaN. Sorry.

pesterhazy10:05:32

@turbopape: yeah unfortunately NaN is truthy

ashercoren10:05:15

I want to use the :modules option in the cljs compiler in order to use web workers in my app (I want to have one module with my main app code, and a separate one for the workers). The problem is that my main app has many many namesapces. Do I have to list them all in the entries of the main module or is there a way around it?

thheller13:05:27

@ashercoren: if you are using the standard cljs :modules you will probably need a lot of tweaks for web workers

thheller13:05:28

but you'll only need to list namespaces that you want to be reachable from the "outside" (eg. HTML)

thheller13:05:37

the rest should be managed via their requires

ashercoren13:05:28

@thheller: I understand that you have a better idea for web workers, other than the standard :modules. Can you elaborate on that?

thheller13:05:05

Well not a better idea, just a different implementation of :modules

thheller13:05:43

shadow-build only injects some setup code to make it easier to work with the worker

thheller13:05:18

so it can share as much code as possible with the normal app

thheller13:05:31

all it does basically is to inject some importScripts statements at the top

thheller13:05:42

cljs itself does not do this

thheller13:05:54

tried to outline how it works in the google group

ashercoren13:05:22

I saw that thread, and was trying to work with it before realizing it was using shadow-build. Does it require much change to use that instead of the regular cljs?

thheller13:05:04

well it is more of a replacement for figwheel or cljsbuild

thheller13:05:20

it still uses all of normal cljs under the hood

thheller13:05:28

except for the build related stuff

thheller13:05:13

so yes, big change if you are used to other tools 😉

thheller13:05:34

but not on the cljs code side

thheller13:05:51

main problem with cljs :modules is that they aren't supported for :none

ashercoren13:05:21

Thank you. I will give it a try. Where is a good place to start? Some tutorial?

thheller13:05:11

well, clone the example repo and modify it for your needs and ask questions I guess

thheller13:05:24

I'm horrible at writing docs since I never know what to write

savelichalex13:05:49

Guys, I have a noobie question) What methods have cljs to work with numbers? Like js/Math

thheller13:05:53

@savelichalex: what do you mean by working with numbers?

savelichalex13:05:13

sqrt, abs etc...

thheller13:05:25

thats all in js/Math

savelichalex13:05:17

I thought cljs has his own methods...

thheller13:05:17

don't think there are, they'd probably just call the js/Math ones anyways

ryanguill14:05:04

does cljs have a different stdlib than clojure.core?

thheller14:05:28

some differences, but mostly the same

savelichalex14:05:54

goog namespace, isn’t it?

thheller14:05:19

goog is closure stuff, no counterpart in clojure

ryanguill14:05:50

sorry for the noob questions - but where is that stuff documented? my googling isn’t finding anything...

thheller14:05:06

what do you want to know? 😛

ryanguill14:05:29

just want to read through the cljs.core documentation

pesterhazy14:05:50

I don't know why this isn't more widely known

richiardiandrea14:05:02

Also @ryanguill there is http://clojurescript.io to check out, quickly accessible Repl with a doc panel

richiardiandrea15:05:44

The doc is taken from cljs-api-info btw ;)

jmmk15:05:08

Not sure if this is a bug or just a weird edge case: I am accessing variables that are defined within an iframe. When I call object? on them, it does a check (identical? (.-constructor my-variable) js/Object) which returns false. This is because js/Object is not the same as my-iframe.contentWindow.Object. I can just do the identical check myself against the iframe's Object, but it seems weird that object? returns false for something that clearly is an object.

dnolen15:05:43

@jmmk that Object is from a different context, we’re not going to make that work, object? is meant to be a fast check

dnolen15:05:59

use goog.typeOf if you need to check things across JS contexts

jmmk15:05:12

@dnolen thanks, will take a look at that

vinnyataide16:05:52

favorited the api docs, every lib should be written like that, resolved almost all my questions since i've been trying to wrap my head around

johanatan17:05:06

hi, does clojure.spec work with clojurescript yet?

dnolen17:05:18

@johanatan: cljs.spec is impemented in ClojureScript master, just not available in a release yet

johanatan17:05:05

@dnolen: ahh, ok. what's the ETA on the next release from master?

dnolen17:05:28

@johanatan: sometime this week, probably by Friday

dnolen17:05:00

however people are always encouraged to build master themselves and give things a spin

dnolen17:05:10

the best way to find bugs before a release goes out

wilkerlucio17:05:23

hey, I'm trying to generate data with cljs.spec, I added the test.check dependency and tried to use it, I'm getting this error: #object[TypeError TypeError: Cannot read property 'check' of undefined]

johanatan17:05:27

@dnolen: is there a guide on how to do that? i've never done it before

wilkerlucio17:05:55

had anyone had success generating data from specs in cljs?

johanatan17:05:37

@dnolen: oh, wow! that looks incredibly easy. thx!

dnolen17:05:08

@wilkerlucio: yes, but you need to include the test.check dependency and you need to require before trying anything

wilkerlucio17:05:19

@dnolen: I added the [org.clojure/test.check "0.9.0"] dependency and the require to [clojure.test.check], is there something else?

dnolen17:05:41

I think just requiring clojure.test.check isn’t enough

dnolen17:05:02

clojure.test.check.generators & clojure.test.check.properties

dnolen17:05:41

I’ve been pondering how to make this a bit simpler but we can’t really do runtime require like clojure.spec does so I haven’t come up with anything satisfactory yet

dnolen17:05:47

something to sort out before the release

wilkerlucio17:05:16

@dnolen: thanks, adding those requires made the trick 🙂

dnolen17:05:35

looking into making this nicer today we’ll see what I come up with

mfikes17:05:12

Evidently clojure.test.check is sufficient for this use of s/exercise:

cljs.user=> (require '[cljs.spec :as s] 'clojure.test.check)
nil
cljs.user=> (s/def ::even (s/and integer? even?))
:cljs.user/even
cljs.user=> (s/exercise ::even 1)
([0 0])

lspector18:05:23

Is there an easy way to make cljs-bootstrap accept multi-line input? At least in the version running at http://clojurescript.net if I start typing a map and hit return before finishing it I get an error.

richiardiandrea18:05:14

@lspector: check http://clojurescript.io, I assure you we have multi-line 😉

lspector18:05:25

Ooo -- I see that shift-return works

lspector18:05:32

And mult-line paste works, even with regular returns in ther -- great!

lspector18:05:57

Thanks @richiardiandrea I'll check that if I get stuck again

mfikes19:05:41

@lspector: Another advantage of http://clojurescript.io is that it is running a newer version. http://clojurescript.net is running a version that existed right after bootstrap ClojureScript was created. We’ve fixed a lot of stuff since then.

mfikes19:05:51

@richiardiandrea: 👍 to you and the others behind http://clojurescript.io. I see it has improvements including tab completion!

richiardiandrea19:05:05

Thanks Mike, we are doing our best ;)

richiardiandrea19:05:20

It has been an engaging OSS project to contribute to

lspector19:05:35

@mfikes: thanks. Interesting. I'm new here though and confused. Any orientation you can provide would be greatly appreciated. My real goal is to run a simple terminal-based app in a web page on my site. I don't really need a full REPL for this but if I have a REPL then I can easily do what I want... So I was thinking of following the instructions at https://github.com/kanaka/cljs-bootstrap/blob/master/README.md to get a page running a REPL working and then figuring out where I can stick my code that will change the normal REPL loop to my terminal-based program. Should I be using something at http://clojurescript.io rather than following the cljs-bootstrap instructions? As is probably obvious I'm not at all a javascript/web programer, although I've been writing Clojure for 6 years and programming much longer...

mfikes19:05:17

@lspector: I’m the wrong guy to answer those questions. I suspect the terminal handling aspects of these web-based REPLs is a bit disconnected from what it means to be a bootstrapped ClojureScript REPL.

lspector19:05:34

@mfikes: Thanks... Not sure what that means though 😕. But I appreciate the effort and I'll try to figure something out.

mfikes19:05:35

@lspector: There’s the concept of “being a terminal”: accepting keystrokes, printing output, etc. Many of the web-based ClojureScript REPLs actually accomplish that using techniques that differ from the stuff needed to take a ClojureScript form, evaluate it, and turn it into a result that can be printed (the bootstrapped ClojureScript aspect). The web REPLs hook both together.

lspector19:05:22

@mfikes: I think that helps. I guess I only need the "being a terminal" part of this, and I'm looking for the simplest way to make that happen, so that a pure Clojure terminal-based program can be run on a web page in a terminal-like field (by a person who knows Clojure but not Javascript or web programming).

mfikes19:05:16

@lspector: If your Clojure-based app can be compiled as ClojureScript, you can then essentially compile it all down to JavaScript to be run directly in the broswer. If you can get away with it, there may be no need for the bootstrapped aspect (which gives you the capability of compiling / evaluating ClojureScript in the browser, but at the cost of carrying along the entire ClojureScript compiler into the browser, and precluding the ability to minimize the JavaScript code size using :advanced option of the Google Closure compler).

mfikes19:05:34

@lspector: Say, for example, if you wrote a text-based adventure in Clojure.

lspector19:05:40

@mfikes: I think I could indeed get away with that... but the rub is that I don't know how to "essentially compile it all down to JavaScript to be run directly in the broswer."

lspector19:05:32

A text-adventure game is a perfect example. Suppose I have one, that runs in Clojure with a loop that calls read and println, and I can run it in a terminal on my machine via lein run, and I've ensured that everything also runs in cljs (maybe with a couple of substitutions). Then: How do I get that running in a web page?

richiardiandrea19:05:59

@lspector: maybe replumb can help in evaluating the instructions, a "terminal-based app" in a browser will maybe mean that you will need to send commands over the wire

mfikes19:05:42

Well, if @lspector’s app is self-contained, it could concievably be compiled as ClojureScript.

mfikes19:05:07

To make it simple, lets say your program reverses strings that you type in.

lspector19:05:29

@richiardiandrea: Sounds interesting but there's a lot there that I don't understand and I think is more complicated than what I need.

mfikes19:05:59

You want to have a “terminal" in the web page to let someone type in a string. You want to then pass that to your ClojureScript code to apply its functionality to the string. And then you want to put the result back in the “terminal”.

lspector19:05:24

@mfikes: Yes, string reversal is also a great example. If I could do that in a terminal-like environment (which can take multi-line input) then I'd be in great shape.

richiardiandrea19:05:52

yeah true that, just brainstorming based on a terminal-app that runs in the browser 😄

mfikes19:05:54

Right, you don’t need boostrap for that. You just need some terminal capability and your ClojureScript code compiled down to JavaScript.

mfikes19:05:31

You could probably even write your terminal code using ClojureScript, but I suspect there are JavaScript things that let you do that.

mfikes19:05:34

@richiardiandrea: http://clojurescript.io didn’t write its terminal window code in ClojureScript, right?

lspector19:05:50

Then I will substitute more interesting functionality in place of string reversal.... In the application I currently want to use this for the functionality will be some fancy mathematical inference (finding terms that perform specified operations on finite algebras), but yes, this could be used also for text adventure games, and lots of other things beginners would want to do... and which I want to do, for example letting users run evolutionary searches to solve computational problems... all of which requires only a simple terminal for interaction...

richiardiandrea19:05:32

well it could have, but we use the tested CodeMirror

richiardiandrea19:05:13

as Mike said, I think that if you want just to "drive" from the terminal you probably don't need bootstrap...bootstrap allows you to compile AND eval clojurescript in a JavaScript environment, that's it

richiardiandrea19:05:10

so if you have the requirement that you need to evaluate (+ 1 2) in the browser, with no interaction with a server, wanting all client side, then you use bootstrap

mfikes19:05:21

Here is one: http://terminal.jcubic.pl Look at the example JavaScript code. You get a command string. You can pass this command to your ClojureScript, and then take the result and call term.echo() with the resulting string.

lspector19:05:58

Thanks @richiardiandrea. I agree that I don't really need bootstrap. I think that what I do need is probably so simple and obvious to most people here that it doesn't seem worth saying, but FWIW I still have a big gap about how to get my pure Clojure/script terminal-based thing running in a web page.

mfikes19:05:37

They’ve hooked evaluation into window.eval() to have it evaluate JavaScript as a demo. Instead you could have an ^:exported ClojureScript function called to do anything with the command string.

lspector19:05:15

@mfikes: Thanks. I had looked at that terminal and it looks promising, but the Javascript stuff isn't comprehensible to me, I don't know where to stick my Clojure code, or what to compile, and all that.

richiardiandrea19:05:20

ok no, wait, if you want a terminal-based thing in a webpage then you do need bootstrap right? Like http://clojurescript.io 😉

richiardiandrea19:05:15

I am maybe lost in requirements now 😄

mfikes19:05:49

No… @lspector just wants a window where someone can type a string, and then that string is passed to some ClojureScript code to, say call (apply str (reverse command)) and then put the result back into the terminal.

richiardiandrea19:05:25

kk clear...then yes unless the string is a ClojureScript form to compile down to JS and evaluate you don't need bootstrap facilities

mfikes19:05:30

In that example @lspector’s code would be AOT compiled to JavaScript and look like a minified version of cljs.core.apply.call(null,cljs.core.str,cljs.core.reverse.call(null,command))

richiardiandrea19:05:04

ahahah Mike is compiling it already

mfikes19:05:23

@lspector’s difficulty is in hooking it all together, using the ClojureScript toolchain, etc.

lspector19:05:24

@mfikes: exactly. Maybe it would help to imagine (not accurately) that I just learned to program a month ago, Clojure is my first language, and I made a spiffy text adventure game that I want to share with the world on a web page. What minimal instructions would let me run this in a web page, given that I don't know Javascript or anything else (but I can follow instructions and move something to a web server).

mfikes19:05:51

@lspector: I’d recommend taking a look at the Quick Start. It shows you how to get your code into a page.

lspector19:05:09

(In truth I've been programming a long time in many languages, but that hypothetical is close to true re: Javascript for me.)

mfikes19:05:43

Then you can use something like that fancy JQuery thing I linked to above to provide a terminal, and when that JQuery thing gives you a string, you have a tiny bit of JavaScript glue to call your ClojureScript code.

mfikes19:05:10

Quick Start is definitely a good foundation, though.

lspector19:05:44

@mfikes: I've gone through the quick start but it doesn't give you a terminal. Output to the console only, and then stuff that requires knowing Javascript to do anything on the page, if I recall correctly.

mfikes19:05:09

Where it calls window.eval, you’d replace it with my.namespace.process(command)

lspector19:05:22

So the part I am missing is exactly how I would wire up the JQuery thing and make it call my code. Again, I suspect this is too simple to think you need to say if you know what you know....

lspector19:05:33

Okay, I'm going to try to find that piece of code...

mfikes19:05:35

I think it is one line of code to change to hook it in.

mfikes19:05:03

Not saying this is the best terminal. It is the first one I saw via Google. 🙂

lspector19:05:23

Any terminal would be fine... although I do want multi-line input

richiardiandrea19:05:06

also jqconsole is a good one with multiline (it is the one http://clojurescript.net is using)

mfikes19:05:25

Or, just put a text field on the page with a big ENTER button next to it 🙂

mfikes20:05:02

Believe me, @lspector , I’m with you… I don’t know the web stack 🙂

mfikes20:05:47

While I’ve done a lot with ClojureScript, for me it has always been outside of the web stack. 😜

lspector20:05:23

I went down the path of "a text field on the page with a big ENTER button next to it" last week, which got me to #C08BDAPRA, which worked but was clunky because I was fighting a lot of the spiffy features of hoplon that I don't really want, connecting interface elements to each other etc. I was able to make my code run in a web page, though, so that was good. But I realized that a terminal interface would be more natural and better for my application and also way more general, that lots of people may want to use (and that I'd use for other projects). So I'm trying to get the terminal idea working.

lspector20:05:52

Meanwhile, right now I don't even see where that code to change is... It's not on the Quick Start page, but in code that gets created when you follow those instructions? I can't seem to find the old project so I guess I'll have to go through the instructions again.

mfikes20:05:55

@lspector: The main idea is that you compile your ClojureScript code to JavaScript, and have it loaded into the browser (as is done in Quick Start), and the it is there, in the JavaScript engine in the browser, waiting to be called upon. You can then use something to get a string from the user (a text field with an ENTER button, or a terminal supporting multi-line entry), and once the event occurs that the user has supplied a string, you glue that event to call your exported ClojureScript function, which does whatever it wants and returns a string. Your glue code then puts that string in the UI (renders it in the page, or passes it to whatever terminal emulator you are using for display).

lspector20:05:16

@mfikes: Thanks. All of that sounds exactly right. I wish there was a path here for the person who knows only Clojure and can't write the glue without learning another language.

mfikes20:05:09

Nah, don’t learn JavaScript. Just figure out enough of it to hook things together.

mfikes20:05:59

I’ve gotten a lot of mileage out of that philosophy 🙂

richiardiandrea20:05:02

I found this: https://github.com/benzap/fluch, maybe you can find some inspiration there too

mfikes20:05:26

Yes. I was looking at the same thing 🙂

benzap20:05:36

woah, I got mentioned?

mfikes20:05:44

@benzap: Yes, if your terminal is workable, @lspector wants one 🙂

richiardiandrea20:05:00

everybody is a rock star here 😄

mfikes20:05:34

The main use case is: “I wrote a command line program in Clojure, and I want to toss it in a web page.” Simple enough.

benzap20:05:36

hmm, I don't know if that was where I was going with it, but i'll look into how I might get it working in clojure as well 🙂

mfikes20:05:40

The example is: My program accepts a string from the user. It then reverses it, and prints it to stdout.

lspector20:05:50

I realize I don't need to know all of JavaScript, but I don't know what I do/don't need to learn or how to learn just the parts I need. Although I realize that this may come off as lazy and selfish :-O, I'd like to learn exactly none of it, if possible, and just be able to paste my working Clojure terminal code somewhere, issue a magic command or two, and have my code running in a terminal in a web page. I'm old enough that running a terminal-based program was the default for every language environment (well, actually I wrote punch card programs too!), and so it sort of seems natural to me that there should be a simple way to do this always... and that for Clojurescript that would be in a web page...

benzap20:05:54

hmm... for the project, i'm trying to get it to the point where I could write ncurses inspired apps in a browser

benzap20:05:06

hence the "Terminal Emulator with $#!*%& "

mfikes20:05:16

If you can do punchcards, you can hook a tiny bit of JavaScript to ClojureScript 🙂

mfikes20:05:08

I’m too old to deal with JavaScript… I don’t plan on learning it myself.

mfikes20:05:19

Life’s too short.

lspector20:05:34

@benzap: @mfikes's examples are spot on, but also think more generally how great it would be if anyone who can write a text adventure game that would run in a terminal in Clojure with lein run could slap it into a template and issue a command and make it run in a web page. And then instead of a text adventure game, something that does fancy mathematical problem solving, or whatever floats your boat.

benzap20:05:07

that sounds pretty useful

lspector20:05:10

Punch cards were not fun. Except they spun in really cool ways if you threw a deck of them off the top of a tall building 🙂

lspector20:05:49

I do think this would be useful. I teach computer science (including Clojure) and I'm sure my students would love a way to do this. And I have a bunch of projects (like the genetic programming code I described at Clojure/Conj 2015) that I'd love to make available for the world to run in a terminal in a web page.

mfikes20:05:27

Actually, @benzap, @lspector’s use case isn’t actually to run Clojure. I think it would be a ClojureScript program that essentially wants access to stdin, stdout, in some fashion.

mfikes20:05:36

FWIW a path I went down with Planck is to augment the existing *out* with *in* and *err* and all of the machinery to imitate .

mfikes20:05:43

Then it is possible to build things like read-line atop that stuff.

benzap20:05:01

interesting, i'll have to look into it 🙂

mfikes20:05:01

Perhaps *in* would make sense in fluch, dunno

benzap20:05:16

would be neat for teaching clojurescript as well. include tools.reader for the clojurescript compiler, and have lessons that imitate a lot of what you see for teaching the scratch programming language

lspector20:05:17

Yes, @mfikes, that is right -- I just want to run a ClojureScript program that interacts with the user in a terminal, using something roughly equivalent to Clojure's read-line, read, print, and println.

lspector20:05:01

For concreteness, if a Clojure/script programmer writes this:

(defn interact
  []
  (print "Type one line: ")
  (flush)
  (println "Backwards, that line is: " (apply str (reverse (read-line))))
  (print "Type a Clojure map: ")
  (flush)
  (println "The values are: " (vals (read))))

lspector20:05:21

Which runs in a terminal with lein run when put in a Clojure project with a -main function like this:

(defn -main
  [& args]
  (interact))

lspector20:05:51

Then how can that programmer make this run in a terminal in a web page, without learning Javascript?

deactivateduser20:05:53

I was searching, but could find any blog post about the performance difference between running the "same" code with clojure on jvm and clojure script on node.js, do you know any websites on this topic? even if it is just some micro benchmark I would like to read about it

lspector20:05:29

@benzap & @mfikes: and note in that interact example the map that the user enters could span multiple lines. Ideally the terminal in a web page would allow that too.

mfikes20:05:30

@lspector: Your interact example can be made to work in Planck 🙂

cljs.user=> (defn interact
       #_=>   []
       #_=>   (print "Type one line: ")
       #_=>   (flush)
       #_=>   (println "Backwards, that line is: " (apply str (reverse (read-line))))
       #_=>   (print "Type a Clojure map: ")
       #_=>   (flush)
       #_=>   (println "The values are: " (vals (read))))
#'cljs.user/interact
cljs.user=> (interact)
Type one line: hello
Backwards, that line is:  olleh
Type a Clojure map: {:a 1 :b 2}
The values are:  (2 1)
nil
So, it could probably work in a web page 🙂

benzap20:05:45

@lspector, for my first stab at it, you would have a static web server running in the background, along with lein cljsbuild auto, with your project.clj pointing at :main example.core.main

benzap20:05:24

a lein plugin would probably be better suited to do the static web server setup

benzap20:05:32

and have it run from -main

mfikes21:05:36

@deactivateduser624417: My experience has been that, if you type hint Clojure, you can generally make it run faster than ClojureScript. But, sometimes ClojureScript is faster owing to the tremendous job JavaScript engines do with automatically detecting types, and compiling down to machine code.

lspector21:05:47

@benzap -- interesting... but I don't understand fully. I put things on the web by throwing .html files in my public directory on my institution's website. They're served by whatever my institution is running. For the #C08BDAPRA experiment I did, I put the stuff that resulted from their getting started instructions in my public directory and it ran fine, without any plugins or other servers or anything like that. It's just that what I got was a #C08BDAPRA thing with input/output fields and a button rather than a terminal field. I'd like to get a terminal field instead... Will this really require understanding stuff like running additional servers?

benzap21:05:45

@lspector: hmm, the problem is that most languages came from a time when a terminal and a console were the first thing you usually saw. Javascript comes from making webpages more dynamic, so javascript inherently doesn't really have anything for terminal input/output. I'm hoping to emulate that behaviour fluch to some extent as suggested by @mfikes

benzap21:05:36

However, I think if someone wrote a plugin to make it so that they run this plugin to generate a static web page with all the bells and whistles, it could be as simple as throwing your code in the -main function and running a closely resembled lein run

benzap21:05:55

maybe a lein plugin called lein-webterminal, and you run lein webterminal run which spawns a static web server with additional stuff for spawning fluch, and running the -main function

lspector21:05:23

@benzap It must not be terribly hard to make Clojurescript/Javascript do this because the bootstrap examples do everything I want and more (I don't need the bootstrap part, just the terminal part). And in plain Javascript http://terminal.jcubic.pl does all I want but I don't know how to glue it to my Clojurescript code.

lspector21:05:38

@benzap, your suggestion would mean that I would have to run that command on the server, and keep that process running (and restart it if the system goes down), etc? I'm pretty sure that what I'm looking for can be done by having nothing running on my server but the main webserver which hands out .html and .js files. At least, I was able to get the #holon version of what I want working without running anything on the server, and the only problem with that was that I had separate UI elements for input/output/run, rather than a terminal field which is the more general solution that I would like to have.

mfikes21:05:00

@lspector: It is nearly a one-line change, if you don’t really need full stdin/stdout, nor multi-line. In other words, you can get a string, and have your ClojureScript code process it, and then put it back out to the terminal.

mfikes21:05:17

The challenging aspect is if you want read-line and friends.

mfikes21:05:24

And if you do everything in ClojureScript (combined with perhaps some JavaScript), the server can serve up static files.

mfikes21:05:13

(I say “challenging” because ClojureScript doesn’t come with machinery to cope with stdin/stdout like —but it can be built in ClojureScript.)

lspector21:05:35

@mfikes: It will be hard to get by without multiline, but if I can get everything else then I'd like to pursue this. But what line, in what file, would I change, to what? And where would my own Clojurescript go?

lspector21:05:30

I'm going to go through the getting started instructions again, but from looking back at it I remember that it has you do and then undo/redo things so it will take a bit for me to recreate the stuff that I expect will have the code that I'm supposed to change.

mfikes21:05:48

In the terminal.jcubic.pl example, you change window.eval(command) to call upon your exported ClojureScript function (whatever you name it).

mfikes21:05:19

Like my.namespace.reverse_string(command)

lspector21:05:37

I must be looking at the wrong place... I don's see mention of this example at https://github.com/clojure/clojurescript/wiki/Quick-Start

lspector21:05:08

I see that image... but where does the code come from? Will it be in a project that results from following the instructions at https://github.com/clojure/clojurescript/wiki/Quick-Start?

mfikes21:05:44

Scroll down to Demo and look at the JavaScript box

mfikes21:05:36

If you type 1+1 in that Demo box, it will pass that string to the JavaScript engine via window.eval(command) and that will result in 2, which will be put in the terminal.

mfikes21:05:58

If you hooked that call to ClojureScript, you could have the ClojureScript program do anything with the string.

lspector21:05:42

Ah -- okay. So I should follow the instructions at http://terminal.jcubic.pl, and that will produce a file that contains window.eval(command) which I should change to my.namespace.reverse_string(command) but instead of my.namespace.reverse_string it should be the name of some Clojurescript function... the code for which I put where? And compile how (maybe following instructions at https://github.com/clojure/clojurescript/wiki/Quick-Start) and put in the same folder? Sorry to be so dense, but it's all of these probably-obvious glue parts that I am completely clueless about

mfikes21:05:49

Of course, the real problem with this is that it is the pattern of “type a command, process it, spit the result out”. It is not stdin/stdout like yo want.

mfikes21:05:47

Yes, @lspector you are on the right path. If you combined http://terminal.jcubic.pl with the ideas from Quick Start you could imagine cobbling together something that uses ClojureScript to reverse strings.

mfikes21:05:25

And, yes, you could use Quick Start to compile… it talks about how to do that.

lspector21:05:04

Well, I guess stdin/stdout would be better... or whatever the bootstrap examples are using would be 100% fine, so maybe I ought to revert to that, and get bootstrap which I don't need, just because the instructions there will, I think, get me a REPL which I can then use to make a Terminal app. Using a chainsaw when a pair of pliers will do, but I don't know how to work the pliers and it looks like there are clear instructions for the chain saw.

lspector21:05:11

@mfikes: yes, I could "imagine" cobbling that together but sometimes my imagination is a bit unmoored from reality 🙂. I'll look into it more, but at the moment it feels like going back to bootstrap may be the shortest route to a workable solution.

mfikes21:05:59

What you really want is an environment that lets you call read-line and read.

lspector21:05:59

@mfikes: yes, but bootstrap must be doing that to implement its REPL. I don't need the E, but the R_PL is what you need for a simple terminal app.

mfikes21:05:40

@lspector: I’m assuming you want to be able to execute code like interact.

lspector21:05:24

Yes, interact is a simple example but if I could do that then I could do something with a loop, and much more interesting processing to produce outputs from the users' inputs.

lspector21:05:31

Note: I don't want the user to be able to call interact -- I want a web page in which something like interact is running in a field, e.g. showing the first prompt when the window is opened, and then responding in the field and re-prompting, etc.

lspector21:05:25

@mfikes: The read-line in Planck looks promising... but again, what I don't know is where to use this, with what glue, etc.

mfikes21:05:04

I’m just saying that Planck is an existence proof that you can write terminal apps using ClojureScript. You just need some extra code like Planck has to conspire to give you stdin.

lspector21:05:42

@mfikes: Ah -- that's great then!

mfikes21:05:02

Making a Planck-like thing with stdin support that can run in a terminal simulation in a browser is possible. I’d call that more than “cobbling” though.

mfikes21:05:24

Just saying it is possible. And perhaps very useful.

lspector21:05:35

Hmmm... If it's more than "cobbling" to you, then I think it's not something I can do myself right now.

lspector21:05:54

I've got some code I need to put in a web page soon, without having time to learn much new stuff, and I think the lesson for me for today may be that I should use clj-bootstrap even though it does a lot that I don't need, and that I should dig into it to figure out where its read-eval-print-loop is and replace that with my own code that does my read-[something-other-than-eval]-print-loop.

lspector21:05:31

Does that strike you as reasonable?

lspector21:05:51

Longer term (and for others) I think there's an opportunity here because I think that there would be a lot of takers (esp in education, but in other contexts as well) for a simple way, that doesn't rely on Javascript/web-programming knowledge, to get a terminal-style Clojurescript program running in a browser.

lspector21:05:26

Thanks @mfikes, that's what I'll try next.

mfikes21:05:06

@lspector: If done right, a library/stack that supports that could trivially make it possible to run the same ClojureScript programs, un-modified, on mobile devices as well.

mfikes21:05:03

console mode for ClojureScript

lspector21:05:28

@mfikes: the mobile idea sounds cool, but FWIW I'd be 90+% satisfied even if it ran only on desktops, only on one specific browser, even if it was hideously ugly, etc. The gap between "Non-programmer users can run my terminal-based thing in their browsers" and "Nobody can run it except me on my computer and others who can deal with installing Clojure on their own machines" is the huge one that I really want to close. Beyond that it's just gravy.

lspector23:05:44

Trying to use cljs-bootstrap to put a minimal terminal-based program in a web-page, as per discussion above with @mfikes. Following instructions at https://github.com/kanaka/cljs-bootstrap/blob/master/README.md, when I do time ./script/build it looks like it is dying with ./script/aot_core: line 7: mvn: command not found. Makes me think "maven" but I don't know from maven. Any help?

gastove23:05:10

Might just need to install maven

richiardiandrea23:05:11

@lspector: maybe you just need to install maven

gastove23:05:52

(`mvn` is definitely the command for maven — on OSX you can just brew install maven.)

gastove23:05:43

I haven’t got a clue why that thing would want it tho 😕

lspector23:05:49

So I've not previously used brew... and now I'm down a rabbit hole trying to install brew so I can install maven...

gastove23:05:26

Oh blarg — there’s a buncha other ways you can get that done. D’you use ports? Prefer a straight installer?

lspector23:05:27

Error: Failure while executing: git clone https://github.com/Homebrew/homebrew-core /usr/local/Library/Taps/homebrew/homebrew-core --config core.autocrlf=false --depth=1 Failed during: /usr/local/bin/brew tap homebrew/core

lspector23:05:44

A straight installer sounds nice

lspector23:05:05

Thanks @gastove -- trying now

lspector23:05:49

Okay -- maven installed -- thanks

lspector23:05:42

A couple steps later: Unable to find npm on your path. Please install it. Any ideas?

gastove23:05:46

npm is the Node Package Manager. Again, available via brew, or from the fine folk at https://www.npmjs.com/

lspector23:05:21

Ah. I see. So one has to buy this? Can't build cljs-bootstrap without doing so?

gastove23:05:43

Uh no, no purchasing. Free as a song.

gastove23:05:01

Oh, look, that page isn’t very helpful. Erhm, sec.