Website

Check-in [ac29c88b97]
Login
Overview
Comment:Completed remaining examples.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: ac29c88b97a6e10459c6de67d4d90af1cf42f27f3458e76ee906920ed6847e4d
User & Date: robin.hansen on 2020-11-05 23:09:41
Other Links: manifest | tags
Context
2020-11-05
23:10
Clear result when switching lessons. check-in: 4003931997 user: robin.hansen tags: trunk
23:09
Completed remaining examples. check-in: ac29c88b97 user: robin.hansen tags: trunk
18:29
Setup remaining lessons. check-in: 6215453307 user: robin.hansen tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified playground/src/Lesson06.elm from [b712c7d379] to [2dd2e36fca].

11
12
13
14
15
16
17



























18
    , content = String.trim <| String.unindent content
    }


content : String
content =
    """



























    """







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

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
42
43
44
45
    , 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.

    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.
    """

Modified playground/src/Lesson07.elm from [72d7583a83] to [e9e29111cf].

11
12
13
14
15
16
17























18
    , content = String.trim <| String.unindent content
    }


content : String
content =
    """























    """







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

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 =
    """
    # Play supports the concept of a Union type

    defunion: State
    : On
    : 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
    """

Modified playground/src/Lesson08.elm from [096e68cb3c] to [8b48ea0c66].

11
12
13
14
15
16
17

















18
    , content = String.trim <| String.unindent content
    }


content : String
content =
    """

















    """







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

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
    , 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
    when: Coordinate( x 0 y 0 )
      drop 1
    when: Coordinate
      drop 0

    def: main
    entry: true
    : 1 1 >Coordinate
      origo?
    """

Modified playground/src/Lesson09.elm from [4f078a733f] to [47060188a9].

11
12
13
14
15
16
17



































18
    , content = String.trim <| String.unindent content
    }


content : String
content =
    """



































    """







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

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
42
43
44
45
46
47
48
49
50
51
52
53
    , content = String.trim <| String.unindent content
    }


content : String
content =
    """
    # Unions allow for some interesting API designs.
    # Let's implement a List data structure.

    defunion: List a
    : NonEmptyList a
    : EmptyList

    deftype: NonEmptyList a
    : first a
    : rest (List a)

    deftype: EmptyList

    # Notice retrieving the first element of a list can only be done if you have a NonEmptyList.
    # Also notice that a lowercased type acts as a placeholder for any type, a generic type.

    def: push
    type: (List a) a -- (NonEmptyList a)
    : swap >NonEmptyList

    defmulti: first-or-default
    type: (List a) a -- a
    when: NonEmptyList
      drop first>
    when: EmptyList
      swap drop

    # 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
    """