Overview
Comment: | Added the first five lessons. |
---|---|
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
f8c89b049fbddd3fa00474960c2ee104 |
User & Date: | robin.hansen on 2020-11-05 18:21:48 |
Other Links: | manifest | tags |
Context
2020-11-05
| ||
18:29 | Setup remaining lessons. check-in: 6215453307 user: robin.hansen tags: trunk | |
18:21 | Added the first five lessons. check-in: f8c89b049f user: robin.hansen tags: trunk | |
2020-11-04
| ||
06:30 | Repl now actually works! Code is executed and potential errors reported. check-in: 73f643169e user: robin.hansen tags: trunk | |
Changes
Modified playground/src/Lesson01.elm from [da64e366ea] to [77584887af].
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import LessonContract exposing (LessonContract)
import String.Extra as String
contract : LessonContract
contract =
{ key = "L01"
, label = "Lesson 1"
, content = String.trim <| String.unindent content
}
content : String
content =
"""
# Welcome to the playground
"""
|
| > > > > > > > > > > > > > > > > |
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 |
import LessonContract exposing (LessonContract) import String.Extra as String contract : LessonContract contract = { key = "L01" , label = "Word definition" , content = String.trim <| String.unindent content } 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. """ |
Modified playground/src/Lesson02.elm from [34a3c501d7] to [d19f821ff3].
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import LessonContract exposing (LessonContract) import String.Extra as String contract : LessonContract contract = { key = "L02" , label = "Lesson 2" , content = String.trim <| String.unindent content } content : String content = """ # Welcome to Lesson 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 |
import LessonContract exposing (LessonContract) import String.Extra as String contract : LessonContract contract = { key = "L02" , label = "Stack orientation" , 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. """ |
Added playground/src/Lesson03.elm version [d7e6a2392a].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
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 |
module Lesson03 exposing (contract) import LessonContract exposing (LessonContract) import String.Extra as String contract : LessonContract contract = { key = "L03" , label = "Stack manipulation" , 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 """ |
Added playground/src/Lesson04.elm version [1b1a65d472].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
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 39 |
module Lesson04 exposing (contract) import LessonContract exposing (LessonContract) import String.Extra as String contract : LessonContract contract = { key = "L04" , label = "Types" , 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 : swap drop 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. """ |
Added playground/src/Lesson05.elm version [bad0c08c86].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
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 39 |
module Lesson05 exposing (contract) import LessonContract exposing (LessonContract) import String.Extra as String contract : LessonContract contract = { key = "L05" , label = "Compound structures" , 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. # 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. """ |
Modified playground/src/Playground.elm from [000c661098] to [710459085c].
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 |
import Browser import Dict exposing (Dict) import Html exposing (Html) import Html.Attributes as Attributes import Html.Events as Events import Lesson01 import Lesson02 import LessonContract exposing (LessonContract) -- LESSONS lessons : Dict String LessonContract lessons = [ Lesson01.contract , Lesson02.contract ] |> List.map LessonContract.asDictEntry |> Dict.fromList -- MODEL |
> > > > > > |
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 |
import Browser import Dict exposing (Dict) import Html exposing (Html) import Html.Attributes as Attributes import Html.Events as Events import Lesson01 import Lesson02 import Lesson03 import Lesson04 import Lesson05 import LessonContract exposing (LessonContract) -- LESSONS lessons : Dict String LessonContract lessons = [ Lesson01.contract , Lesson02.contract , Lesson03.contract , Lesson04.contract , Lesson05.contract ] |> List.map LessonContract.asDictEntry |> Dict.fromList -- MODEL |