Skip to content

Instantly share code, notes, and snippets.

@useronym
Last active May 13, 2017 08:55
Show Gist options
  • Save useronym/5f400c8417ef994a6fd3d278aebfda15 to your computer and use it in GitHub Desktop.
Save useronym/5f400c8417ef994a6fd3d278aebfda15 to your computer and use it in GitHub Desktop.
(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