r3/barewords.tng
author Tony Garnock-Jones <tonygarnockjones@gmail.com>
Wed, 16 Jan 2019 17:15:58 +0000
changeset 438 1fe179d53161
parent 46 6a9fab6479be
permissions -rw-r--r--
Add missing primitive implementation for the plain interpreter.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
     1
define [
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
     2
  .proto: [.list: .nil]
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
     3
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
     4
  (x=[.list: _] .initialize: aList):
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
     5
    (x \ [.list: aList])
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
     6
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
     7
  (x=[.list: l] .with: aThing):
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
     8
    (x \ [.list: (l .with: aThing)])
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
     9
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    10
  (x=[.list: l] .handle):
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    11
    (l .do: [eachItem: eachItem .print])
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    12
];;
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    13
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    14
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    15
define [
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    16
  proto: [list: nil]
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    17
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    18
  (.x=[list: _] initialize: .aList):
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    19
    (.x \ [list: .aList])
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    20
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    21
  (.x=[list: .l] with: .aThing):
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    22
    (.x \ [list: (.l with: .aThing)])
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    23
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    24
  (.x=[list: .l] handle):
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    25
    (.l do: [.eachItem: .eachItem print])
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    26
];;
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    27
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    28
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    29
"
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    30
The problem is really barewords. (Or applications, if you want to look at it that way.)
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    31
What if application got syntax? f $ x
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    32
$ looks like S, for Send
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    33
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    34
We need to do something about bindings, too.
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    35
var=pattern ?
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    36
var@pattern ?
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    37
"
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    38
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    39
define [
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    40
  proto: [list: nil]
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    41
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    42
  (x=[list: _] initialize: aList=_):
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    43
    (x \ [list: aList])
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    44
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    45
  (x=[list: l=_] with: aThing=_):
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    46
    (x \ [list: (l with: aThing)])
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    47
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    48
  (x=[list: l=_] handle):
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    49
    (l do: [eachItem=_: eachItem print])
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    50
];;
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    51
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    52
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    53
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    54
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    55
[self
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    56
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    57
  .list: .nil
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    58
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    59
  [.initialize: aList]:
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    60
    (self \ [.list: aList])
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    61
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    62
  [.with: aThing]:
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    63
    (self \ [.list: (self.list .with: aThing)])
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    64
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    65
  .handle:
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    66
    (self.list [.do: [eachItem: eachItem.print]])
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    67
];;
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    68
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    69
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    70
[.self
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    71
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    72
  list: nil
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    73
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    74
  [initialize: .aList]:
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    75
    (.self \ [list: .aList])
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    76
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    77
  [with: .aThing]:
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    78
    (.self \ [list: (.self list with: .aThing)])
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    79
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    80
  handle:
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    81
    (.self list [do: [.eachItem: .eachItem print]])
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    82
];;
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    83
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    84
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    85
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    86
initialize: aList
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    87
     list := aList.
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    88
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    89
add: aThing
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    90
     list add: aThing.
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    91
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    92
handle
6a9fab6479be More syntax thoughts.
Tony Garnock-Jones <tonyg@lshift.net>
parents:
diff changeset
    93
    list do: [:eachItem | eachItem print].