Overview
Comment: | Minor improvements to text in playground lessons. |
---|---|
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
d6befbcefb84be94f82fee86d485212f |
User & Date: | robin.hansen on 2020-11-15 11:47:41 |
Other Links: | manifest | tags |
Context
2020-11-16
| ||
04:35 | Better use of spacing on the frontpage. check-in: cd2216e109 user: robin.hansen tags: trunk | |
2020-11-15
| ||
11:47 | Minor improvements to text in playground lessons. check-in: d6befbcefb user: robin.hansen tags: trunk | |
11:32 | Huge improvements to front page style. check-in: 6de38c26fd user: robin.hansen tags: trunk | |
Changes
Modified src/Lesson01.elm from [77584887af] to [c95826daba].
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
content : String content = """ # Welcome to the playground # Here you can learn the Play language by reading and toying around with examples. # Below you'll find a simple word definition. # In other programming languages, this will usually be called a function definition. def: main # 1 entry: true # 2 : 5 # 3 # A '#' character marks the beginning of a comment. A comment is ignored by the compiler, and serves the purpose of making things more clear to a human reader of the code. # 1. We begin a new word definition, and this word will be called main. # 2. 'main' is an entry point, this is called when your program starts up. # 3. A single ':' without any prefix marks the definition of the word. In this word, we're simply returning the number 5 (the last element in a definition is its return value). # Hit the 'run' button below to execute this simple Play program. """ |
> > > | | < | |
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 |
content : String content = """ # Welcome to the playground # Here you can learn the Play language by reading and toying around with examples. # A '#' character marks the beginning of a line comment. # Comments are ignored by the compiler, and serves the purpose of making things clearer for a human. # Below you'll find a simple word definition. # In other programming languages, this will usually be called a function definition. def: main # 1 entry: true # 2 : 5 # 3 # 1. We begin a new word definition, and this word will be called main. # 2. 'main' is an entry point, this is called when your program starts up. # 3. A single ':' without any prefix marks the definition of the word. In this word, we're simply returning the number 5 (the last element in a definition is its return value). # Hit the 'run' button above to execute this Play program. """ |
Modified src/Lesson02.elm from [d19f821ff3] to [b3cb2b9f78].
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
, content = String.trim <| String.unindent content } content : String content = """ # In the last lesson we saw that the last element in a word definition, was its return value. # In fact, words can have multiple return values: def: four-and-five : 4 5 # Play is stack oriented. What really happens in the word definition above is that, when executed, the numbers 4 and 5 will be put on a stack. # What happens when a word is placed on the stack? It executes! def: main entry: true : four-and-five + # Executing 'main' will first execute the word 'four-and-five', which will place the numbers 4 and 5 on the stack. # Then the word '+' will execute, which pops two numbers off the stack, adds them together, and places the sum on the stack. """ |
| > > | > | > > > > > |
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 39 40 41 |
, content = String.trim <| String.unindent content } content : String content = """ # In the last example we saw that the last element in a word definition, was returned. # In fact, words can have multiple return values: def: four-and-five : 4 5 # How does this work? # The first thing to understand is that Play is stack oriented. # What really happens in the word definition above is that, when executed, the numbers 4 and 5 will be put on a stack. # What happens when a word is placed on the stack? It executes! def: main entry: true : four-and-five + # Executing 'main' will first execute the word 'four-and-five' # 'four-and-five' will place the numbers 4 and 5 on the stack. # Then the word '+' will execute, which pops two numbers off the stack, adds them together, and places the sum on the stack. # Whatever is on the stack at the end of a program, is printed in the black box to the right. # There aren't really any return values. Every word simply accepts, modifies and returns a stack. """ |
Modified src/Lesson03.elm from [d7e6a2392a] to [35a77b6d6c].
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 |
, content = String.trim <| String.unindent content
}
content : String
content =
"""
# Sometimes it can be nice to re-arrange values on the stack, and Play has some built in words for that purpose.
# 'dup' let's you duplicate a value
def: square
: dup *
# 'swap' switches the positions of two values
# 'drop' discards a value
# When you have two values on the stack, like '4' and '5', you can drop '4' like this
def: drop-first
: swap drop
# There are more, but the ones listed above are the most common
def: main
entry: true
: 4 5
drop-first
square
"""
|
| > > > |
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 39 40 |
, content = String.trim <| String.unindent content } content : String content = """ # Sometimes it can be nice to re-arrange values on the stack. # Play has some built in words for that purpose. # 'dup' let's you duplicate a value def: square : dup * # 'swap' switches the positions of two values # 'drop' discards a value # When you have two values on the stack, like '4' and '5', you can drop '4' like this def: drop-first : swap drop # There are more, but the ones listed above are the most common def: main entry: true : 4 5 drop-first square """ |
Modified src/Lesson04.elm from [1b1a65d472] to [76b31e1469].
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
..
29
30
31
32
33
34
35
36
37
38
39
|
, content = String.trim <| String.unindent content } content : String content = """ # Play is staticly typed, but in most cases is smart enough to infer what the type of a word is without any input from you. # The word definitions in the previous lesson are shown here with type annotations. def: square type: Int -- Int : dup * def: drop-first type: Int Int -- Int ................................................................................ def: main type: -- Int entry: true : 4 5 drop-first square # '--' is what seperates inputs from outputs. # 'drop-first' requires two Int's to be on the stack, and will replace them with one Int. # 'main' requires nothing to be on the stack, and will add one Int to it. """ |
>
|
|
|
|
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
..
30
31
32
33
34
35
36
37
38
39
40
|
, content = String.trim <| String.unindent content } content : String content = """ # Play is staticly typed. # In most cases, Play is smart enough to infer what the type of words. # The word definitions in the previous example are shown here with type annotations. def: square type: Int -- Int : dup * def: drop-first type: Int Int -- Int ................................................................................ def: main type: -- Int entry: true : 4 5 drop-first square # '--' is what seperates requirements from results. # 'drop-first' requires two Int's to be on the stack, and will replace them with one Int. # 'main' requires nothing to be on the stack, and will add one Int to it. """ |
Modified src/Lesson05.elm from [bad0c08c86] to [705d93b1f7].
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
..
30
31
32
33
34
35
36
37
38
39
|
, content = String.trim <| String.unindent content
}
content : String
content =
"""
# Play allows you to define compound structures
deftype: Coordinate
: x Int
: y Int
# This will define a 'Coordinate' which has two members, x and y, which are integers.
................................................................................
# The '>' character can be read as 'into'. '>x' is then read as 'into x' and 'x>' is read as 'x into'. So either you're reading from the stack and into x, or from x into the stack.
def: main
type: -- Int
entry: true
: 1 2 >Coordinate # creates a Coordinate(x=1, y=2)
5 >x # Replaces the Coordinate(x=1, y=2) with Coordinate(x=5, y=2)
x> # Replaces the Coordinate(x=5, y=2) with the value of x.
"""
|
|
|
|
|
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
..
30
31
32
33
34
35
36
37
38
39
|
, content = String.trim <| String.unindent content } content : String content = """ # Play allows you to define compound structures. deftype: Coordinate : x Int : y Int # This will define a 'Coordinate' which has two members, x and y, which are integers. ................................................................................ # The '>' character can be read as 'into'. '>x' is then read as 'into x' and 'x>' is read as 'x into'. So either you're reading from the stack and into x, or from x into the stack. def: main type: -- Int entry: true : 1 2 >Coordinate # creates a Coordinate(x=1, y=2) 5 >x # Replaces the Coordinate(x=1, y=2) with Coordinate(x=5, y=2) x> # Replaces the Coordinate(x=5, y=2) with the value of x. """ |
Modified src/Lesson06.elm from [2dd2e36fca] to [647f69d864].
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
, content = String.trim <| String.unindent content } content : String content = """ # Play allows you to pass words around as arguments, and even construct anonymous words. # We call them quotations. Other languages call them anonymous functions. # For this example, let's bring back the Coordinate type from the previous lesson. deftype: Coordinate : x Int : y Int # Now, imagine we want to create a word that allows you to modify the 'x' member in any way imaginable. # This is a good use case for quotations. |
| | |
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
, content = String.trim <| String.unindent content } content : String content = """ # Play allows you to place word references on the stack, and even construct anonymous words. # We call them quotations. Other languages call them anonymous functions. # For this example, let's bring back the Coordinate type from the previous example. deftype: Coordinate : x Int : y Int # Now, imagine we want to create a word that allows you to modify the 'x' member in any way imaginable. # This is a good use case for quotations. |
Modified src/Lesson07.elm from [e9e29111cf] to [bfb7927262].
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
: Off
deftype: On
deftype: Off
# This defines a Union of On and Off, called State.
# Whenever you use State as a type, you're saying that it really could be either On or Off.
# To handle such types we need to use multi-words, which are words with a definition that depends on the type that is actually present.
defmulti: state->int
type: State -- Int
when: On
drop 1
when: Off
drop 0
def: main
entry: true
: >On state->int
"""
|
> | |
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
: Off deftype: On deftype: Off # This defines a Union of On and Off, called State. # Whenever you use State as a type, you're saying that it really could be either On or Off. # To handle such types we need to use multi-words. # Multi-words are words with a definition that depends on the type that is actually present on the stack. defmulti: state->int type: State -- Int when: On drop 1 when: Off drop 0 def: main entry: true : >On state->int """ |
Modified src/Lesson08.elm from [8b48ea0c66] to [418a8dc6b7].
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
, content = String.trim <| String.unindent content
}
content : String
content =
"""
# Multi words allows you to be very specific about when a specific condition applies.
deftype: Coordinate
: x Int
: y Int
defmulti: origo?
type: Coordinate -- Int
|
| |
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
, content = String.trim <| String.unindent content
}
content : String
content =
"""
# Multi-words allows you to be very specific about when a specific condition applies.
deftype: Coordinate
: x Int
: y Int
defmulti: origo?
type: Coordinate -- Int
|
Modified src/Lesson09.elm from [47060188a9] to [25dc9187ff].
45 46 47 48 49 50 51 52 53 |
# Here we can specify that the result of adding an element to a List, always result in a NonEmptyList. # A NonEmptyList is still a List, though. def: main entry: true : >EmptyList 10 push 0 first-or-default # Could have use 'first>' here """ |
| |
45 46 47 48 49 50 51 52 53 |
# Here we can specify that the result of adding an element to a List, always result in a NonEmptyList. # A NonEmptyList is still a List, though. def: main entry: true : >EmptyList 10 push 0 first-or-default # Could have used 'first>' here. """ |