[plt-scheme] creating an instance of a structure
I have looked through the emails I have for structure information, and have now updated to v200 so the fixes are in.
In the manual on mzscheme the example on creating and using structs is a little confusing and I am hoping someone can help. Please forgive me as I am coming from a Lisp perspective where named arguments are used to define and access elements.
I have been going through Learn Scheme in Fixnum Days, which I am enjoying however the chapter on structures seems to be a little off the mark.
First of all it is define-struct not defstruct, figured that one myself, and making a simple tree structure is easy, however here is where things get sticky:
(define-struct tree (height girth age leaf-shape leaf-colour)) ; to define the structure
t-y-s's version of creating an instance:
(define elm (make-tree
'height 30
'leaf-shape 'frond
'leaf-colour 'green))
This gives:
make-tree: expects 5 arguments, given 6: height 30 leaf-shape frond leaf-colour green
The example in the MzScheme manual is very trivial for brevity, so the initialization does not need to name the elements, and initializes them all. Is there an equivalent to the above that works in Dr.Scheme/mzscheme? At the moment it will only accept a straight up 5 arguments and I don't seem to be able to skip any, or give entries for specific slots.
This leads to the next problem, accessing and setting the slots later:
t-y-s says:
The accessor procedures are invoked as follows:
(tree.height coconut) => 30
(tree.leaf-shape coconut) => frond
(tree.girth coconut) => <undefined>
The modifier procedures are invoked as follows:
(set!tree.height coconut 40)
(set!tree.girth coconut 10)
The above is what I would expect, coming from Lisp, but this doesn't work and mzscheme again is a little quiet on the subject. I feel like I am missing something incredibly obvious, can someone set me on the path to enlightenment?
Thanks,
Rohan