Link | dictionary |
Author | Jason Huck |
Category | Data Type |
Version | 8.x |
License | http://opensource.org/licenses/artistic-license.php |
Posted | 24 Oct 2006 |
Updated | 18 Nov 2006 |
More by this author... |
This is a simple custom type for storing and retrieving arbitrary name=value pairs on the fly. It's essentially [map] without the need for ->insert and ->find. You can still use all the standard member tags of [map], though, including ->size, ->keys, ->values, ->contains, and ->remove.
'Initialize and Display:
'; /* this works as well as the method below var('user') = dictionary( 'name' = 'John Smith', 'address' = '1234 This Way', 'city' = 'Anytown', 'state' = 'KY', 'zip' = 90210 ); // */ // /* var('user') = dictionary; $user->name = 'John Smith'; $user->address = '1234 This Way'; $user->city = 'Anytown'; $user->state = 'NE'; $user->zip = 90210; // */ $user->name + '
'; $user->address + '
'; $user->city + ', ' + $user->state + ' ' + $user->zip; '
Keys: '; $user->keys; '
Values: '; $user->values; '
Size: '; $user->size; '
Remove and Contains: '; $user->remove('zip'); $user->contains('zip'); '
Convert: '; $user;
Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
define_type( 'dictionary', -prototype, -description='A basic dictionary type.' ); define_tag('oncreate'); local('ivars') = @self->properties->first; iterate(params, local('i')); if(!#i->first->waskeyword && #i->isa('pair')); #ivars->insert(#i->first = #i->second); /if; /iterate; /define_tag; define_tag('size'); return(self->properties->first->size); /define_tag; define_tag('onconvert'); return(self->properties->first); /define_tag; define_tag('_unknowntag'); local('ivars') = @self->properties->first; local('maptags') = @#ivars->properties->second; #maptags->keys >> tag_name ? return( @#maptags->find(tag_name)->run( -owner=self->properties->first, -params=params ) ); #ivars->keys !>> tag_name ? #ivars->insert(tag_name = dictionary); return(@#ivars->find(tag_name)); /define_tag; /define_type;
No comments
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft