Skip to content

Instantly share code, notes, and snippets.

View sgrove's full-sized avatar
💭
Infinigraph, and beyond!

Sean Grove sgrove

💭
Infinigraph, and beyond!
View GitHub Profile
@sgrove
sgrove / cis194-ex1.hs
Created November 30, 2014 01:47
CIS194 Ex. 1
module CIS194 where
-- Exercise 1
toDigits :: Integer -> [Integer]
toDigits 0 = []
toDigits x = map read [[c] | c <- show x, x > 0]
toDigitsRev :: Integer -> [Integer]
toDigitsRev = reverse . toDigits
S .
B _build
PKG core
PKG core_kernel
Pkg async
PKG core_extended
PKG lwt lwt.unix
PKG cohttp
EXT nonrec
From 6ae91a7285e7cf4976185891c1022847aaca56a8 Mon Sep 17 00:00:00 2001
From: Sean Grove <s@bushi.do>
Date: Wed, 28 Aug 2013 14:43:55 -0700
Subject: [PATCH] Add failing syntax test
---
test/cljs/cljs/core_test.cljs | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/test/cljs/cljs/core_test.cljs b/test/cljs/cljs/core_test.cljs
@sgrove
sgrove / compiler.cljs
Created August 25, 2013 20:52
Example compiler output for constants-table
(defn emit-constants-table [table]
(doseq [[keyword value] table]
(emits value "=new cljs.core.Keyword(")
(emit-constant (.sym keyword))
(emits ");\n")))
@sgrove
sgrove / analyzer.clj
Created August 25, 2013 19:36
Real Keywords 00002
; Changes to analyzer.clj
(def keyword_counter (atom 0))
(defn genid
"Returns a new symbol with a unique name. If a prefix string is
supplied, the name is prefix# where # is some unique number. If
prefix is not supplied, the prefix is 'K__'."
([] (genid "K__"))
([prefix-string]
(when (nil? keyword_counter)
@sgrove
sgrove / analyzer.clj
Last active December 21, 2015 11:49
Real keywords 00001
(def ^:dynamic *real-keywords?* true)
(def ^:dynamic *constant-table* (atom {}))
(defn reset-constant-table! []
(reset! *constant-table* {}))
(defn register-constant! [k]
(println "Registering constant!")
(swap! *constant-table*
(fn [table]
var foo = {ns_shadow_test:{}};
foo.ns_shadow_test.bar = function() {
return 1
};
foo.ns_shadow_test.quux = function(a) {
return a.ns_shadow_test.bar.call(null) + a
};
foo.ns_shadow_test.test_shadow = function() {
if(cljs.core._EQ_.call(null, foo.ns_shadow_test.quux.call(null, 2), 3)) {
return null

Edit your cljsbuild compiler options and add a source map output location. Wherever you put it, it needs to be accessible by the browser

:cljsbuild {:test-commands {"unit-tests" ["runners/phantomjs.js"
                                        "resources/public/js/vendor/handlebars-1.0.rc.1.min.js"
                                        "resources/private/js/unit-test.js"]}
          :builds
          [{:source-paths ["src/cljs"],
            :id "dev",
            :compiler {:pretty-print true,

:output-dir "resources/public/js/bin-debug",

@sgrove
sgrove / explanation.md
Last active December 20, 2015 01:39
Adding symbol location to source maps for fn params and let bindings

Right now fn params are compiled out in compiler.clj via e.g. (emit-fn-method ...) using:

(emitln "(function " (munge name) "(" (comma-sep (map munge params)) "){")

comma-sep just munges the names, interposes ',', and emitss the result, losing any metadata.

If instead in the analyzer when building the fn params, we attached extra keys to give a param the same shape as a :var, then the compiler can simply call (emit param) and have it treated as a var.

(in cljs.analyzer/analyze-fn-method):

2012-12-02T22:36:04+00:00 heroku[web.1]: State changed from crashed to starting
2012-12-02T22:36:08+00:00 heroku[web.1]: Starting process with command `lein trampoline run`
2012-12-02T22:36:13+00:00 app[web.1]: Could not transfer artifact commons-pool:commons-pool:pom:1.6 from/to (http://s3pository.herokuapp.com/maven-central): Failed to transfer file: http://s3pository.herokuapp.com/maven-central/commons-pool/commons-pool/1.6/commons-pool-1.6.pom. Return code is: 503, ReasonPhrase:Service Unavailable: Back-end server is at capacity.
2012-12-02T22:36:13+00:00 app[web.1]: Could not find artifact commons-pool:commons-pool:pom:1.6 in clojars (https://clojars.org/repo/)
2012-12-02T22:36:13+00:00 app[web.1]: Could not transfer artifact commons-codec:commons-codec:pom:1.6 from/to (http://s3pository.herokuapp.com/maven-central): Failed to transfer file: http://s3pository.herokuapp.com/maven-central/commons-codec/commons-codec/1.6/commons-codec-1.6.pom. Return code is: 503, ReasonPhrase:Service Unavailable: Back-en