Skip to content

Instantly share code, notes, and snippets.

@useronym
Created May 14, 2017 08:35
Show Gist options
  • Save useronym/9d79cc2769e57d02e41b5144b6267fb3 to your computer and use it in GitHub Desktop.
Save useronym/9d79cc2769e57d02e41b5144b6267fb3 to your computer and use it in GitHub Desktop.
(defmacro tupleize-record (rec-name)
`(lambda (rec)
,(lists:map (lambda (field-name)
(tuple field-name (rec-get rec-name field-name)))
(rec-fields rec-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