Skip to content

Instantly share code, notes, and snippets.

@Liutos
Created June 26, 2012 01:40
Show Gist options
  • Save Liutos/2992622 to your computer and use it in GitHub Desktop.
Save Liutos/2992622 to your computer and use it in GitHub Desktop.
The definition of macro ROW->INSTANCE-OF-CLASS
(defmacro row->instance-of-class (row class &body slots)
"Create an instance of class `class' filled with values extracted from `row'. The `slots' is a list of symbols. The symbols would be used as both the place indicator and each would converts to keyword symbol for using in a implicit MAKE-INSTANCE call."
(let ((_row_ (gensym))
(_class_ (gensym)))
`(let ((,_row_ ,row)
(,_class_ ,class))
(destructuring-bind ,slots ,_row_
(make-instance ,_class_
,@(mapcan #'(lambda (sym)
`(,(read-from-string
(format nil ":~S" sym))
,sym))
slots))))))
(defmacro row->instance-of-class (row class &body slots)
"Create an instance of class `class' filled with values extracted from `row'.
The `slots' is a list of symbols. The symbols would be used as both the place
indicator and each would converts to keyword symbol for using in a implicit
MAKE-INSTANCE call."
(let ((_row_ (gensym))
(_class_ (gensym)))
`(let ((,_row_ ,row)
(,_class_ ,class))
(destructuring-bind ,slots ,_row_
(make-instance ,_class_
,@(mapcan #'(lambda (sym)
`(,(read-from-string
(format nil ":~S" sym))
,sym))
slots))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment