In scheming_away I started exploring things and stopped somewhere in the middle. Strated with defining things as structures, then as a tree structure. Now comes a third attempt at the same height. Thank god I'm not competing.
;a tuple is a structure with an id and a value
(define-struct tuple (id value))
;tuple + -> list of tuples
(define make-thing (lambda( head . rest)
(map (lambda(x)
(make-tuple
(car x)
(cdr x)))
(cons head rest))))
;just print the bleeding thing
(define thing-print (lambda (t) (for-each tuple-print t)))
;print a tuple
(define tuple-print (lambda( t)
(begin
(display (symbol->string (tuple-id t)))
(display ":")
(display (tuple-value t))
(newline))))
(define a (make-thing
(cons 'type 'story)
(cons 'id 1)
(cons 'title "a node title")
(cons 'body "a node body")))
(thing-print a)You could've notice that I'm not an experienced schemer, so excuse my language, if you feel offended. The above snippets looks better. In php it would look pretty similar, something like:
function make-tuple($id, $value)
{
return array("id"=>$id, "value"=>$value);
}
function make-thing() {
foreach(func_get_args() as $tuple) {
$result[]=$tuple;
}// array_map can be used instead, but
// this is a more popular php idiom
return $result;
}
//I'll leave printing for you
Why I would prefer this representation to its predecessors?
This still doesn't represent the complexity of a thing - for example how do I contruct a particular thing from a thing template (?thing types?)? How can I perform per thing extensions, for example adding new tuples if needed? And how do I sensibly manage that? Have I mentioned the context dependent semantics of the things - for example - print phase, database phase, ....
What are the downsides of the take3 attempt?
So essentially I need something, which has constant time random access (preferably by name), non-stringent structure, i.e the structure should be able to grow and contract over time, as well as having differently named elements in it. Scheme's association lists and hashes, defined in some SRFIs I can't remember at the moment, are of particular interest here.
Ok, Vlado, stop scribbling and go back to play.