-
Notifications
You must be signed in to change notification settings - Fork 1
Type
Liu Siwei edited this page Jan 21, 2018
·
21 revisions
| Type | $type(x) | Check |
|---|---|---|
| Number | 'number' | .isNumber |
| Boolean | 'boolean' | .isBoolean |
| String | 'string' | .isString |
| Pair | 'pair' | .isPair |
| List | 'list' | .isList |
| Array | 'array' | .isArray |
Strings are values enclosed by single quotes or double quotes.
str1 := 'This is a string'
str2 := "This is also a string"To declare multi-line string, use back quote
str := `line 1
line 2
line 3`[TODO]
[TODO]
p := (2,5)p.head // => 2
p.tail // => 5List is one of the primitive data types in YJLO Script.
Empty list:
[]List with initial elements:
[1, 2, 3]Nested list:
[1, [2, 3], [4]]The last comma (trailing comma) in the list is ignored. For example,
list = [
[1,2],
[3,4],
]is also valid.
| Function call | Output |
|---|---|
[].isEmpty |
true |
[1, 2].isEmpty |
false |
| Function call | Output |
|---|---|
[1, 2, 3].head |
1 |
[3].head |
3 |
| Function call | Output |
|---|---|
[1, 2, 3].tail |
[2,3] |
[1, 2].tail |
[2] |
[1].tail |
[] |
| Function call | Output |
|---|---|
[1, 2, 3].len |
3 |
[].len |
0 |
| Function call | Output |
|---|---|
[1, 2, 3].reversed |
[3, 2, 1] |
| Function call | Output |
|---|---|
[1, 2, 3].has(3) |
true |
[1, 2, 3].has(4) |
false |
| Function call | Output |
|---|---|
[1, 2, 3].index(3) |
2 |
[1, 2, 3].index(4) |
-1 |
Create an array without initial data
/* create an array */
Array(3) // => an array with length of 3
/* create a multi-dimensional array */
Array(10,8,2) // => a 10x8x2 arrayCreate an array with initial data by giving a list
Array([2,3,4])
Array([[1,2,3], [4,5,6], [7,8,9]]) // => a 3x3 arraya := Array([3,8,5,-2])
a[0] // => 3
a[2] // => 5
/* negative index */
a[-1] // => -2
a[-4] // => -3
/* multidimensional indexing */
b := Array(3,4,2)
b[1][2][0] = 5| Function call | Output |
|---|---|
Array([1,2,3]).len |
3 |
Array().len |
0 |
| Function call | Output |
|---|---|
Array([1,2,3]).index(2) |
1 |
Array([1,2,3]).index(5) |
-1 |
Introduction
Langauge Guide
Libraries
- Utility
- ListUtil
- StringUtil
- Math
- Data Structure
- LinkedList
- Stack
- Heap
- HeapList
- HashMap
- HashSet
- Others
- UnitTest
- Tokenizer
Dev Reference
- Syntax Sugar