[dictionary]

Description

Link: [dictionary]
Author: Jason Huck
Category: Data Type
Version: 8.x
License:
Posted: Oct. 24, 2006
Updated: Nov. 18, 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.

Parameters

none


Sample Usage

'Initialize and Display:<br>';
/* 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 + '<br>';
$user->address + '<br>';
$user->city + ', ' + $user->state + ' ' + $user->zip;



'<hr>Keys: ';	
$user->keys;

'<hr>Values: ';
$user->values;

'<hr>Size: ';
$user->size;

'<hr>Remove and Contains: ';
$user->remove('zip');
$user->contains('zip');

'<hr>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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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

none

Email:


Password:



Newest

Most Popular