Writing a clojurescript REPL in clojurescript - clojure

I'm interested in embedding a clojurescript REPL in a webpage. How could I write a clojurescript evaluator in clojurescript, so that I can compile that to javascript and embed the javascript in the webpage? I can't go down the route of compiling the clojurescript to javascript in the cloud.

Now it's possible :))
http://app.gadjett.com/cljs_compiler/index-dev.html
Github
https://github.com/viebel/klipse

There's no way to do this as ClojureScript does not bootstrap itself. Currently a non-goal for the project, though I'm sure somebody could pursue the idea in a fork.

There is clojurescript.net, and the source is available here.
Or clojurescript.io, which uses re-plumb.

Related

Can I create a program in Clojure able to edit it's own code?

I am thinking of creating an educational program in Clojure that would show a console where the user could edit code in order to change a running code in another part of the screen (like a game, for instance). Would that be possible? If so, what should I study in order to be able to do this?
It is possible. See this Interactive programming Flappy Bird in ClojureScript . It uses clojurescript and figwheel as its development environment.
The awesome thing about figwheel is that you can change the flappybird running code in the browser by simply evaluating new code in the repl and then figwheel push the new code to the browser. The changes happened in real time.
You can start studying clojure and clojurescript.
Hm, changing code during runtime is one of the basic concepts behind clojure.
Watch this for more on this topic: https://www.youtube.com/watch?v=P76Vbsk_3J0
Otherwise every repl or form of a repl can do that.
To get started have a look at Lighttable: http://lighttable.com/ It has inline evaluation in the editor.

Hello World - Clojurescript

Beginner here.
Can I compile an existing Clojure script to run it on the web using ClojureScript?
Let's say that I have a script that prints Hello world in my terminal, and I want to print that text on the browser. Should I rewrite a whole script with ClojureScript syntax, or should I just compile it using another compiler?
(ns clojure-hello-world.core
(:gen-class))
(defn -main [& args]
(println "Hello World"))
(Long answer :P)
Even though Clojure and ClojureScript share a good amount of features, there are some that are specific to one or the other. For example there are no real classes in JavaScript so the :gen-class specification in the ns form doesn't make much sense.
One important fact is that the syntax of both Clojure and ClojureScript is exactly the same, differences have to do mostly with the host VM in which they run (Java VM in the case of Clojure and JavaScript VM in the case of ClojureScript).
There is a list of the differences between the two Clojure implementations here.
There's also a tool called cljx to "write a portable codebase targeting Clojure/ClojureScript". Recently there has been some discussion on the Clojure Dev group around finally implementing feature expressions which would on one hand deprecate the use of cljx but on the other complicate the work that tools have to do to extract information from Clojure source files.
I would start with lein-cljsbuild to get started. This will get you going with a nice edit eval and look at browser loop. It's well worth getting this setup first because it makes learning ClojureScript much more fun. I promise it's worth the hassle. If you need more interactive support the folks in #clojure on freenode are very kind and helpful.
Basically, the Browser executes JavaScript. You compile your ClojureScript code to JavaScript. The Browser loads your JavaScript via an HTML page. So, you have to create an HTML Page and point your Browser at it.
The simplest way I got started was to use Luminous (http://www.luminusweb.net/docs/clojurescript.md).
However, Chestnut (https://github.com/plexus/chestnut) looks promising.

What is the preferred way to use clojure for making a mobile app (Android and IOs versions)

I've already seen that there are a few tools to build mobile apps from clojure but i would like to know more details about libraries, environment, drawbacks, profiling and real working examples
Thanks
Using ClojureScript with React Native is now becoming a great answer to this question:
Performance of React Native is great.
Existing React libraries like Om and Reagent work with React Native.
You can benefit from “learn once, write anywhere” knowledge reuse.
You benefit from using a stack and language that have significant communities behind them.
And the most compelling reason: React Native allows you to write mobile apps using ClojureScript's strength as a functional language, avoiding the imperative style, mutation, and statefulness.
So far, here is my investigation result:
To create native mobile apps I've found 2 lein plugins available:
Native android: lein-droid. Let's you compile, deploy, install and live repl with usual lein commands [lein droid doall, lein droid install, lein droid compile].
Native iOS: lein-fruit. A Leiningen plugin for building native iOS apps in Clojure and Java using the RoboVM bytecode-to-native translator.
There is also another interesting way to build an iOS app in the same way that works clojurescript to obtain javascript. In this case from clojure to scheme to C with clojure-scheme
And on irc #clojure channel, David Nolen and others suggest the following paths:
[6:27pm] dnolen: tangrammer: w/ iOS you'll have better luck with the JavaScriptCore bridge and ClojureScript
[6:27pm] dnolen: tangrammer: I've tried it works great and I know other people are experimenting with it as well
[6:28pm] dnolen: tangrammer: it does limit you to iOS 7, but you could take the Ejecta approach for earlier OSs
[6:38pm] dnolen: tangrammer: core.async on iOS works great
[6:38pm] dnolen: tangrammer: you can also do multithreaded CLJS on iOS
The Why and How of Clojure on Android is a great starting point and covers this better than I could here. From what I have seen the lein-droid leiningen plugin is the easiest way to get started though the process is sometimes not entirely smooth.

Get the Clojurescript repl/connect to not compile when in production?

In my clojurescript code I have the following:
(defn onload [] (repl/connect "http://localhost:9000/repl"))
(set! (.-onload js/window) onload)
The Clojurescript repl is very useful in development, but I am hesitant to leave it in the code during production. What is the cleanest way to have the above code present during development (simple compilation), but absent during production (advanced compilation)?
The modern-cljs tutorial actually describes exactly how to solve this here.
Hope that helps!
Unfortunately there aren't currently any well defined ways to do conditional compilation in ClojureScript.
You could add configuration variables to control whether to start a REPL in a variety of ways, but one quick and easy way would be to get the hostname of the current page, and only invoke repl/connnect if it was "localhost" or whatever other domains you're using for development work.
I think a combination of lein2 profiles and cljsbuild src-paths munging can do the trick. eg, create a namespace that simply loads your repl, and exclude it with a profile run for the final compile (possibly might need to create a dummy namespace in another src-path directory).

Are there any good open source examples of JRuby + Clojure integration?

Are there any open source projects that use both JRuby and Clojure and integrate the two parts somehow?
I have never used these projects, but they should give you a starting point:
https://github.com/stilkov/jruby-rails-clojure
https://github.com/technomancy/clojure-gem
The AltLaw project (2007-2010) used JRuby and Clojure.
Example Clojure code calling JRuby
I added a Clojure REPL to Redcar Editor. It was a pretty painless process and worked just as you would expect. The source code is available on GitHub.