Changes between Version 5 and Version 6 of Doc/panc/dml/functions
- Timestamp:
- Mar 3, 2007, 4:38:23 PM (17 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Doc/panc/dml/functions
v5 v6 9 9 10 10 {{{ 11 "/test" = "[" + base64_decode("aGVsbG8gd29ybGQ=") + "]";12 # will be the string "[hello world]"11 '/test' = '[' + base64_decode("aGVsbG8gd29ybGQ=") + ']'; 12 # will be the string '[hello world]' 13 13 }}} 14 14 … … 17 17 This function returns a clone (copy) of the given argument. 18 18 19 === create( name:string, . .. ) : nlist ===19 === create( name:string, ... ) : nlist === 20 20 21 21 This function returns the named list which is the result of the execution of the structure template identified … … 41 41 This function prints the given message on stdout when debugging is enabled with the DEBUG USER 42 42 flag. 43 43 44 {{{ 44 45 # print the value of x if it is positive 45 if (x > 0) 46 debug("x is positive: " + to_string(x)); 46 if (x > 0) debug("x is positive: " + to_string(x)); 47 47 }}} 48 48 … … 50 50 51 51 This 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”]. . . ). 52 subscript such as foo or foo[123] or foo[123][”abc”]). 53 53 54 {{{ 54 55 # the following will put the list ("a", "c") at path "/x" 55 56 "/x" = { 56 x = list("a", "b", "c");57 delete(x[1]);58 return(x);59 }; 60 }}} 61 62 === error( m essage:string ) ===57 x = list("a", "b", "c"); 58 delete(x[1]); 59 return(x); 60 }; 61 }}} 62 63 === error( msg:string ) === 63 64 64 65 This function prints the given message on stderr and aborts the compilation. … … 66 67 {{{ 67 68 # 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"); 69 function 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 73 75 # normal processing... 74 76 }; … … 111 113 ok = first(numlist, k, v); 112 114 while (ok) { 113 sum = sum + v;114 ok = next(numlist, k, v);115 sum = sum + v; 116 ok = next(numlist, k, v); 115 117 }; 116 118 # sum will be 15 119 117 120 # put the list of all the keys of table inside keys 118 121 table = nlist("a", 1, "b", 2, "c", 3); 119 122 keys = list(); 120 123 ok = 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); 123 127 }; 124 128 # keys will be ("a", "b", "c") … … 215 219 This function checks if the given argument has a null value (i.e. is anything but null). 216 220 221 === is_number( arg:element ) : boolean === 222 223 Returns true if the argument is either a long or double property. 224 217 225 === is_property( arg:element ) : boolean === 218 226 … … 234 242 {{{ 235 243 "/table" = nlist("red", 0xf00, "green", 0x0f0, "blue", 0x00f); 244 236 245 "/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); 248 258 }; 249 259 # /keys will be the string "red green blue" … … 287 297 # IPv4 address in dotted number notation 288 298 type 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); 300 309 }; 301 310 }}} … … 421 430 # we add one DNS server to the current list 422 431 # (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")); 425 433 # the RAM of this machine is the same as the machine foo 426 434 "/hardware/memory/size" = value("//foo/hardware/memory/size");