| Line 6: |
Line 6: |
| | * You cannot define namespaces, classes or functions | | * You cannot define namespaces, classes or functions |
| | * Number operations in SIPL convert all numbers to doubles behind the scenes | | * Number operations in SIPL convert all numbers to doubles behind the scenes |
| − | * You can use the var keyword to declare temporary variables, but you cannot specify their type | + | * You can use the '''var''' keyword to declare temporary variables, but you cannot specify their type |
| − | * You cannot use bitwise operations. The ^ symbol raises a number to a power | + | * You cannot use bitwise operations. The <code>^</code> symbol raises a number to a power or evaluates xor on booleans |
| − | * You cannot increment or use operations together with assignment, i.e. += or ++. You must write <code>i = i + 1</code> | + | * You cannot increment or use operations together with assignment, i.e. <code>+=</code> or <code>++</code>. You must write <code>i = i + 1</code> |
| − | * SIPL does not support the new keyword, but you can create arrays by writing <code>~[1, 2, 3]</code> | + | * SIPL does not support the '''new''' keyword, but you can create arrays by writing <code>~[1, 2, 3]</code> or call a constructor by just using the type name, e.g. <code>Color(1,0,0)</code> |
| | * For loops are not supported, however you can write <code>'''foreach''' (element '''in''' list)</code> | | * For loops are not supported, however you can write <code>'''foreach''' (element '''in''' list)</code> |
| | + | * Enums should not be qualified when assigning, comparing or in function parameters, e.g. you should write '''Female''' instead of '''Human.Gender.Female'''. |
| | * Comparisons can be chained, e.g. <code>'''if''' (10 < x < 20)</code> | | * Comparisons can be chained, e.g. <code>'''if''' (10 < x < 20)</code> |
| − | * Any enumerable can be indexed into with a number (except for dictionaries), including sets.
| |
| | * Single quotation marks (') do nothing | | * Single quotation marks (') do nothing |
| | * Multiline comments are not supported | | * Multiline comments are not supported |
| | | | |
| | ==Example== | | ==Example== |
| − | '''var''' words = ~["hello", " ", "world"]; ''//Create an array'' | + | '''var''' words = ~[<span style="color:blue">"hello"</span>, <span style="color:blue">" "</span>, <span style="color:blue">"world"</span>]; <span style="color:green">//Create an array</span> |
| − | '''if''' (5 < 10 < 20) ''//Always true'' | + | '''if''' (<span style="color:blue">5</span> < <span style="color:blue">10</span> < <span style="color:blue">20</span>) <span style="color:green">//Always true</span> |
| | { | | { |
| − | '''var''' result = ""; | + | '''var''' result = <span style="color:blue">""</span>; |
| | '''foreach''' (word '''in''' words) | | '''foreach''' (word '''in''' words) |
| | { | | { |
| − | result = result + word; ''//Concatenate the strings from the array'' | + | result = result + word; <span style="color:green">//Concatenate the strings from the array</span> |
| | } | | } |
| − | Debug(result); ''//Log the result'' | + | Debug(result); <span style="color:green">//Log the result</span> |
| | + | } |
| | + | '''else''' |
| | + | { |
| | + | Debug(<span style="color:blue">"Something went wrong"</span>); |
| | } | | } |
| | | | |
| Line 59: |
Line 63: |
| | * Count(func) – Returns how many elements satisfy func(x) | | * Count(func) – Returns how many elements satisfy func(x) |
| | * Where(func) – Returns elements that satisfy func(x) | | * Where(func) – Returns elements that satisfy func(x) |
| | + | * First() - Returns the first element of the enumerable or null |
| | + | * Last() - Returns the last element of the enumerable or null |
| | * FindFirst(func) – Returns the first element that satisfies func(x) | | * FindFirst(func) – Returns the first element that satisfies func(x) |
| | * OrderBy(func) – Returns elements sorted by func(x) in ascending order | | * OrderBy(func) – Returns elements sorted by func(x) in ascending order |
| Line 65: |
Line 71: |
| | * Sum(func) – Returns the sum of running func(x) on all elements | | * Sum(func) – Returns the sum of running func(x) on all elements |
| | * Average(func) – Returns the sum of running func(x) on all elements divided by the amount of elements | | * Average(func) – Returns the sum of running func(x) on all elements divided by the amount of elements |
| | + | * Min(func) – Returns the smallest number resulting from running func(x) on all elements, returns 0 on empty input |
| | + | * Max(func) – Returns the largest number resulting from running func(x) on all elements, returns 0 on empty input |
| | * Size() – Returns how many elements there are in the enumerable | | * Size() – Returns how many elements there are in the enumerable |
| | * GetRandomElement() – Returns a random element from the enumerable | | * GetRandomElement() – Returns a random element from the enumerable |