Created
August 10, 2014 07:31
-
-
Save agumonkey/c2c33c88d5372e25312b to your computer and use it in GitHub Desktop.
Everything is a function ? even structs and types ?
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
(setq lexical-binding t) | |
(defun make-struct (fields) | |
(lambda (values) | |
(let ((map (-zip fields values))) | |
(lambda (field) | |
(assoc field map))))) | |
;;; generic | |
(setq s (make-struct '(:a :b :c))) | |
(setq u (funcall s '(1 2 3))) | |
(funcall u :a) | |
(funcall u :b) | |
(funcall u :c) | |
(-map (lambda (f) (funcall u f)) '(:a :b :c)) ; u -> u | |
;;; specific | |
(setq Person (make-struct '(:name :age :city))) | |
(setq john (funcall Person '(John 23 London))) | |
(funcall john :age) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment