Changeset 34971 in project
 Timestamp:
 12/29/17 21:35:14 (12 months ago)
 Location:
 wiki/man/5
 Files:

 1 deleted
 1 edited
Legend:
 Unmodified
 Added
 Removed

wiki/man/5/Module (chicken base)
r34904 r34971 307 307 === Lists 308 308 309 ==== alistref 310 311 <procedure>(alistref KEY ALIST [TEST [DEFAULT]])</procedure> 312 313 Looks up {{KEY}} in {{ALIST}} using {{TEST}} as the comparison function (or {{eqv?}} if 314 no test was given) and returns the cdr of the found pair, or {{DEFAULT}} (which defaults to {{#f}}). 315 316 317 ==== alistupdate 318 319 <procedure>(alistupdate KEY VALUE ALIST [TEST])</procedure> 320 <procedure>(alistupdate! KEY VALUE ALIST [TEST])</procedure> 321 322 If the list {{ALIST}} contains a pair of the form {{(KEY . X)}}, then this procedure 323 replaces {{X}} with {{VALUE}} and returns {{ALIST}}. If {{ALIST}} contains no such item, then 324 {{alistupdate}} returns {{((KEY . VALUE) . ALIST)}}. The optional argument 325 {{TEST}} specifies the comparison procedure to search a matching pair in {{ALIST}} 326 and defaults to {{eqv?}}. {{alistupdate!}} is the destructive version of {{alistupdate}}. 327 328 329 ==== atom? 330 331 <procedure>(atom? X)</procedure> 332 333 Returns {{#t}} if {{X}} is not a pair. 334 335 336 ==== butlast 337 338 <procedure>(butlast LIST)</procedure> 339 340 Returns a fresh list with all elements but the last of {{LIST}}. 341 342 343 ==== chop 344 345 <procedure>(chop LIST N)</procedure> 346 347 Returns a new list of sublists, where each sublist contains {{N}} 348 elements of {{LIST}}. If {{LIST}} has a length that is not 349 a multiple of {{N}}, then the last sublist contains the remaining 350 elements. 351 352 <enscript highlight=scheme> 353 (chop '(1 2 3 4 5 6) 2) ==> ((1 2) (3 4) (5 6)) 354 (chop '(a b c d) 3) ==> ((a b c) (d)) 355 </enscript> 356 357 358 ==== compress 359 360 <procedure>(compress BLIST LIST)</procedure> 361 362 Returns a new list with elements taken from {{LIST}} with 363 corresponding true values in the list {{BLIST}}. 364 365 <enscript highlight=scheme> 366 (define nums '(99 100 110 401 1234)) 367 (compress (map odd? nums) nums) ==> (99 401) 368 </enscript> 369 370 371 ==== flatten 372 373 <procedure>(flatten LIST1 ...)</procedure> 374 375 Returns {{LIST1 ...}} concatenated together, with nested lists 376 removed (flattened). 377 378 309 379 ==== foldl 310 380 … … 333 403 (foldr + 0 '(1 2 3)) ==> (+ 1 (+ 2 (+ 3 0))) 334 404 </enscript> 405 406 407 ==== intersperse 408 409 <procedure>(intersperse LIST X)</procedure> 410 411 Returns a new list with {{X}} placed between each element. 412 413 414 ==== join 415 416 <procedure>(join LISTOFLISTS [LIST])</procedure> 417 418 Concatenates the lists in {{LISTOFLISTS}} with {{LIST}} placed 419 between each sublist. {{LIST}} defaults to the empty list. 420 421 <enscript highlight=scheme> 422 (join '((a b) (c d) (e)) '(x y)) ==> (a b x y c d x y e) 423 (join '((p q) () (r (s) t)) '()) ==> (p q   r (s) t) 424 </enscript> 425 426 {{join}} could be implemented as follows: 427 428 <enscript highlight=scheme> 429 (define (join lstoflsts #!optional (lst '())) 430 (apply append (intersperse lstoflists lst)) ) 431 </enscript> 432 433 434 ==== rassoc 435 436 <procedure>(rassoc KEY LIST [TEST])</procedure> 437 438 Similar to {{assoc}}, but compares {{KEY}} with the {{cdr}} of each pair in {{LIST}} using 439 {{TEST}} as the comparison procedures (which defaults to {{eqv?}}. 440 441 442 ==== tail? 443 444 <procedure>(tail? X LIST)</procedure> 445 446 Returns true if {{X}} is one of the tails (cdr's) of {{LIST}}. 335 447 336 448 … … 370 482 371 483 {{subvector}} was introduced in CHICKEN 4.7.3. 484 485 486 === Combinators 487 488 489 ==== constantly 490 491 <procedure>(constantly X ...)</procedure> 492 493 Returns a procedure that always returns the values {{X ...}} regardless of the number and value of its arguments. 494 495 <enscript highlight=scheme> 496 (constantly X) <=> (lambda args X) 497 </enscript> 498 499 500 ==== complement 501 502 <procedure>(complement PROC)</procedure> 503 504 Returns a procedure that returns the boolean inverse of {{PROC}}. 505 506 <enscript highlight=scheme> 507 (complement PROC) <=> (lambda (x) (not (PROC x))) 508 </enscript> 509 510 511 ==== compose 512 513 <procedure>(compose PROC1 PROC2 ...)</procedure> 514 515 Returns a procedure that represents the composition of the 516 argumentprocedures {{PROC1 PROC2 ...}}. 517 518 <enscript highlight=scheme> 519 (compose F G) <=> (lambda args 520 (callwithvalues 521 (lambda () (apply G args)) 522 F)) 523 </enscript> 524 525 {{(compose)}} is equivalent to {{values}}. 526 527 528 ==== conjoin 529 530 <procedure>(conjoin PRED ...)</procedure> 531 532 Returns a procedure that returns {{#t}} if its argument satisfies the 533 predicates {{PRED ...}}. 534 <enscript highlight=scheme> 535 ((conjoin odd? positive?) 33) ==> #t 536 ((conjoin odd? positive?) 33) ==> #f 537 </enscript> 538 539 540 ==== disjoin 541 542 <procedure>(disjoin PRED ...)</procedure> 543 544 Returns a procedure that returns {{#t}} if its argument satisfies any 545 predicate {{PRED ...}}. 546 <enscript highlight=scheme> 547 ((disjoin odd? positive?) 32) ==> #t 548 ((disjoin odd? positive?) 32) ==> #f 549 </enscript> 550 551 552 ==== each 553 554 <procedure>(each PROC ...)</procedure> 555 556 Returns a procedure that applies {{PROC ...}} to its arguments, and returns the result(s) 557 of the last procedure application. For example 558 559 <enscript highlight=scheme> 560 (each pp eval) 561 </enscript> 562 563 is equivalent to 564 565 <enscript highlight=scheme> 566 (lambda args 567 (apply pp args) 568 (apply eval args) ) 569 </enscript> 570 571 {{(each PROC)}} is equivalent to {{PROC}} and {{(each)}} is equivalent to 572 {{void}}. 573 574 575 ==== flip 576 577 <procedure>(flip PROC)</procedure> 578 579 Returns a twoargument procedure that calls {{PROC}} with its 580 arguments swapped: 581 <enscript highlight=scheme> 582 (flip PROC) <=> (lambda (x y) (PROC y x)) 583 </enscript> 584 585 586 ==== identity 587 588 <procedure>(identity X)</procedure> 589 590 Returns its sole argument {{X}}. 591 592 593 ==== listof? 594 595 <procedure>(listof? PRED)</procedure> 596 597 Returns a procedure of one argument that returns {{#t}} when 598 applied to a list of elements that all satisfy the predicate procedure 599 {{PRED}}, or {{#f}} otherwise. 600 601 <enscript highlight=scheme> 602 ((listof? even?) '(1 2 3)) ==> #f 603 ((listof? number?) '(1 2 3)) ==> #t 604 </enscript> 605 606 607 ==== o 608 609 <procedure>(o PROC ...)</procedure> 610 611 A single value version of {{compose}} (slightly faster). {{(o)}} is equivalent 612 to {{identity}}. 372 613 373 614
Note: See TracChangeset
for help on using the changeset viewer.