Skip to content

Program structure

Basically, all Pineapple program are just lists of definitions.

The definitions are:

  • Function definition

  • Struct definition

  • Import definition

  • Constants definition

  • Type aliases definition

  • Trait declaration definition

  • Trait implementation definition

  • Enumeration definition

Warning

Those features that are not ticked means that they are not implemented yet.

For example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// function definition
def .main
    "Hello world".show

// struct definition
def People
    :name String
    :age  Number

// import definition
import "./myFunctions.pine"

// constants definition
def pi = 3.142

// type aliases definition
def Color = Tuple{Int,Int,Int}

// trait declaration definition
def Equatable{T}
    def (this T) == (that T) -> Bool
    def (this T) != (that T) -> Bool
        return not this == that

// trait implementation definition
def Equatable{Color}
    def (this Color) == (that Color) -> Bool
        return \
            this.(0) == that.(0) and \
            this.(1) == that.(1) and \
            this.(2) == that.(2)

// enumeration definition
def Color
    #red
    #green
    #blue
    #yellow

Comments