[lp_array_roundrobin]

Description

Link: [lp_array_roundrobin]
Author: Bil Corry
Category: Array
Version: 8.x
License: Public Domain
Posted: Apr. 19, 2006
Updated: Apr. 28, 2006
More by this author...
WARNING: This tag only works with LP8.5!  It will crash LP8.1!

Given an array, it will return the next element in the array.  Can optionally specify the index number using  ->setindex:

lp_array_roundrobin->(setindex: $indexnumber);

Requires [lp_logical_between]

Parameters

-index integer, optional Optionally start the roundrobin at an index other than 1.
-elements custom type, optional The list of elements to create the array out of.

Sample Usage

var:'test' = lp_array_roundrobin;
	$test->(insert: 'a');
	$test->(insert: 'b');
	$test->(insert: 'c');
	loop: 10;
		loop_count; ': ' $test '<br>';
	/loop;
	'<hr>';
	var:'test' = (lp_array_roundrobin: 1, 2, 3, 4, 5);
	$test->(setindex: 5);
	loop: 10;
		loop_count; ': ' $test '<br>';
	/loop;
						

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
[

define_type:'lp_array_roundrobin','array',
	-description='Given an array, it will return the next element in the array.  Can optionally specify the index number.',
	-prototype;

	local:'index' = integer;

	define_tag:'onConvert';
		self->'index' += 1;
		if: self->'index' > self->size;
			self->'index' = 1;
		/if;
		return: self->(get: self->'index');
	/define_tag;

	define_tag:'setIndex',
		-required='index', -copy;
		#index = (integer: #index);
		fail_if: !(lp_logical_between: #index, 1, self->size), -1, 'Invalid index value.';
		self->'index' = #index - 1;
	/define_tag;

/define_type;

]

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular