Arithmetic and booleansSpecifying numbersHere are the Pliant notations for 100 in decimal, hexadecimal and binary encoding: 100 The last line is also 100 but with type Intn. See 'Unlimited integers' section bellow. Basic arithmeticThe four classical arithmetic operators are noted + - * and \ or / in Pliant. console 3+4*2 eol will display 11, not 14. '\' means integer division, '/' means floting point division: console 7\3 eol '%' is the remaining operator: console 7%3 eol '^' is the power operator: console 7^3 eol Basic arithmetic on integers is implemented in /pliant/graphic/language/basic/arithmetric.c Compact notationsvar Int i := 3 is the same as var Int i := 3 Of course, we also have '-=' '*=' '\=' '/=' '%=' and '^=' operators. For advanced users, please notice that these operators can be purely syntactical. I mean, if you define '+' operator for a new data type, then '+=' will work automatically though you may define it to provide more optimal implementation of this special case. ExchangingWhile I'm talking about assigning (I have to move all this to a better place since it's not related to arithmetic), swap instruction can be used to exchange values: var Array:Int i j The key advantage of 'swap' is that it's efficient because it only exchanges the scalar part of the data (in this example, the elements in the array will not be moved). In other words, 'swap i j' is a more efficient equivalent to the following code: var Pointer:Type t :> typeof i Bits operatorsPliant provides bit to bit logical operations: var Int i := 3 OverflowThe following program will overflow, so display an unexpected result: function fact x -> f If the program is run at debugging level 1, the overflow will happen silently, so the result will just be wrong. You can test it through copying the small program in a /pliant/test/fact.pli file, then issue the following command at the prompt (I mean use the: pliant module /test/fact.pli Now, if you switch from the default debugging level 1, to the stricter but much slower debugging level 2 through the following command: pliant debug 2 module /test/fact.pli then instead of silently computing and displaying the wrong result, Pliant will report an overflow error message. Please notice that before starting to test Pliant programs at debugging level 2, you might have to type the following command to precompile Pliant core at debugging level 2: pliant reset debug 2 'precompile /binary/default.dump module /pliant/install/precompile.pli' Should you be aware of potential arithmetic overflow and assume it (it is a wanted or harmless feature in some algorithms), then you can use the side dotted arithmetic operators. The following program will silently overflow even when run at debugging level 2: function fact x -> f Of course, we also have '.+.' and '.-.' Unlimited integersNow, you can avoid the overflow issue through using the slower but unrestricted Intn data type instead of Int function fact x -> f Unsigned and fixed size integersThe size of a Pliant 'Int' on a 32 bits processor is 32 bits, and on a 64 bits process it is 64 bits as opposed to C. Unsigned integers are: var uInt i Fixed size integers are: var Int8 i var uInt8 i The following data types are specifically high indian and low indian encoded: var uInt_hi i Please notice that several types are missing. I mean first 'uInt64_hi' and 'uInt64_li', then the all 'Int_hi' 'Int16_hi' 'Int32_hi' 'Int64_hi' and 'Int_li' 'Int16_li' 'Int32_li' 'Int64_li'. Should they be of any use at some point, extending the code in /pliant/language/type/number/int_indian.pli would be fairly straightforward. Floating pointFloating point data types are: var Float f Please notice that Float and Float64 are just the same. Floating point constants can be provided as: 13.0 Transcendental functions: module "/pliant/math/functions.pli" Undefined valueData type 'Int' has an undefined value: var Int i := undefined Also the undefined value is just a symbolic one, not an effective one. In the following sample: var Int i := undefined The value of 'j' is not 'undefined' as common sense would expect: ? More precisely, on a 32 bits system, undefined value is just the value -2^31. On the other hand, when handled as a floatting point data, undefined value is effective: var Float i := undefined The ouput will be the expected one: ? ComparisonAvailable comparisons are the classical ones, where different is noted '<>': var Int i j When you declare a new type, defining all operators above one after the other might be a bit boring, so support for all comparison operators can be provided as a single 'compare' instruction: function compare a b -> c The result is generally one of the three values 'compare_inferior', 'compare_equal' and 'compare_superior'. Here is a sample direct usage of 'compare' function: var Float a b of course, this is the same as: if a<>b BooleansThere are two kind of booleans in Pliant: var Bool i 'Bool' is a boolean stored on a single byte, 'CBool' is a C like boolean so stored on 4 bytes on a 32 bits platform and assumed to be true when and only when not zero. 'CBool' is more efficient because it can be stored in processor registers since it has 'atomic' property. Operations or booleans are the classical ones: var CBool k Parser issuePliant does not use comma to separate parameters of a function. In math, if you write f(5,-2) you know that 'f' function has two parameters 5 and -2. But in Pliant, if you write (f 5 -2), does it mean that 'f' has also two parameters 5 and -2 or that 'f' has a single 3 parameter. f 5 -2 # assume two parameters because minus has a space before and no space after |