git @ Cat's Eye Technologies Robin / a697615
Finish documenting the `list` module. catseye 13 years ago
2 changed file(s) with 58 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
115115 `disj` are probably fine names for the n-ary versions of those
116116 operations; they can each take a single list as their argument.
117117
118 * Establish a convention for "side-effecting" operations and make all the
119 names in the standard modules follow it.
120
118121 * Possibly add alist functions to the `list` module, or create a new `alist`
119122 module for that purpose: `lookup`, `insert` (?), and `remove`.
120123
121124 * Write a `timer` module which exports a process which can be asked
122125 (via a message) to send back a message after a given time has passed.
123126 This could be used to build a version of `recv` which can time out.
127
128 * Write a `console` module which exports a process with an interface
129 similar to `Console::Virtual`'s. In the reference interpreter, this can
130 be implemented with `hscurses`. (But don't make `hscurses` a strict
131 requirement for building the reference interpreter.)
124132
125133 * Write a `functional` module which exports some functions for working
126134 with functions, such as `identity`, `compose`, and possibly `curry`
158166 * Document the `boolean` module.
159167
160168 * Document the `arith` module.
161
162 * Finish documenting the `list` module.
163169
164170 * Document the "why" behind some of the design decisions. Particularly,
165171 why S-expression based syntax, why import can only be done at the top
195201 * Write a `pixley` module which exports only the identifiers supported
196202 by Pixley. This could be imported, instead of `core`, to emulate
197203 Pixley in Robin.
204
205 * Using the `console` module, write `robotfindskitten` in Robin!
246246
247247 ### `length` ###
248248
249 `length` evaluates its single argument to obtain a proper list, then
250 evaluates to a non-negative integer which is the length of the list
251 (the number of pairs, not counting nested pairs and not counting the
252 empty list at the very tail.)
253
249254 | (robin (0 . 1) (small (0 . 1) list (0 . 1))
250255 | (length ()))
251256 = 0
253258 | (robin (0 . 1) (small (0 . 1) list (0 . 1))
254259 | (length (list 1 2 #t #f 3)))
255260 = 5
261
262 | (robin (0 . 1) (small (0 . 1) list (0 . 1))
263 | (length (literal (1 2 #t #f . 3))))
264 ? robin: uncaught exception: (expected-pair . 3)
256265
257266 | (robin (0 . 1) (small (0 . 1) list (0 . 1))
258267 | (length (literal whatnot)))
298307
299308 ### `take-while` ###
300309
310 `take-while` evaluates its first argument to obtain a predicate and its
311 second argument to obtain a list. It then evaluates to the longest prefix
312 of the list whose elements all satisfy the predicate.
313
301314 | (robin (0 . 1) (small (0 . 1) list (0 . 1))
302315 | (take-while (fun (x) (symbol? x)) (literal (one two 3 4 five 6 seven))))
303316 = (one two)
311324 = (1 2 3 4 5 6)
312325
313326 | (robin (0 . 1) (small (0 . 1) list (0 . 1))
327 | (take-while (fun (x) (number? x)) (literal (1 2 3 #f 5 . 6))))
328 = (1 2 3)
329
330 | (robin (0 . 1) (small (0 . 1) list (0 . 1))
331 | (take-while (fun (x) (number? x)) (literal (1 2 3 4 5 . #f))))
332 ? robin: uncaught exception: (expected-pair . #f)
333
334 | (robin (0 . 1) (small (0 . 1) list (0 . 1))
314335 | (take-while (fun (x) (symbol? x)) ()))
315336 = ()
316337
320341
321342 ### `drop-while` ###
322343
344 `drop-while` evaluates its first argument to obtain a predicate and its
345 second argument to obtain a list. It then evaluates to the suffix of the
346 given list, starting at the first element which does not satisfy the
347 predicate.
348
323349 | (robin (0 . 1) (small (0 . 1) list (0 . 1))
324350 | (drop-while (fun (x) (symbol? x)) (literal (one two 3 4 five 6 seven))))
325351 = (3 4 five 6 seven)
333359 = ()
334360
335361 | (robin (0 . 1) (small (0 . 1) list (0 . 1))
362 | (drop-while (fun (x) (symbol? x)) (literal (one two 3 4 five 6 . seven))))
363 = (3 4 five 6 . seven)
364
365 | (robin (0 . 1) (small (0 . 1) list (0 . 1))
366 | (drop-while (fun (x) (symbol? x)) (literal (one two . three))))
367 ? robin: uncaught exception: (expected-pair . three)
368
369 | (robin (0 . 1) (small (0 . 1) list (0 . 1))
336370 | (drop-while (fun (x) (symbol? x)) ()))
337371 = ()
338372
342376
343377 ### `first` ###
344378
379 `first` evaluates its first argument to obtain a non-negative integer,
380 considered to be a desired length, and its second argument to obtain a list.
381 It then evaluates to the prefix of the given list of the desired length.
382
345383 | (robin (0 . 1) (small (0 . 1) list (0 . 1))
346384 | (first 0 (list 1 2 3 4 5)))
347385 = ()
368406
369407 ### `rest` ###
370408
409 `rest` evaluates its first argument to obtain a non-negative integer,
410 considered to be a desired position, and its second argument to obtain a
411 list. It then evaluates to the suffix of the given list starting at the
412 desired position. The position 0 indicates the beginning of the list.
413
371414 | (robin (0 . 1) (small (0 . 1) list (0 . 1))
372415 | (rest 0 (list 1 2 3 4 5)))
373416 = (1 2 3 4 5)
397440 = foo
398441
399442 ### `last` ###
443
444 `rest` evaluates its first argument to obtain a non-negative integer,
445 considered to be a desired length, and its second argument to obtain a
446 list. It then evaluates to the suffix of the given list of the desired
447 length.
400448
401449 | (robin (0 . 1) (small (0 . 1) list (0 . 1))
402450 | (last 0 (list 1 2 3 4 5)))