Data Types
Silk
is a dynamically typed language, and types are determined at
runtime. You do not need to declare the type of a variable; a
variable is created the first time you assign a value to it.
nCount=1;
dMile=100.68;
strName="Wang Gang";
Silk has 8 data types:
IntegerAn integer is a whole number, positive or negative, without decimals.
In 32-bit Silk, the value range is from -2147483648 to 2147483647.
In 64-bit Silk, the value range is from -9223372036854775808 to 9223372036854775807.
You can convert values of other types into integers by using the built-in function _int:
n=_int("12");
m=_int(12.36);
is "floating point number", it is a number, positive or negative,
containing one or more decimals. The storage size is 8 bytes and the
value range is from 2.3E-308 to 1.7E+308
You can convert the variable with other types into integer by using built-in function _float:
StringString is surrounded by double quotation marks. Escape characters such as '\n' are supported within string.
Arraynames=["Wang","Zhang","Li"];
array2=[1,"abc",200.23,names,{"Zhao":50}];
print(names[1]);
An
array is used to store a collection of data, and can be accessed by the
index of the element. Unlike C, Silk supports different data type
in array. We can store Integer, Float, String, Array and Dictionary in
a single array.
Dictionarynames=["Wang","Zhang","Li"];
dicts={"Wang":25,"Zhang":30,"Li":[10,20],"Others":names};
print(dicts["Zhang"]);
Dictionary
is used to store data values in key:value pairs. It is written with
curly brackets, and the key does not allow duplicates. Silk
supports different data type in dictionary. We can store Integer,
Float, String, Array and Dictionary in a single dictionary.
BooleanIn Silk, Boolean values are represented by the integers 1 and 0, so you can use true and false instead of 1 and 0.
HandleA handle
is sort of a pointer, and it allows you to keep a reference
to an object, rather than the object itself. If you open a file
or load a Dll, the return value is a handle, and you can control the
file/dll with the handle.
lib=_loadlib(get_curdir()+"sqlitedll64.dll");
print(_type(lib));
NullIn
Silk, we have a special value 'null', null is not the same as 0, false,
or an empty string. it means nothing and only null can be null.