Lasso Soft Inc. > Home

[dictionary]

Linkdictionary
AuthorJason Huck
CategoryData Type
Version8.x
Licensehttp://opensource.org/licenses/artistic-license.php
Posted24 Oct 2006
Updated18 Nov 2006
More by this author...

Description

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.

Sample Usage

'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;

Source Code

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;

Related Tags

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft