Sometimes, a shellscript is the right tool for the job. At that, Bash has arrays and a safe mode, which in large part makes it possible and practical (respectively) to write scripts without glaring bugs. Other times, you are invoking the shell because that's what you get.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* From http://caml.inria.fr/pub/ml-archives/caml-list/2004/06/8730fc362310ad9db0c2239b5b815a22.en.html *) | |
exception Overflow | |
let ( + ) a b = | |
let c = a + b in | |
if (a lxor b) lor (a lxor (lnot c)) < 0 then c else raise Overflow | |
let ( - ) a b = | |
let c = a - b in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- https://aupiff.com/eliminating-explicit-parentheses-with-a-handy-combinator | |
u = (:) 'g' (show 13) | |
u' = (.) (.) (:) 'g' show 13 | |
v = length ((:) 1 [4,2]) | |
v' = (.) (.) (.) length (:) 1 [4,2] | |
w = (++) "elab" ((:) 'o' "rate") | |
w' = (.) ((.) (.) (.)) (++) "elab" (:) 'o' "rate" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn collapse | |
"Collapses a tree of nested collections | |
into a vector indexed by depth | |
in the original structure." | |
[tree] | |
(loop [flat (transient []) | |
tree tree] | |
(if (empty? tree) | |
(persistent! flat) | |
(recur (conj! flat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; https://stackoverflow.com/questions/11409140/stumped-with-functional-breadth-first-tree-traversal-in-clojure | |
(def tree [1 [2 [4] [5]] [3 [6]]]) | |
(defn bfs | |
[tree] | |
(loop [ret [] | |
queue (conj [] tree)] | |
(if (seq queue) | |
(let [[node & children] (first queue)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns sunil.curry) | |
(defn partial+ | |
"Takes a function f and fewer than the normal arguments to f, and | |
returns a fn that takes a variable number of additional args. When | |
called, the returned function calls f with args + additional args. | |
differs from the core version in that it works on just one argument." | |
{:added "1.0"} | |
([f] f) | |
([f arg1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn tally [n] | |
(apply str | |
(concat | |
(repeat (quot n 5) "卌") | |
(repeat (mod n 5) "|")))) | |
(map tally (range 1 11)) | |
;; ("|" "||" "|||" "||||" "卌" "卌|" "卌||" "卌|||" "卌||||" "卌卌") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns core.clj | |
(:require [clojure.string :as str] | |
[fipp.edn :refer [pprint] :rename {pprint fipp}] | |
[com.positronic-solutions.pulley.cps :refer :all] | |
[no.disassemble :refer :all])) | |
(defn stacks [] | |
(->> disassemble | |
call-cc | |
str/split-lines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{:minor-version 0, | |
:major-version 49, | |
:name anaphora$get_cc$fn__9738$fn__9739, | |
:interface-names [], | |
:fields | |
({:access-flags #{}, | |
:name cc, | |
:descriptor "Ljava/lang/Object;", | |
:synthetic? false, | |
:deprecated? false, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define zero (lambda (f) (lambda (x) x))) | |
(define one (lambda (f) (lambda (x) (f x)))) | |
(define two (lambda (f) (lambda (x) (f (f x))))) | |
(define three (lambda (f) (lambda (x) (f (f (f x)))))) | |
(define four (lambda (f) (lambda (x) (f (f (f (f x))))))) | |
(define five (lambda (f) (lambda (x) (f (f (f (f (f x)))))))) | |
(define six (lambda (f) (lambda (x) (f (f (f (f (f (f x))))))))) | |
(define seven (lambda (f) (lambda (x) (f (f (f (f (f (f (f x)))))))))) | |
(define eight (lambda (f) (lambda (x) (f (f (f (f (f (f (f (f x))))))))))) | |
(define nine (lambda (f) (lambda (x) (f (f (f (f (f (f (f (f (f x)))))))))))) |
NewerOlder