Changes between Version 5 and Version 6 of Doc/panc/dml/functions


Ignore:
Timestamp:
Mar 3, 2007, 4:38:23 PM (17 years ago)
Author:
/O=GRID-FR/C=FR/O=CNRS/OU=LAL/CN=Charles Loomis
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Doc/panc/dml/functions

    v5 v6  
    99
    1010{{{
    11 "/test" = "[" + base64_decode("aGVsbG8gd29ybGQ=") + "]";
    12 # will be the string "[hello world]"
     11'/test' = '[' + base64_decode("aGVsbG8gd29ybGQ=") + ']';
     12# will be the string '[hello world]'
    1313}}}
    1414
     
    1717This function returns a clone (copy) of the given argument.
    1818
    19 === create( name:string, . . . ) : nlist ===
     19=== create( name:string, ... ) : nlist ===
    2020
    2121This function returns the named list which is the result of the execution of the structure template identified
     
    4141This function prints the given message on stdout when debugging is enabled with the DEBUG USER
    4242flag.
     43
    4344{{{
    4445# print the value of x if it is positive
    45 if (x > 0)
    46 debug("x is positive: " + to_string(x));
     46if (x > 0) debug("x is positive: " + to_string(x));
    4747}}}
    4848
     
    5050
    5151This function deletes the element identified by the ”variable expression” (i.e. variable name with optional
    52 subscript such as foo or foo[123] or foo[123][”abc”]. . . ).
     52subscript such as foo or foo[123] or foo[123][”abc”]).
     53
    5354{{{
    5455# the following will put the list ("a", "c") at path "/x"
    5556"/x" = {
    56 x = list("a", "b", "c");
    57 delete(x[1]);
    58 return(x);
    59 };
    60 }}}
    61 
    62 === error( message:string ) ===
     57  x = list("a", "b", "c");
     58  delete(x[1]);
     59  return(x);
     60};
     61}}}
     62
     63=== error( msg:string ) ===
    6364
    6465This function prints the given message on stderr and aborts the compilation.
     
    6667{{{
    6768# user function requiring one long argument
    68 define function foo = {
    69 if (argc != 1)
    70 error("foo(): wrong number of arguments: " + to_string(argc));
    71 if (!is_long(argv[0]))
    72 error("foo(): argument is not a long");
     69function foo = {
     70
     71  if (argc != 1) error("foo(): wrong number of arguments: " + to_string(argc));
     72
     73  if (!is_long(argv[0])) error("foo(): argument is not a long");
     74
    7375# normal processing...
    7476};
     
    111113ok = first(numlist, k, v);
    112114while (ok) {
    113 sum = sum + v;
    114 ok = next(numlist, k, v);
     115  sum = sum + v;
     116  ok = next(numlist, k, v);
    115117};
    116118# sum will be 15
     119
    117120# put the list of all the keys of table inside keys
    118121table = nlist("a", 1, "b", 2, "c", 3);
    119122keys = list();
    120123ok = first(table, k, v);
    121 while (ok) {
    122 keys[length(keys)] = k;ok = next(table, k, v);
     124  while (ok) {
     125  keys[length(keys)] = k;
     126  ok = next(table, k, v);
    123127};
    124128# keys will be ("a", "b", "c")
     
    215219This function checks if the given argument has a null value (i.e. is anything but null).
    216220
     221=== is_number( arg:element ) : boolean ===
     222
     223Returns true if the argument is either a long or double property.
     224
    217225=== is_property( arg:element ) : boolean ===
    218226
     
    234242{{{
    235243"/table" = nlist("red", 0xf00, "green", 0x0f0, "blue", 0x00f);
     244
    236245"/keys" = {
    237 tbl = value("/table");
    238 res = "";
    239 len = length(tbl);
    240 idx = 0;
    241 while (idx < len) {
    242 res = res + key(tbl, idx) + " ";
    243 idx = idx + 1;
    244 };
    245 if (length(res) > 0)
    246 splice(res, -1, 1);
    247 return(res);
     246
     247  tbl = value("/table");
     248  res = "";
     249  len = length(tbl);
     250  idx = 0;
     251  while (idx < len) {
     252    res = res + key(tbl, idx) + " ";
     253    idx = idx + 1;
     254  };
     255
     256  if (length(res) > 0) splice(res, -1, 1);
     257  return(res);
    248258};
    249259# /keys will be the string "red green blue"
     
    287297# IPv4 address in dotted number notation
    288298type ipv4 = string with {
    289 result = matches(self, ’ˆ(\d+)\.(\d+)\.(\d+)\.(\d+)$’);
    290 if (length(result) == 0)
    291 return("bad string");
    292 i = 1;
    293 while (i <= 4) {
    294 x = to_long(result[i]);
    295 if (x > 255)
    296 return("chunk " + to_string(i) + " too big: " + result[i]);
    297 i = i + 1;
    298 };
    299 return(true);
     299  result = matches(self, ’ˆ(\d+)\.(\d+)\.(\d+)\.(\d+)$’);
     300  if (length(result) == 0)
     301  return("bad string");
     302  i = 1;
     303  while (i <= 4) {
     304    x = to_long(result[i]);
     305    if (x > 255) return("chunk " + to_string(i) + " too big: " + result[i]);
     306    i = i + 1;
     307  };
     308  return(true);
    300309};
    301310}}}
     
    421430# we add one DNS server to the current list
    422431# (we need to use list() because merge() requires lists)
    423 "/system/dns/servers" = merge(value("/system/dns/servers"),
    424 list("137.138.16.5"));
     432"/system/dns/servers" = merge(value("/system/dns/servers"), list("137.138.16.5"));
    425433# the RAM of this machine is the same as the machine foo
    426434"/hardware/memory/size" = value("//foo/hardware/memory/size");