~repos /plum

#treesitter#compiler#wasm

git clone https://pyrossh.dev/repos/plum.git
Discussions: https://groups.google.com/g/rust-embed-devs

A statically typed, imperative programming language inspired by rust, python


de232c45 pyrossh

1 year ago
docs
Files changed (2) hide show
  1. std/list.mi +85 -14
  2. std/str.mi +35 -3
std/list.mi CHANGED
@@ -2,9 +2,9 @@ module std
2
2
 
3
3
  `A list is a data structure describing a contiguous section of an array stored separately from the slice variable itself.
4
4
  `It contains the pointers to the start and end nodes (head, tail) and maintains the size as well
5
- record list<V>(
5
+ record list[V](
6
- head: node?
6
+ head: node[V]?
7
- tail: node?
7
+ tail: node[V]?
8
8
  size: int
9
9
  )
10
10
 
@@ -17,7 +17,14 @@ record node[V](
17
17
 
18
18
  fn (l: list) get(i: int): A =
19
19
  `gets the element at i'th index of the list
20
+ current := l.head
21
+ index := 0
22
+ while current != nil
23
+ if index == i
24
+ current.value
20
- pass
25
+ else
26
+ current = current.next
27
+ index += 1
21
28
 
22
29
  fn (l: list) set(i: int, v: V): A =
23
30
  `sets the element at i'th index of the list
@@ -36,30 +43,43 @@ fn (l: list) remove(i int) =
36
43
  l.tail = list.tail?.prev
37
44
  l.size -= 1
38
45
 
39
- fn (l: list) some(predicate: fn(v: V): bool) =
46
+ fn (l: list) reverse(v: fn(v: V): true): list[A] =
40
- `returns true if any element in the list satisfies the predicate
47
+ `returns a new list with the elements in reverse order.
41
48
  pass
42
49
 
50
+ fn (l: list) sort(sorter: fn(v: V): true): list[A] =
51
+ `returns a new list with the elements sorted by sorter
52
+ pass
43
53
 
44
- fn (l: list) reversed(v: fn(v: V): true) =
54
+ fn (l: list) find(search: V): V? =
45
- `returns a new list with the elements in reverse order.
55
+ `returns an item in the list if the item is is equal to search item
56
+ pass
57
+
58
+ fn (l: list) find_index(search: V): int? =
59
+ `returns the index of an item in the list if present and comparable otherwise nil
46
60
  pass
47
61
 
48
- fn (l: list) sort(v: fn(v: V): true) =
62
+ fn (l: list) contains(v: V): int? =
49
- `returns a new list with the elements sorted in ascending order.
63
+ `returns the index of an item in the list if present and comparable otherwise nil
64
+ pass
65
+
66
+ fn (l: list) concat(ol: list): list[A] =
67
+ `returns the index of an item in the list if present and comparable otherwise nil
50
68
  pass
51
69
 
52
- fn (l: list) indexOf(v: V): int? =
70
+ fn (l: list) sub_list(start: int, end: int?): list[A] =
53
71
  `returns the index of an item in the list if present and comparable otherwise nil
54
72
  pass
55
73
 
56
- fn (l: list) each(cb: fn(v: V)) =
74
+ fn (l: list) each(cb: fn(v: V)): void =
75
+ `calls f for each elem in the list
57
76
  current := l.head
58
77
  while current != nil
59
78
  cb(current.value)
60
79
  current = current.next
61
80
 
62
- fn (l: list) map(cb: fn(v: V): A): list[A] =
81
+ fn (l: list) map[B](cb: fn(v: V): B): list[A] =
82
+ `returns a list made up of B elements for each elem in the list
63
83
  nl := []
64
84
  current := l.head
65
85
  while current != nil
@@ -67,15 +87,66 @@ fn (l: list) map(cb: fn(v: V): A): list[A] =
67
87
  nl.push(item)
68
88
  nl
69
89
 
90
+ fn (l: list) flat_map() =
91
+ `returns a new list with all elements shuffled`
92
+ pass
93
+
70
94
  fn (l: list) retain(predicate: fn(v: V): A): list[A] =
71
95
  `returns a new list with the elements that matched the predicate
72
96
  pass
73
97
 
98
+ fn (l: list) reject(predicate: fn(v: V): A): list[A] =
99
+ `returns a new list with the elements that matched the predicate removed
100
+ pass
101
+
102
+ fn (l: list) any(predicate: fn(v: V): bool) =
103
+ `returns true if any element in the list satisfies the predicate
104
+ pass
105
+
106
+ fn (l: list) all(predicate: fn(v: V): bool) =
107
+ `returns true if all of the elements in the list satisfies the predicate
108
+ pass
109
+
74
110
  fn (l: list) reduce[B](acc: B, cb: fn(v: V): A): B =
75
111
  `returns the accumulated value of all the elements in the list
76
112
  pass
77
113
 
114
+ fn (l: list) first(): A? =
115
+ `returns the first element in the list
116
+ l.head?.value
117
+
118
+ fn (l: list) last(): A? =
119
+ `returns the last element in the list
120
+ l.tail?.value
121
+
122
+ fn (l: list) take(n: int): list[A] =
123
+ `returns a list containing the first n elements of the given list
124
+ pass
125
+
126
+ fn (l: list) drop(n: int): list[A] =
127
+ `Returns a list containing the first n elements of the given list
128
+
129
+ fn (l: list) sample() =
130
+ `returns a new list with all elements shuffled`
131
+ pass
132
+
133
+ fn (l: list) shuffle() =
134
+ `returns a new list with all elements shuffled`
135
+ pass
136
+
137
+ fn (l: list) partition() =
138
+ `returns a new list with all elements shuffled`
139
+ pass
140
+
141
+ fn (l: list) chunk() =
142
+ `returns a new list with all elements shuffled`
143
+ pass
144
+
145
+ fn (l: list) group_by() =
146
+ `returns a new list with all elements shuffled`
147
+ pass
148
+
78
- fn (l: list) to_str() =
149
+ fn (l: list) to_str(): str =
79
150
  res := Buffer()
80
151
  l.each() |v|
81
152
  if @HasTrait(V, ToStr)
std/str.mi CHANGED
@@ -97,7 +97,7 @@ fn (s str) pad_start(sub: str, count: int): str =
97
97
 
98
98
  fn search(pattern: Regex): str =
99
99
  pass
100
-
100
+
101
101
  fn slice(start: int, end: int): str =
102
102
  pass
103
103
 
@@ -115,7 +115,7 @@ fn (s str) pad_start(sub: str, count: int): str =
115
115
 
116
116
  fn trim(): str =
117
117
  pass
118
-
118
+
119
119
  fn trim_start(): str =
120
120
  pass
121
121
 
@@ -145,4 +145,36 @@ fn (s str) pad_start(sub: str, count: int): str =
145
145
  match to_lower()
146
146
  "true" -> bool::true
147
147
  "false" -> bool::false
148
- _ -> error("could not parse bool '${this}'")
148
+ _ -> error("could not parse bool '${this}'")
149
+
150
+
151
+ _.camelCase
152
+ _.capitalize
153
+ _.deburr
154
+ _.endsWith
155
+ _.escape
156
+ _.escapeRegExp
157
+ _.kebabCase
158
+ _.lowerCase
159
+ _.lowerFirst
160
+ _.pad
161
+ _.padEnd
162
+ _.padStart
163
+ _.parseInt
164
+ _.repeat
165
+ _.replace
166
+ _.snakeCase
167
+ _.split
168
+ _.startCase
169
+ _.startsWith
170
+ _.template
171
+ _.toLower
172
+ _.toUpper
173
+ _.trim
174
+ _.trimEnd
175
+ _.trimStart
176
+ _.truncate
177
+ _.unescape
178
+ _.upperCase
179
+ _.upperFirst
180
+ _.words