Download LambdaCore Database Programmer`s Manual Version 1.3
Transcript
Chapter 1: The LambdaCore Classes
74
where our result is an overall result, set to ‘true’ if some string didn’t match, followed
by the object reference numbers of players that matched. An optional third argument,
prefix, gives an identifying string to prefix to each of the nasty messages.
For example, supposing there are only players named ‘blip’ and ‘blipster’ in the
database:
Results
Strings
Ret
Player Sees....
----------------------------{$nothing}
{"George"} 0
nothing
{$failed_match}
{"George"} 1
"George" is not the
name of any player.
{$ambiguous_match} {"blip"}
1
"blip" could refer to any
of a number of people."
{#28}
{"blip"}
{0, #28} nothing
The following code fragment from $player:page shows how you might use this function in your own programs:
who = $string_utils:match_player(args[1]);
if ($command_utils:player_match_result(who, args[1])[1])
return;
The variable args[1] contains the name of the player we are trying to page
No properties are defined on the $command_utils class.
1.3.5 The List Utilities Class
The list utilities class, $list_utils defines a number of functions that manipulate lists.
list map prop (list objs, string prop)
Verb
This function returns a list of the values of a specified property prop on each of the
objects in the list objs. If prop does not exist on one of the objects, an error occurs.
As an example, the following code will list all the locations that have at least one
player in them. It uses the :map_prop verb to generate a list corresponding to each
player’s location. Set addition is used to provide a list of the location names without
duplication. Note that the players() primitive returns a list of all the player objects
in the database.
locs = $list_utils:map_prop(players(), "location");
rooms = {};
for x in (locs)
rooms = setadd(rooms, x.name);
endfor
player:tell("Inhabited locations are ",
$string_utils:english_list(rooms), ".");
list map verb (list objs, string verb [, list varg])
Verb
This function returns a list of the return values of a specified verb verb on each of the
objects in the list objs. varg is optional and defines the arguments to verb; it defaults
to the empty list {}. If verb does not exist on one of the objects, an error occurs.