YCP knows the following data types:
void, boolean, integer, float, string, locale, byteblock symbol, list, map, term, path, block, declaration
void
1 -17049349 0x9fa0 0xDEADBEEF 0233float
1.0 -0.0035 1e30 -0.128e-17string
\n | newline (ASCII 10) |
\t | tabulator |
\r | carriage return (ASCII 13) |
\b | backspace |
\f | formfeed |
\abc | ASCII character represented by the octal value abc. Note that unlike in C, there must be exactly 3 octal digits! |
\X | The character X itself |
"This string end with a newline character.\n" "This string has \ no newline character in it." "This is also a newline: \012"locale
_("Everybody likes Linux!") _("%d m$-windows system deleted", "%d m$-windows systems deleted", 42) _("%d linux system installed", "%d linux systems installed", 42+n)byteblock
In most cases, however, you won't write a byteblock constant in one of your scripts directly. You can use the wfm builtin ReadByteblock to read a complete file into a byteblock.
Variable _17 _this_IS_also_a_symbol `literally_takenlist
[ 1, 2, true ] [ variable, 17 + 38, some_function(x, y) ] [ ] [ "list", "of", "strings" ]map
$[ ] $[ "/usr": 560, "/home" : 3200 ] $[ 1: true, 2: [ true, false ], "string" : 8+9 ]term
A term is something you won't find in C, Perl, Pascal or Lisp. You will find it in Prolog for example. It ist a list plus a symbol, with the list written in normal brackets. The term alpha(17, true) has the symbol alpha and the list [ 17, true ] as arguments. This look pretty like a function call, and in fact that is it's most common use. If you write alpha(17, true) the YCP interpreter will look for a function definition of alpha.
However, you can also use the term as a normal value, for example to specify how a user dialog should look like. In this case you need to quote the term's symbol with the single backquote. Examples:
functioncall(17, true) `HBox(`Pushbutton(`Id(.ok), "OK"), Textentry(`Id(.name), "Name")) _emptyterm()path
\n | newline (ASCII 10) |
\t | tabulator |
\r | carriage return (ASCII 13) |
\b | backspace |
\f | formfeed |
\xXX | ASCII character represented by the hexadecimal value XX |
\" | " |
\X | The character X itself |
. .17 .etc.fstab .etc.fstab.entries.4 ."" ."\"Hello !\n\"".World ."\xFF\xff"."-aaa-" ."abc" == .abc ."\xFF" == ."\xff" ."\x41" == .A ."" != .block
{ return 17; } { integer a = 5; return a + 8; }declaration
Maybe you know what variable declarations are. For example in C you write float a to declare a variable a of type float. The keyword float tells the compiler, that only floating point values are a legal value for the variable a.
A YCP declaration is somewhat more general. It is a restriction on the values some variable or function parameter can hold. For example with:
integer a = 0;
you declare a variable that can hold only integer values. The interpreter will check and warn you, if some mismatched value is assigned to a.
The most general declaration is any. It matches any value. The declarations boolean, integer, float, void, ... match values of a certain type.
Declarations can be combined with the | and & to form more precise or more general restrictions on values. | denotes a logical or, & a logical and.
integer|float b = 0;
This statement declares a variable b. You can't say that the variable b has the type "integer or float", since this is no type. The statement says: "b can hold values of type integer or float". As you can see, declarations are properties of variables, types are properties of values.
For lists and terms there are three declaration constructors:
In YCP a declaration can be used as a value itself. With the is you can check, if a value matches a declaration. If you want to check, whether the value contained in a is a number, you can write:
if (is(a, integer|float)) ...Or you can store it into a variable and write something like this:
declaration number = integer|float; if (is(a, number)) ...However, when declarations appear at variable declarations, function definitions or declaration constructors, you have to write literal declarations. It is not possible to substitute a(integer|float x) with a(number x)..