From 8aa00fea278841a0920b76ba4f81e458ece877a8 Mon Sep 17 00:00:00 2001 From: Mike Cifelli Date: Thu, 9 Mar 2017 14:14:54 -0500 Subject: [PATCH] Add a dynamic data structure example --- lisp/random/structure.lisp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 lisp/random/structure.lisp diff --git a/lisp/random/structure.lisp b/lisp/random/structure.lisp new file mode 100644 index 0000000..0ad2850 --- /dev/null +++ b/lisp/random/structure.lisp @@ -0,0 +1,22 @@ +(load "../lang/dlambda.lisp") +(load "../lang/functions.lisp") + +(define-special keys (&rest fields) + (eval + (list 'let (mapcar 'list fields) + '(eval + (dlambda + (:get (field) (eval field)) + (:set (field value) (set field value))))))) + +(defun process-data (data) + (let ((one (call data :get 'one)) + (two (call data :get 'two)) + (three (call data :get 'three))) + (list one two three))) + +(setq data (keys one two three)) +(call data :set 'one "goodbye") +(call data :set 'two "key") +(call data :set 'three "!") +(process-data data)