Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This pull-request contains a proof of concept "struct" implementation, which currently allows structures to be defined - as a list of fields, and objects created assuming all fields are present. This will close #82, once complete. Sample usage: ;; define a structure (struct person name address) ;; create an instance (set! self (person "Steve Kemp" "My home address, Helsinki, Finland")) (print "struct.type is %s" (type self)) (print "struct.address contains:%s" (get self "address")) (print "struct.name contains:%s" (get self "name")) Here you'll notice that the struct is actually a hash, and we're merely setting the named fields as key/val pairs. This is pretty smart, all we've really done is recorded the fields a structure should contain, and hooked into our execution to instantiate a new hash when we see a named structure - before falling back to invoking a command instead. The bit that's missing? We want to have "type?" support, and we want to have accessors created. type? support is trivial if we copy/paste primitive.Hash into primitive.Struct and add a "type" member. We just return: struct-%s, primitive.Type However adding accessors get's tricky. I could have another map but getting type validaiton is gonna be a pain. It also seems like if I continue to abuse/reuse the Hash type we could use something siumilar to allow: hash.field To either get/set values and that feels like a useful piece of syntatic sugar. Will experiment before committing.
- Loading branch information