Last active
May 13, 2017 08:55
-
-
Save useronym/5f400c8417ef994a6fd3d278aebfda15 to your computer and use it in GitHub Desktop.
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
(defmacro make-record (name) | |
`(lambda (rec) | |
(lists:zip ,(rec-fields name) | |
(lists:map (lambda (rec-field) (funcall ,(rec-get name rec-field) rec | |
,(rec-fields name))))))) | |
(defmacro rec-fields (name) | |
`(,(ltoa (++ "fields-" (atol name))))) | |
(defmacro rec-get (name field) | |
`(lambda (rec) (,(ltoa (++ (atol name) "-" (atol field))) rec))) | |
(defun atol (a) | |
(atom_to_list a)) | |
(defun ltoa (l) | |
(list_to_atom l)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment