246 | 246 |
|
247 | 247 |
### `length` ###
|
248 | 248 |
|
|
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 |
|
249 | 254 |
| (robin (0 . 1) (small (0 . 1) list (0 . 1))
|
250 | 255 |
| (length ()))
|
251 | 256 |
= 0
|
|
253 | 258 |
| (robin (0 . 1) (small (0 . 1) list (0 . 1))
|
254 | 259 |
| (length (list 1 2 #t #f 3)))
|
255 | 260 |
= 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)
|
256 | 265 |
|
257 | 266 |
| (robin (0 . 1) (small (0 . 1) list (0 . 1))
|
258 | 267 |
| (length (literal whatnot)))
|
|
298 | 307 |
|
299 | 308 |
### `take-while` ###
|
300 | 309 |
|
|
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 |
|
301 | 314 |
| (robin (0 . 1) (small (0 . 1) list (0 . 1))
|
302 | 315 |
| (take-while (fun (x) (symbol? x)) (literal (one two 3 4 five 6 seven))))
|
303 | 316 |
= (one two)
|
|
311 | 324 |
= (1 2 3 4 5 6)
|
312 | 325 |
|
313 | 326 |
| (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))
|
314 | 335 |
| (take-while (fun (x) (symbol? x)) ()))
|
315 | 336 |
= ()
|
316 | 337 |
|
|
320 | 341 |
|
321 | 342 |
### `drop-while` ###
|
322 | 343 |
|
|
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 |
|
323 | 349 |
| (robin (0 . 1) (small (0 . 1) list (0 . 1))
|
324 | 350 |
| (drop-while (fun (x) (symbol? x)) (literal (one two 3 4 five 6 seven))))
|
325 | 351 |
= (3 4 five 6 seven)
|
|
333 | 359 |
= ()
|
334 | 360 |
|
335 | 361 |
| (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))
|
336 | 370 |
| (drop-while (fun (x) (symbol? x)) ()))
|
337 | 371 |
= ()
|
338 | 372 |
|
|
342 | 376 |
|
343 | 377 |
### `first` ###
|
344 | 378 |
|
|
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 |
|
345 | 383 |
| (robin (0 . 1) (small (0 . 1) list (0 . 1))
|
346 | 384 |
| (first 0 (list 1 2 3 4 5)))
|
347 | 385 |
= ()
|
|
368 | 406 |
|
369 | 407 |
### `rest` ###
|
370 | 408 |
|
|
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 |
|
371 | 414 |
| (robin (0 . 1) (small (0 . 1) list (0 . 1))
|
372 | 415 |
| (rest 0 (list 1 2 3 4 5)))
|
373 | 416 |
= (1 2 3 4 5)
|
|
397 | 440 |
= foo
|
398 | 441 |
|
399 | 442 |
### `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.
|
400 | 448 |
|
401 | 449 |
| (robin (0 . 1) (small (0 . 1) list (0 . 1))
|
402 | 450 |
| (last 0 (list 1 2 3 4 5)))
|