Overview
Comment: | Fix typos and improve explination in several examples. |
---|---|
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
8879ef99d1c8318b54ce07ceb87400ee |
User & Date: | robin.hansen on 2020-11-20 05:35:57 |
Other Links: | manifest | tags |
Context
2020-11-20
| ||
05:55 | Re-worked hook text in header. Added footer with lead-developer name and link to twitter profile. Si... check-in: 108084d650 user: robin.hansen tags: trunk | |
05:35 | Fix typos and improve explination in several examples. check-in: 8879ef99d1 user: robin.hansen tags: trunk | |
05:28 | Use max-age instead of must-revalidate as cache settings on html pages. check-in: fc22552f03 user: robin.hansen tags: trunk | |
Changes
Modified src/Lesson01.elm from [c95826daba] to [1a1cfdb705].
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
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. |
> |
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
content : String
content =
"""
# Welcome to the playground
# Here you can learn the Play language by reading and toying around with examples.
# You can find more examples in the dropdown above.
# 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.
|
Modified src/Lesson04.elm from [76b31e1469] to [e29abb4f77].
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
..
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 ................................................................................ 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. """ |
|
|
|
|
|
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
..
30
31
32
33
34
35
36
37
38
39
40
|
, content = String.trim <| String.unindent content } content : String content = """ # Play is statically typed. # In most cases, Play is smart enough to infer the types. # The word definitions in the previous example are shown here with type annotations. def: square type: Int -- Int : dup * def: drop-first ................................................................................ def: main type: -- Int entry: true : 4 5 drop-first square # '--' is what separates requirements from results. # 'drop-first' requires two Ints 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 [705d93b1f7] to [715d3162cd].
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# This will define a 'Coordinate' which has two members, x and y, which are integers.
# Play will also generate some words for you to be able to read and modify this structure.
# '>Coordinate' is a word that requires two Ints to be on the stack, and will create a Coordinate with those numbers as x and y, respectively.
# '>x' and '>y' requires an Int and a Coordinate to be on the stack, and sets the x/y member to the provided Int.
# 'x>' and 'y>' will return the x/y value of a Coordinate, which must be on the stack.
# 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.
"""
|
> > | > > |
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# This will define a 'Coordinate' which has two members, x and y, which are integers. # Play will also generate some words for you to be able to read and modify this structure. # '>Coordinate' is a word that requires two Ints to be on the stack, and will create a Coordinate with those numbers as x and y, respectively. # '>x' and '>y' requires an Int and a Coordinate to be on the stack, and sets the x/y member to the provided Int. # 'x>' and 'y>' will return the x/y value of a Coordinate, which must be on the stack. # The '>' character can be read as 'into'. # '>x' is then read as 'into x' and 'x>' is read as 'x into'. # Either you're reading from the stack and into x, or from x into the stack. # Do note that '>' and '<' is not special syntax, but can be used in the name of any word. 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 [647f69d864] to [b06a29eede].
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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.
def: update-x
type: Coordinate [ Int -- Int ] -- Coordinate
: swap # bring Coordinate to the top of the stack
dup x> # read value of x without loosing the original Coordinate
-rotate # rotates the three top stack elements counter-clockwise
! # execute qutotation
>x # set x to whatever was returned by quotation
def: main
entry: true
: 1 2 >Coordinate
[ 1 + ] update-x
x>
# Quotations are wrapped in brackets. Think of them as inline word definitions.
"""
|
| |
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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.
def: update-x
type: Coordinate [ Int -- Int ] -- Coordinate
: swap # bring Coordinate to the top of the stack
dup x> # read value of x without loosing the original Coordinate
-rotate # rotates the three top stack elements one space to the left
! # execute qutotation
>x # set x to whatever was returned by quotation
def: main
entry: true
: 1 2 >Coordinate
[ 1 + ] update-x
x>
# Quotations are wrapped in brackets. Think of them as inline word definitions.
"""
|