Skip to content

Instantly share code, notes, and snippets.

View sundarj's full-sized avatar

Sundar Joshi sundarj

View GitHub Profile
@halgari
halgari / gist:c17f378718cbd2fd82324002133ef678
Created November 23, 2018 20:54
Contributing to Clojure

So you’d like to contribute to Clojure, great! Let’s talk about what that involves.

The first thing you’ll want to make sure is that your idea is valid, and that you won’t spend a ton of time working on something that won’t make into master. To do this, you should create a JIRA ticket. For example, let’s say we want to improve how core.async handles channel closing propagation. It’s not a super complex problem, but there are some design questions about which of the various semantics currently in place should be the default, and if some semantics should be configurable.

So start by making a JIRA ticket and stating what the problem is you’re trying to solve, what the possible options for solving the problem. Now hit save and wait for the ticket to be triaged. Alex Miller will take a look when he can, and that can take a few days to a few weeks, depending on the time of the year (he has other responsibilities). Alex may out-right reject the idea if he knows Rich would never approve the ticket, but otherwise h

@mfikes
mfikes / clojurescript-types.md
Last active November 1, 2018 16:47
Understanding ClojureScript types

In progress - an explanation of the ClojureScript type system

The main idea is that a type can either be reprsented by a symbol, like number or string, or a set, like #{number string}. The latter means that the value set includes all numbers and strings.

These type symbols are the same ones used in tag meta, as in ^number, which expands to {:tag number}

The type of the value nil is the symbol clj-nil (as opposed to (symbol "nil"))

If you see nil as a type, this means the type wasn't infered.

@mfikes
mfikes / README.md
Last active December 12, 2019 12:08
ClojureScript parameter type inference

This is a demo of experimental work into ClojureScript parameter type inference.

The work is in a branch, and if you'd like to try out any of this yourself, you can start up a REPL based on the experimental branch using the following command, and play along at home:

clj -Srepro -Sdeps '{:deps {github-mfikes/gist-1e2341b48b882587500547f6ba19279d {:git/url "https://gist.github.com/mfikes/1e2341b48b882587500547f6ba19279d" :sha "55d6c6e9a1c4fc9b58fec74aef1af4aba57bad2a"}}}' -m cljs.main -co @compile-opts.edn -re node -r

To date, all ClojureScript inference "flows" in a certain direction, essentially from primitive values or type-hinted locals to their use sites. For example, consider this expression:

@mfikes
mfikes / deps.edn
Last active May 30, 2018 09:31
Try running this in your terminal: clojure -Sdeps '{:deps {github-mfikes/e600e965da916699a703c9b1f1ff6d3b {:git/url "https://gist.github.com/mfikes/e600e965da916699a703c9b1f1ff6d3b" :sha "aa946e43d193fa719544057b0561b03ce2a72977"}}}' -m cljs.main -m hello-clojure
{:paths ["."]
:deps {org.clojure/clojurescript
{:git/url "https://github.com/clojure/clojurescript"
:sha "08beee84b05f911a6bb0eff0dd1235c201b26c70"}}}
@athos
athos / deps.edn
Last active June 2, 2024 08:57
Try on your terminal `clojure -Sdeps '{:deps {hello-clojure/hello-clojure {:git/url "https://gist.github.com/athos/b68b15b08efedffaf14d8c020b125202" :git/sha "099bdf7d565b2c35c1df601abf58514cc5276237"}}}' -M -m hello-clojure`
{:paths ["."]
:deps {clansi/clansi {:mvn/version "1.0.0"}}}
@mfikes
mfikes / tree-seq.clj
Last active May 22, 2020 21:03
Directly-reducible PoC in Clojure
(defn nth' [coll n]
(transduce (drop n) (completing #(reduced %2)) nil coll))
(defn tree-seq'
[branch? children root]
(eduction (take-while some?) (map first)
(iterate (fn [[node pair]]
(when-some [[[node' & r] cont] (if (branch? node)
(if-some [cs (not-empty (children node))]
[cs pair]
@borkdude
borkdude / specter.clj
Last active October 16, 2024 20:01
Vanilla Clojure vs. Specter vs. transducers
(ns specter-idea
(:require [com.rpl.specter :as specter :refer [setval ALL
NONE multi-path
selected?
pred
]]))
(def data ;; only x and y are allowed
[{:name "x" :rels ["x" "y"]} ;=> fine, keep as is
{:name "y" :rels ["x" "y" "z"]} ;=> keep only allowed rels: {:name "y" :rels ["x" "y"]}
@madstap
madstap / car.clj
Last active September 13, 2022 19:15
car, cdr, cadadr and friends in clojure
(ns car
"The sixties are back!"
(:require
[clojure.math.combinatorics :as combo]))
(defn ad-combos [n]
(distinct
(mapcat (fn [i]
(combo/selections '[a d] i))
(range 1 (inc n)))))
(defn topo [graph]
(when-not (empty? graph)
(lazy-seq
(let [n (first (for [[node s] graph
:when (not (seq s))]
node))]
(assert n "if this fails there is a cycle")
(cons n (topo (into {} (for [[node deps] graph
:when (not= n node)]
[node (disj deps n)]))))))))
;; Reducing function:
;; A function that takes an accumulator and an item and returns a new accumulator.
;; Like the function you would pass to reduce.
;; Transducer:
;; A function that takes a reducing function and
;; returns a new reducing function.
;; Slightly simplified, this is the meat of map with arity one.