Reputation: 58786
The documentation seems quite sparse in LightTable. I want to create a very bare bones ClojureScript web application in LightTable as a starting point to build on. I have the Instarepl in Clojure working fine, and then I create a new file called dummy.cljs containing the following:
(ns dummy)
(js/alert "Hello lighttable")
How can I run this?
I have figured this out now, and I will post a video on how todo it as it is quite visual.
Here is the video:
http://www.youtube.com/watch?v=GZ6e0tKqYas
Upvotes: 15
Views: 5648
Reputation: 190859
Well, LightTable is good as REPL in development phase, but when you're done, you need to compile the ClojureScript to be executed (i.e., with node.js).
Then, you can give the ClojureScript expression, and evaluate it with command-enter or shift-command-enter key (with Mac OS X).
The simplest way is to use lein, but if you don't want to use lein, this is one of the possible ways.
Or download a newer version if available.
└── src
├── build.clj
└── smcho
└── core.cljs
build.clj is as follows, you can change the namespace and accordingly the directory name as necessary.
(require 'cljs.build.api)
(cljs.build.api/build "src"
{:main 'smcho.core
:output-to "main.js"
:target :nodejs})
This is ClojureScript code; the main method is added.
(ns smcho.core
(:require [cljs.nodejs :as nodejs]))
(nodejs/enable-util-print!)
(defn factorial [x]
(reduce * (range 1 (inc x))))
(defn fib [n]
(if (<= n 1)
1
(+ (fib (- n 1)) (fib (- n 2)))))
(defn sort-seq []
(sort (repeat 100 (rand-int 2000))))
(defn time-fun [fun]
(let [start (.getTime (js/Date.))
_ (fun)
end (.getTime (js/Date.))
result (- end start)]
result))
(defn time-it [fun]
(let [values (for [i (range 200)] (time-fun fun))]
(/ (apply + values)
(count values))))
(defn -main []
(println "(factorial 5000) \t Avg: " (time-it #(factorial 5000)))
(println "(fib 20) \t Avg: " (time-it #(fib 20)))
(println "(sort-seq) \t Avg: " (time-it #(sort-seq))))
(set! *main-cli-fn* -main)
java -cp cljs.jar:src clojure.main src/build.clj
node main.js
This will show the execution results.
(factorial 5000) Avg: 0.65
(fib 20) Avg: 0.135
(sort-seq) Avg: 0.135
The example code is copied from http://blog.gonzih.me/blog/2013/01/23/clojurescript-on-beaglebone-simple-benchmark-with-node-dot-js/ .
Upvotes: 3
Reputation: 3883
To use light table with clojurescript, one difference from clojure project is:
If I connect some page with browser (internal or external), I need to run:
lein cljsbuild auto
in terminal.
otherwise, the goog related js can not be found.
You can check from here:
https://groups.google.com/forum/#!topic/light-table-discussion/fJBLMzmZSWw
Upvotes: 1
Reputation: 773
lein ring server
and lein cljsbuild auto
, in order to run local web-server with clojurescript autocompileSimpler way would be using http://clojurescriptone.com/ and lein repl as main development tool and use LT only as additional tool for solving some small problems within one-two files.
Upvotes: 14