MapleTableAlloc
create a table in external code
MapleTableAssign
assign into a table in external code
MapleTableSelect
select from a table in external code
MapleTableDelete
delete an element in a table in external code
MapleTableHasEntry
test if an element exists in a table in external code
Calling Sequence
Parameters
Description
Examples
MapleTableAlloc(kv)
MapleTableAssign(kv, table, ind, val)
MapleTableSelect(kv, table, ind)
MapleTableDelete(kv, table, ind)
MapleTableHasEntry(kv, table, ind)
kv
-
kernel handle of type MKernelVector
table
Maple table object
ind
index or key that maps to the data in a table
val
value to assign into the table
These functions can be used in external code with OpenMaple or define_external.
MapleTableAlloc creates a new table object. Tables are dynamic and grow as needed, so, unlike MapleListAlloc, no size parameter is needed.
MapleTableAssign sets the element at index ind of the table to the value val, that is, table[ind] := val. An index can be any valid Maple object. Elements can be removed and inserted from tables at any time (unlike MapleListAssign, which can only be used immediately after creating a list).
MapleTableSelect retrieves the element at index ind of the table. If no element exists at the index ind, then NULL is returned.
MapleTableDelete removes the element at index ind of the table. If no element exists at the index ind, the table is unmodified.
MapleTableHasEntry returns TRUE if there exists an element at index ind of the table, and FALSE if nothing exists at that index.
#include <string.h>
#include "maplec.h"
ALGEB M_DECL MyDictionary( MKernelVector kv, ALGEB *args )
{
ALGEB tab, val;
char *code;
M_INT argc;
M_BOOL r;
argc = MapleNumArgs(kv,(ALGEB)args);
if( argc < 1 ) {
MapleRaiseError(kv,"at least one argument expected");
return( NULL );
}
if( !IsMapleString(kv,args[1]) ) {
MapleRaiseError(kv,"string expected");
code = MapleToString(kv,args[1]);
if( strcmp(code,"create") == 0 ) {
return( MapleTableAlloc(kv) );
if( argc < 3 ) {
MapleRaiseError(kv,
"at least 3 arguments expected for this operation");
if( !IsMapleTable(kv,args[2]) ) {
MapleRaiseError(kv,"table expected");
tab = args[2];
if( strcmp(code,"insert") == 0 ) {
if( argc != 4 ) {
MapleRaiseError(kv,"4 arguments expected for insert");
MapleTableAssign(kv,tab,args[3],args[4]);
return( ToMapleBoolean(kv,TRUE) );
else if( strcmp(code,"lookup") == 0 ) {
if( (val=MapleTableSelect(kv,tab,args[3])) == NULL )
return( ToMapleBoolean(kv,-1) );
else
return( val );
else if( strcmp(code,"remove") == 0 ) {
r = MapleTableHasEntry(kv,tab,args[3]);
MapleTableDelete(kv,tab,args[3]);
return( ToMapleBoolean(kv,r) );
else {
MapleRaiseError1(kv,"unrecognized option %1",args[1]);
Execute the external function from Maple.
with⁡ExternalCalling:
dll≔ExternalLibraryName⁡HelpExamples:
dict≔DefineExternal⁡MyDictionary,dll:
d≔dict⁡create:
dict⁡insert,d,Paul,1,2,3
true
dict⁡lookup,d,Paul
1,2,3
dict⁡remove,d,Paul
FAIL
false
See Also
CustomWrapper
define_external
OpenMaple
OpenMaple/C/API
OpenMaple/C/Examples
Download Help Document