Created
March 20, 2012 04:18
-
-
Save alandipert/2131286 to your computer and use it in GitHub Desktop.
Function-level programming a la Backus
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 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 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think that's the point: (comp f g) is not "creating", while (define f (lambda ...)) must be. FLP does not allow the latter.