Skip to content
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

String

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`

Methods

[TODO]

.len

.toCharList

.charCode

.substring(from, to)

Indexing

[TODO]

Pair

Create

p := (2,5)

Get values

p.head	// => 2
p.tail	// => 5

List

List is one of the primitive data types in YJLO Script.

Create a list

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.

Methods

.isEmpty

Function call Output
[].isEmpty true
[1, 2].isEmpty false

.head

Function call Output
[1, 2, 3].head 1
[3].head 3

.tail

Function call Output
[1, 2, 3].tail [2,3]
[1, 2].tail [2]
[1].tail []

.len

Function call Output
[1, 2, 3].len 3
[].len 0

.reversed

Function call Output
[1, 2, 3].reversed [3, 2, 1]

.has(element)

Function call Output
[1, 2, 3].has(3) true
[1, 2, 3].has(4) false

.index(element)

Function call Output
[1, 2, 3].index(3) 2
[1, 2, 3].index(4) -1

Array

Create

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 array

Create 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 array

Indexing

a := 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

Methods

.len

Function call Output
Array([1,2,3]).len 3
Array().len 0

.index(element)

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
Clone this wiki locally