Skip to content

Instantly share code, notes, and snippets.

@waywardmonkeys
Created September 13, 2013 10:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waywardmonkeys/6549141 to your computer and use it in GitHub Desktop.
Save waywardmonkeys/6549141 to your computer and use it in GitHub Desktop.
Testing out creating classes with slots at runtime
Module: dynamic-class
Synopsis: Testing out creating classes with slots at runtime
Author: Bruce Mitchener
Copyright:
define function main (name :: <string>, arguments :: <vector>)
let foo-gf = make(<generic-function>, required: 1, debug-name: "foo");
let bar-gf = make(<generic-function>, required: 1, debug-name: "bar");
let slots = vector(vector(allocation: #"instance",
getter: foo-gf,
required-init-keyword: #"foo"),
vector(allocation: #"instance",
getter: bar-gf,
init-value: 456,
init-keyword: #"bar"));
let <dynamic-class> = make(<class>,
debug-name: "<dynamic-class>",
superclasses: vector(<object>),
slots: slots);
let inst = make(<dynamic-class>, foo: 123);
format-out("%= (%=)\n", inst, debug-name(<dynamic-class>));
for (sd in slot-descriptors(<dynamic-class>))
format-out(" %= = %=\n", debug-name(sd.slot-getter), slot-value(inst, sd));
end;
format-out("---\n");
exit-application(0);
end function main;
main(application-name(), application-arguments());
{<dynamic-class> #x004F01F0} ("<dynamic-class>")
"foo" = 123
"bar" = 456
---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment