Skip to content

Instantly share code, notes, and snippets.

@alandipert
Created March 20, 2012 04:18
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alandipert/2131286 to your computer and use it in GitHub Desktop.
Save alandipert/2131286 to your computer and use it in GitHub Desktop.
Function-level programming a la Backus
(ns flp
"Function-level programming a la Backus; see
http://www.stanford.edu/class/cs242/readings/backus.pdf"
(:refer-clojure :exclude [/]))
;;; Functional Forms - combine existing functions to form new ones.
(def ^{:doc "Composition"} ° comp)
(defn / [f]
"Insert"
(partial reduce f))
(defn α [f]
"ApplyToAll"
(partial map (partial apply f)))
;;; Functions - take and return non-functions (atoms).
(defn Trans [coll]
"Transpose"
(apply map vector coll))
;;; Compute the inner product.
(def IP (° (/ +) (α *) Trans))
(comment
(IP [[1 2 3] [6 5 4]]) ;=> 28
)
@micha
Copy link

micha commented Mar 20, 2012

I think that's the point: (comp f g) is not "creating", while (define f (lambda ...)) must be. FLP does not allow the latter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment