Giter VIP home page Giter VIP logo

lt-cljs-tutorial's Introduction

Light Table ClojureScript Tutorial

An introduction to the ClojureScript programming language aimed at Light Table users. If you have an old version of Light Table, you may need to upgrade to 0.6.X or newer.

Install Leiningen. You can then open lt-cljs-tutorial.cljs in Light Table and evaluate it interactively by adding a Light Table UI connection as explained in the tutorial.

I hope this can be a kind of ClojureScript wiki of sorts for Light Table users. Pull requests welcome.

For users of editors/IDEs supporting nREPL there is a port of this tutorial targeting those development environments as well.

lt-cljs-tutorial's People

Contributors

ajschumacher avatar blakejakopovic avatar bruceadams avatar casidiablo avatar dechov avatar djebbz avatar ikr avatar jballanc avatar jimt avatar justinhj avatar magomimmo avatar mattsonlyattack avatar minikomi avatar mtrimpe avatar onthestairs avatar priyatam avatar rickhall2000 avatar rreas avatar rtorr avatar swannodette avatar tgvashworth avatar thangmai avatar ultimapanzer avatar zaiste avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lt-cljs-tutorial's Issues

Things I didn't understand

Coming from a background of very little lisp and no clojure. If I'm not part of the target audience, then feel free to ignore these comments. Most of the tutorial was comprehensible and very instructive, however.

loop/recur not sure what's happening - is it a macro? b/c it doesn't look like a function call. What's the syntax mean?

defmulti the syntax is totally opaque to me.

protocols...are polymorphic functions? What's the difference between a protocol and a function? Or is that all it is? A bit more explanation would be much appreciated. For example, what's the significance of the word this in the following (defprotocol MyProtocol (awesome [this])). Changing it to "thing" or "cat" seems to have no effect.

Maybe if you showed the "ILookup" protocol definition or something it would make more sense.

Is there any difference between (extend-protocol protocol type ...) and (extend-type type protocol ...)?

Fantastic tutorial, on the whole!

Error on first eval

I'm getting an error upon evaluating that very first namespace form:

"Invalid behavior: :lt.plugins.clojure/eval!"
TypeError: Cannot call method 'call' of undefined
    at notify (/opt/LightTable/plugins/clojure/clojure_compiled.js:1259:24)
    at check_all (/opt/LightTable/plugins/clojure/clojure_compiled.js:1274:83)
    at run_local_server (/opt/LightTable/plugins/clojure/clojure_compiled.js:1209:110)
    at try_connect (/opt/LightTable/plugins/clojure/clojure_compiled.js:347:45)
    at lt.objs.eval.find_client (file:///opt/LightTable/core/node_modules/lighttable/bootstrap.js:29877:16)
    at lt.objs.eval.get_client_BANG_ (file:///opt/LightTable/core/node_modules/lighttable/bootstrap.js:29907:32)
    at Function.__BEH__eval_BANG_ (/opt/LightTable/plugins/clojure/clojure_compiled.js:412:69)
    at c (file:///opt/LightTable/core/node_modules/lighttable/bootstrap.js:6196:14)
    at a (file:///opt/LightTable/core/node_modules/lighttable/bootstrap.js:6236:18)
    at lt.object.raise_STAR_ (file:///opt/LightTable/core/node_modules/lighttable/bootstrap.js:17890:74)

No reader function for tag js

Is the error that I get. I am connected to LightTable UI, and have attempted to evaluate the first form.

I'm guessing this is a dumb error on my part, but since this is a tutorial for first-timers I figured I'd ask.

Some obscurities

This snippet on exceptions is obscure. How, exactly, does :default work as a catch-all here, and does it have wider application? I know it is used in multi-methods, but have not found any other references to it.

;; JavaScript unfortunately allows you to throw anything. You can handle
;; this in ClojureScript with the following.

(try
  (throw (js/Error. "Oops"))
  (catch :default e
    e))

I have had to track down the following syntax once before, and I think it deserves more explanation.

;; We can use property access with `set!` to change the fill color of a
;; a canvas rendering context.

(set! (.-fillColor ctxt) "#ffffff")

I'm talking about the .-fillColor.

Clarify naming of Js types when extending them with protocols

Starting from here, you show examples of extensions of native Javascript objects. But syntax is not clear :

(extend-type string ...)
(extend-type js/Date ...)
(extend-type number ...)

In Javascript, string and number are written String and Number. Why are they lowercase here whereas Date is accessed through js and with the normal Javascript case ?

Confusion from extend-type/extend-protocol example

https://github.com/swannodette/lt-cljs-tutorial/blob/master/lt-cljs-tutorial.cljs#L1335-L1355

These lines of code and comments seem to suggest that there is some sort of real difference between extend-type and extend-protocol:

;; Or you can extend a protocol on a defrecord.

I wasn't sure, so I read up on them in the docs. The docs for extend-protocol state:

Useful when you want to provide several implementations of the same
protocol all at once. [...] Expands into calls to extend-type

So am I right in assuming that extend-protocol is but a convenience macro that always expands to extend-type calls? If so, the marked lines seem a little bit odd, as we're getting nothing out of using extend-protocol instead of extend-type for a single defrecord, the syntax just seems flipped around and it left me thinking there was a fundamental difference between the two.

Fails evaluating namespace with "We couldn't connect"

I tried running the lt-cljs-tutorial (freshly cloned) on a new Mac (OS X 10.13.1) and new d/l of LightTable 0.8.1.

After adding the connection as directed I tried evaluating the namespace form and got the output below. I have run all this before without a problem on another platform. Has something changed?

We couldn't connect.

Looks like there was an issue trying to connect to the project. Here's what we got:
final project: {:description A local light table project, :compile-path /private/var/folders/p7/glb8sl9d6vz8y10f0vw493n00000gn/T/AppTranslocation/76839D72-2CAE-4778-BEA4-995C1631A8B8/d/LightTable.app/Contents/Resources/app/plugins/Clojure/runner/resources/target/classes, :deploy-repositories [[clojars {:url https://clojars.org/repo/, :password :gpg, :username :gpg}]], :group local-client, :resource-paths (/private/var/folders/p7/glb8sl9d6vz8y10f0vw493n00000gn/T/AppTranslocation/76839D72-2CAE-4778-BEA4-995C1631A8B8/d/LightTable.app/Contents/Resources/app/plugins/Clojure/runner/resources/dev-resources /private/var/folders/p7/glb8sl9d6vz8y10f0vw493n00000gn/T/AppTranslocation/76839D72-2CAE-4778-BEA4-995C1631A8B8/d/LightTable.app/Contents/Resources/app/plugins/Clojure/runner/resources/resources), :uberjar-merge-with {META-INF/plexus/components.xml leiningen.uberjar/components-merger, data_readers.clj leiningen.uberjar/clj-map-merger, #"META-INF/services/." [clojure.core/slurp (fn [p1__949__951__auto__ p2__950__952__auto__] (clojure.core/str p1__949__951__auto__
p2__950__952__auto__)) clojure.core/spit]}, :name local-client, :checkout-deps-shares [:source-paths :test-paths :resource-paths :compile-path #'leiningen.core.classpath/checkout-deps-paths], :source-paths (/private/var/folders/p7/glb8sl9d6vz8y10f0vw493n00000gn/T/AppTranslocation/76839D72-2CAE-4778-BEA4-995C1631A8B8/d/LightTable.app/Contents/Resources/app/plugins/Clojure/runner/resources/src), :eval-in :subprocess, :repositories [[central {:url https://repo1.maven.org/maven2/, :snapshots false}] [clojars {:url https://clojars.org/repo/}]], :test-paths (/private/var/folders/p7/glb8sl9d6vz8y10f0vw493n00000gn/T/AppTranslocation/76839D72-2CAE-4778-BEA4-995C1631A8B8/d/LightTable.app/Contents/Resources/app/plugins/Clojure/runner/resources/test), :target-path /private/var/folders/p7/glb8sl9d6vz8y10f0vw493n00000gn/T/AppTranslocation/76839D72-2CAE-4778-BEA4-995C1631A8B8/d/LightTable.app/Contents/Resources/app/plugins/Clojure/runner/resources/target, :prep-tasks [javac compile], :native-path /private/var/folders/p7/glb8sl9d6vz8y10f0vw493n00000gn/T/AppTranslocation/76839D72-2CAE-4778-BEA4-995C1631A8B8/d/LightTable.app/Contents/Resources/app/plugins/Clojure/runner/resources/target/native, :offline? false, :root /private/var/folders/p7/glb8sl9d6vz8y10f0vw493n00000gn/T/AppTranslocation/76839D72-2CAE-4778-BEA4-995C1631A8B8/d/LightTable.app/Contents/Resources/app/plugins/Clojure/runner/resources, :pedantic? ranges, :clean-targets [:target-path], :plugins [], :plugin-repositories [[central {:url https://repo1.maven.org/maven2/, :snapshots false}] [clojars {:url https://clojars.org/repo/}]], :version 0.0.1, :jar-exclusions [#"^."], :global-vars {}, :uberjar-exclusions [#"(?i)^META-INF/[^/].(SF|RSA|DSA)$"], :jvm-opts [], :dependencies ([org.clojure/clojure 1.5.1] [org.clojure/tools.nrepl 0.2.10 :exclusions ([org.clojure/clojure])] [clojure-complete/clojure-complete 0.2.3 :exclusions ([org.clojure/clojure])] [lein-light-nrepl/lein-light-nrepl 0.1.3] [lein-light-nrepl-instarepl/lein-light-nrepl-instarepl 0.3.1]), :release-tasks [[vcs assert-committed] [change version leiningen.release/bump-version release] [vcs commit] [vcs tag] [deploy] [change version leiningen.release/bump-version] [vcs commit] [vcs push]], :repl-options {:nrepl-middleware [lighttable.nrepl.handler/lighttable-ops], :init (clojure.core/swap! lighttable.nrepl.core/my-settings clojure.core/merge {:name LightTable-REPL, :project (quote {:description A local light table project, :compile-path /private/var/folders/p7/glb8sl9d6vz8y10f0vw493n00000gn/T/AppTranslocation/76839D72-2CAE-4778-BEA4-995C1631A8B8/d/LightTable.app/Contents/Resources/app/plugins/Clojure/runner/resources/target/classes, :deploy-repositories [[clojars {:url https://clojars.org/repo/, :password :gpg, :username :gpg}]], :group local-client, :resource-paths (/private/var/folders/p7/glb8sl9d6vz8y10f0vw493n00000gn/T/AppTranslocation/76839D72-2CAE-4778-BEA4-995C1631A8B8/d/LightTable.app/Contents/Resources/app/plugins/Clojure/runner/resources/dev-resources /private/var/folders/p7/glb8sl9d6vz8y10f0vw493n00000gn/T/AppTranslocation/76839D72-2CAE-4778-BEA4-995C1631A8B8/d/LightTable.app/Contents/Resources/app/plugins/Clojure/runner/resources/resources), :uberjar-merge-with {META-INF/plexus/components.xml leiningen.uberjar/components-merger, data_readers.clj leiningen.uberjar/clj-map-merger, #"META-INF/services/." [clojure.core/slurp (fn* [p1__949__951__auto__ p2__950__952__auto__] (clojure.core/str p1__949__951__auto__
p2__950__952__auto__)) clojure.core/spit]}, :name local-client, :checkout-deps-shares [:source-paths :test-paths :resource-paths :compile-path #'leiningen.core.classpath/checkout-deps-paths], :source-paths (/private/var/folders/p7/glb8sl9d6vz8y10f0vw493n00000gn/T/AppTranslocation/76839D72-2CAE-4778-BEA4-995C1631A8B8/d/LightTable.app/Contents/Resources/app/plugins/Clojure/runner/resources/src), :eval-in :subprocess, :repositories [[central {:url https://repo1.maven.org/maven2/, :snapshots false}] [clojars {:url https://clojars.org/repo/}]], :test-paths (/private/var/folders/p7/glb8sl9d6vz8y10f0vw493n00000gn/T/AppTranslocation/76839D72-2CAE-4778-BEA4-995C1631A8B8/d/LightTable.app/Contents/Resources/app/plugins/Clojure/runner/resources/test), :target-path /private/var/folders/p7/glb8sl9d6vz8y10f0vw493n00000gn/T/AppTranslocation/76839D72-2CAE-4778-BEA4-995C1631A8B8/d/LightTable.app/Contents/Resources/app/plugins/Clojure/runner/resources/target, :prep-tasks [javac compile], :native-path /private/var/folders/p7/glb8sl9d6vz8y10f0vw493n00000gn/T/AppTranslocation/76839D72-2CAE-4778-BEA4-995C1631A8B8/d/LightTable.app/Contents/Resources/app/plugins/Clojure/runner/resources/target/native, :offline? false, :root /private/var/folders/p7/glb8sl9d6vz8y10f0vw493n00000gn/T/AppTranslocation/76839D72-2CAE-4778-BEA4-995C1631A8B8/d/LightTable.app/Contents/Resources/app/plugins/Clojure/runner/resources, :pedantic? ranges, :clean-targets [:target-path], :plugins [], :plugin-repositories [[central {:url https://repo1.maven.org/maven2/, :snapshots false}] [clojars {:url https://clojars.org/repo/}]], :version 0.0.1, :jar-exclusions [#"^."], :global-vars {}, :uberjar-exclusions [#"(?i)^META-INF/[^/]*.(SF|RSA|DSA)$"], :jvm-opts [], :dependencies ([org.clojure/clojure 1.5.1] [org.clojure/tools.nrepl 0.2.10 :exclusions ([org.clojure/clojure])] [clojure-complete/clojure-complete 0.2.3 :exclusions ([org.clojure/clojure])]), :release-tasks [[vcs assert-committed] [change version leiningen.release/bump-version release] [vcs commit] [vcs tag] [deploy] [change version leiningen.release/bump-version] [vcs commit] [vcs push]], :test-selectors {:default (constantly true)}})})}, :test-selectors {:default (constantly true)}}
java.io.IOException: Permission denied. Please check your access rights for /private/var/folders/p7/glb8sl9d6vz8y10f0vw493n00000gn/T/AppTranslocation/76839D72-2CAE-4778-BEA4-995C1631A8B8/d/LightTable.app/Contents/Resources/app/plugins/Clojure/runner/resources/.nrepl-port
at leiningen.repl$repl.doInvoke(repl.clj:317)
at clojure.lang.RestFn.invoke(RestFn.java:425)
at leiningen.light_nrepl$light.invoke(light_nrepl.clj:77)
at leiningen.light_nrepl$_main.doInvoke(light_nrepl.clj:85)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at leiningen.light_nrepl.main(Unknown Source)

ReferenceError: lt_cljs_tutorial is not defined

I receive the following error when trying to evaluate line 81 (https://github.com/swannodette/lt-cljs-tutorial/blob/master/lt-cljs-tutorial.cljs#L81). Should I not be evaluating there or is this another issue?

ReferenceError: lt_cljs_tutorial is not defined
    at eval (/Users/bliss/Code/lt-cljs-tutorial/lt-cljs-tutorial.cljs[eval7]:81:1)
    at eval (native)
    at Function.eval (file:///Applications/LightTable/LightTable.app/Contents/Resources/app.nw/core/node_modules/lighttable/bootstrap.js:33785:461)
    at b (file:///Applications/LightTable/LightTable.app/Contents/Resources/app.nw/core/node_modules/lighttable/bootstrap.js:6188:14)
    at a (file:///Applications/LightTable/LightTable.app/Contents/Resources/app.nw/core/node_modules/lighttable/bootstrap.js:6234:18)
    at cljs.core.do_dispatch (file:///Applications/LightTable/LightTable.app/Contents/Resources/app.nw/core/node_modules/lighttable/bootstrap.js:13583:26)
    at cljs.core.MultiFn.cljs$core$IMultiFn$_dispatch$arity$2 (file:///Applications/LightTable/LightTable.app/Contents/Resources/app.nw/core/node_modules/lighttable/bootstrap.js:13655:32)
    at cljs.core._dispatch (file:///Applications/LightTable/LightTable.app/Contents/Resources/app.nw/core/node_modules/lighttable/bootstrap.js:13568:14)
    at a (file:///Applications/LightTable/LightTable.app/Contents/Resources/app.nw/core/node_modules/lighttable/bootstrap.js:13662:32)
    at b [as call] (file:///Applications/LightTable/LightTable.app/Contents/Resources/app.nw/core/node_modules/lighttable/bootstrap.js:13666:14)

Exception on the first def

When I reach this line:

(def x 1)

And I hit Control-Enter:

ReferenceError: lt_cljs_tutorial is not defined
    at eval (/home/al/lt-cljs-tutorial.cljs[eval48]:77:1)
    at eval (native)
    at Function.eval (app://lighttable/core/node_modules/lighttable/bootstrap.js:33600:461)
    at b (app://lighttable/core/node_modules/lighttable/bootstrap.js:6143:14)
    at a (app://lighttable/core/node_modules/lighttable/bootstrap.js:6189:18)
    at cljs.core.do_dispatch (app://lighttable/core/node_modules/lighttable/bootstrap.js:13499:26)
    at cljs.core.MultiFn.cljs$core$IMultiFn$_dispatch$arity$2 (app://lighttable/core/node_modules/lighttable/bootstrap.js:13571:32)
    at cljs.core._dispatch (app://lighttable/core/node_modules/lighttable/bootstrap.js:13484:14)
    at a (app://lighttable/core/node_modules/lighttable/bootstrap.js:13578:32)
    at b [as call] (app://lighttable/core/node_modules/lighttable/bootstrap.js:13582:14)

I'm new to both LightTable and ClojureScript so I might be missing something but the tutorial worked fine until that point.

regex

Hi David, shouldn't we add regex as well, even if js regex are not fully supported?

Light Table 0.5.x

I had trouble running some of the examples in older versions of Light Table.

For example, evaluating

(def another-array #js [1 2 3])

I would get the error

No reader function for tag js core.clj:4327 clojure.core/ex-info

This seems to have been fixed a while ago in Light Table, but I thought I would let you know if others run into this issue. Maybe we could update the README with versions that work correctly.

Weird

I saw this today which looks wrong.

screen shot 2014-03-22 at 1 54 16 pm

Specifically, this part:

screen shot 2014-03-22 at 1 57 00 pm

Am I missing something or is this a bug?

no file or url found for cljs connection

I'm following the tutorial first step, but with leiningen installed and light table 0.8.0-alpha I've got the error message : no file or url found for cljs connection when I hit cmd-enter just after the namespace command

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.