Changeset 13831 in project for chicken


Ignore:
Timestamp:
03/18/09 18:47:28 (11 years ago)
Author:
Kon Lovett
Message:

Use of random for *nix systems, use of srandomev for gnu systems. Rmvd data-structures stuff from Unit extras manual, modified `random' description to indicate integer values & not exact integer.

Location:
chicken/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • chicken/trunk/extras.scm

    r13544 r13831  
    8686;;; Random numbers:
    8787
    88 (define random-seed
    89     (let ((srand   (foreign-lambda void "srand" unsigned-integer)))
     88(cond-expand
     89  (unix
     90
     91    (define random-seed)
     92    (define randomize)
     93
     94    (let ((srandom (foreign-lambda void "srandom" unsigned-integer)))
     95
     96      (set! random-seed
     97        (lambda (#!optional (seed (current-seconds)))
     98          (##sys#check-integer seed 'random-seed)
     99          (srandom seed) ) )
     100
     101      (set! randomize
     102        (lambda (#!optional (seed (##sys#fudge 2)))
     103          (##sys#check-exact seed 'randomize)
     104          (srandom seed) ) ) )
     105
     106    (define (random n)
     107      (##sys#check-integer n 'random)
     108      (if (eq? 0 n)
     109          0
     110          ((foreign-lambda* long ((integer64 n)) "return( random() % ((uint64_t) n) );") n) ) ) )
     111  (else
     112
     113    (define random-seed
     114      (let ((srand (foreign-lambda void "srand" unsigned-integer)))
    90115        (lambda n
    91             (and (> (length n) 1)
    92                  (##sys#error 'random-seed "too many arguments" (length n) 1))
    93             (let ((t   (if (null? n)
    94                            (current-seconds)
    95                            (car n))))
    96                 (##sys#check-integer t 'random-seed)
    97                 (srand t)))))
    98 
    99 (define (random n)
    100   (##sys#check-exact n 'random)
    101   (if (eq? n 0)
    102       0
    103       (##core#inline "C_random_fixnum" n) ) )
    104 
    105 (define (randomize . n)
    106   (##core#inline
    107    "C_randomize"
    108    (if (##core#inline "C_eqp" n '())
    109        (##sys#fudge 2)
    110        (let ((nn (##sys#slot n 0)))
    111          (##sys#check-exact nn 'randomize)
    112          nn) ) ) )
     116          (let ((t (if (null? n) (current-seconds) (car n))))
     117            (##sys#check-integer t 'random-seed)
     118            (srand t) ) ) ) )
     119
     120    (define (randomize . n)
     121      (let ((nn (if (null? n) (##sys#fudge 2) (car n))))
     122        (##sys#check-exact nn 'randomize)
     123        (##core#inline "C_randomize" nn) ) )
     124
     125    (define (random n)
     126      (##sys#check-exact n 'random)
     127      (if (eq? n 0)
     128          0
     129          (##core#inline "C_random_fixnum" n) ) ) ) )
    113130
    114131
  • chicken/trunk/manual/Unit data-structures

    r13683 r13831  
    6767(chop '(a b c d) 3)     ==> ((a b c) (d))
    6868</enscript>
    69 
    7069
    7170
  • chicken/trunk/manual/Unit extras

    r13740 r13831  
    44== Unit extras
    55
    6 This unit contains a collection of useful utility definitions.
    7 This unit is used by default, unless the program
    8 is compiled with the {{-explicit-use}} option.
    9 
    10 
    11 === Lists
    12 
    13 
    14 ==== alist-ref
    15 
    16  [procedure] (alist-ref KEY ALIST [TEST [DEFAULT]])
    17 
    18 Looks up {{KEY}} in {{ALIST}} using {{TEST}} as the comparison function (or {{eqv?}} if
    19 no test was given) and returns the cdr of the found pair, or {{DEFAULT}} (which defaults to {{#f}}).
    20 
    21 
    22 ==== alist-update!
    23 
    24  [procedure] (alist-update! KEY VALUE ALIST [TEST])
    25 
    26 If the list {{ALIST}} contains a pair of the form {{(KEY . X)}}, then this procedure
    27 replaces {{X}} with {{VALUE}} and returns {{ALIST}}. If {{ALIST}} contains no such item, then
    28 {{alist-update!}} returns {{((KEY . VALUE) . ALIST)}}. The optional argument
    29 {{TEST}} specifies the comparison procedure to search a matching pair in {{ALIST}}
    30 and defaults to {{eqv?}}.
    31 
    32 
    33 ==== atom?
    34 
    35  [procedure] (atom? X)
    36 
    37 Returns {{#t}} if {{X}} is not a pair. This is identical to {{not-pair?}} from [[Unit srfi-1]] but
    38 kept for historical reasons.
    39 
    40 
    41 ==== rassoc
    42 
    43  [procedure] (rassoc KEY LIST [TEST])
    44 
    45 Similar to {{assoc}}, but compares {{KEY}} with the {{cdr}} of each pair in {{LIST}} using
    46 {{TEST}} as the comparison procedures (which defaults to {{eqv?}}.
    47 
    48 
    49 ==== butlast
    50 
    51  [procedure] (butlast LIST)
    52 
    53 Returns a fresh list with all elements but the last of {{LIST}}.
    54 
    55 
    56 ==== chop
    57 
    58  [procedure] (chop LIST N)
    59 
    60 Returns a new list of sublists, where each sublist contains {{N}}
    61 elements of {{LIST}}. If {{LIST}} has a length that is not
    62 a multiple of {{N}}, then the last sublist contains the remaining
    63 elements.
    64 
    65 <enscript highlight=scheme>
    66 (chop '(1 2 3 4 5 6) 2) ==> ((1 2) (3 4) (5 6))
    67 (chop '(a b c d) 3)     ==> ((a b c) (d))
    68 </enscript>
     6This unit contains a collection of useful utility definitions. The unit is
     7used by default, unless the program is compiled with the {{-explicit-use}}
     8option.
    699
    7010
    7111
    72 ==== compress
    73 
    74  [procedure] (compress BLIST LIST)
    75 
    76 Returns a new list with elements taken from {{LIST}} with
    77 corresponding true values in the list {{BLIST}}.
    78 
    79 <enscript highlight=scheme>
    80 (define nums '(99 100 110 401 1234))
    81 (compress (map odd? nums) nums)      ==> (99 401)
    82 </enscript>
     12=== Random numbers
    8313
    8414
    85 ==== flatten
     15==== random-seed
    8616
    87  [procedure] (flatten LIST1 ...)
     17 [procedure] (random-seed [SEED])
    8818
    89 Returns {{LIST1 ...}} concatenated together, with nested lists
    90 removed (flattened).
     19Seeds the random number generator with {{SEED}} (an {{integer}}) or
     20{{(current-seconds)}} if {{SEED}} is not given.
    9121
    9222
    93 ==== intersperse
     23==== randomize
    9424
    95  [procedure] (intersperse LIST X)
     25 [procedure] (randomize [SEED])
    9626
    97 Returns a new list with {{X}} placed between each element.
     27Set random-number seed. If {{SEED}} (an {{exact integer}}) is not supplied, the
     28current time is used. On startup (when Unit {{extras}} is initialized), the
     29random number generator is initialized with the current time.
    9830
    9931
    100 ==== join
     32==== random
    10133
    102  [procedure] (join LISTOFLISTS [LIST])
     34 [procedure] (random N)
    10335
    104 Concatenates the lists in {{LISTOFLISTS}} with {{LIST}} placed
    105 between each sublist. {{LIST}} defaults to the empty list.
     36Returns a random {{integer}} in {{[0 N-1]}}. {{N}} is an {{integer}}.
    10637
    107 <enscript highlight=scheme>
    108 (join '((a b) (c d) (e)) '(x y)) ==> (a b x y c d x y e)
    109 (join '((p q) () (r (s) t)) '(-))  ==> (p q - - r (s) t)
    110 </enscript>
    111 
    112 {{join}} could be implemented as follows:
    113 
    114 <enscript highlight=scheme>
    115 (define (join lstoflsts #!optional (lst '()))
    116   (apply append (intersperse lstoflists lst)) )
    117 </enscript>
    118 
    119 
    120 ==== shuffle
    121 
    122  [procedure] (shuffle LIST)
    123 
    124 Returns {{LIST}} with its elements sorted in a random order.
    125 
    126 
    127 ==== tail?
    128 
    129  [procedure] (tail? X LIST)
    130 
    131 Returns true if {{X}} is one of the tails (cdr's) of {{LIST}}.
     38On '''Windows''' {{N}} and the random value are {{exact integer}}.
    13239
    13340
     
    14047==== sprintf
    14148
    142  [procedure] (fprintf PORT FORMATSTRING ARG ...)
    143  [procedure] (printf FORMATSTRING ARG ...)
    144  [procedure] (sprintf FORMATSTRING ARG ...)
     49 [procedure] (fprintf PORT FORMATSTRING [ARG...])
     50 [procedure] (printf FORMATSTRING [ARG...])
     51 [procedure] (sprintf FORMATSTRING [ARG...])
    14552
    14653Simple formatted output to a given port ({{fprintf}}), the
     
    17986==== format
    18087
    181  [procedure] (format [DESTINATION] FORMATSTRING ARG ...)
     88 [procedure] (format [DESTINATION] FORMATSTRING [ARG...])
    18289
    183 The parameters  {{FORMATSTRING}} and {{ARG ...}} are as for
    184 ({{printf}}/{{sprintf}}/{{fprintf}}).
     90The parameters {{FORMATSTRING}} and {{ARG...}} are as for {{printf}}.
    18591
    186 The optional {{DESTINATION}}, when supplied, performs
    187 a ({{sprintf}}) for a  {{#f}},
    188 a ({{printf}}) for a {{#t}},
    189 and a ({{fprintf}}) for an output-port.
    190 When missing a ({{sprintf}}) is performed.
     92The optional {{DESTINATION}}, when supplied, performs:
    19193
    192 
    193 
    194 === Queues
    195 
    196 
    197 ==== list->queue
    198 
    199  [procedure] (list->queue LIST)
    200 
    201 Returns {{LIST}} converted into a queue, where the first element
    202 of the list is the same as the first element of the queue. The resulting
    203 queue may share memory with the list and the list should not be modified
    204 after this operation.
    205 
    206 
    207 ==== make-queue
    208 
    209  [procedure] (make-queue)
    210 
    211 Returns a newly created queue.
    212 
    213 
    214 ==== queue?
    215 
    216  [procedure] (queue? X)
    217 
    218 Returns {{#t}} if {{X}} is a queue, or {{#f}} otherwise.
    219 
    220 
    221 ==== queue->list
    222 
    223  [procedure] (queue->list QUEUE)
    224 
    225 Returns {{QUEUE}} converted into a list, where the first element
    226 of the list is the same as the first element of the queue. The resulting
    227 list may share memory with the queue object and should not be modified.
    228 
    229 
    230 ==== queue-add!
    231 
    232  [procedure] (queue-add! QUEUE X)
    233 
    234 Adds {{X}} to the rear of {{QUEUE}}.
    235 
    236 
    237 ==== queue-empty?
    238 
    239  [procedure] (queue-empty? QUEUE)
    240 
    241 Returns {{#t}} if {{QUEUE}} is empty, or {{#f}} otherwise.
    242 
    243 
    244 ==== queue-first
    245 
    246  [procedure] (queue-first QUEUE)
    247 
    248 Returns the first element of {{QUEUE}}. If {{QUEUE}} is empty
    249 an error is signaled
    250 
    251 
    252 ==== queue-last
    253 
    254  [procedure] (queue-last QUEUE)
    255 
    256 Returns the last element of {{QUEUE}}. If {{QUEUE}} is empty
    257 an error is signaled
    258 
    259 
    260 ==== queue-remove!
    261 
    262  [procedure] (queue-remove! QUEUE)
    263 
    264 Removes and returns the first element of {{QUEUE}}. If {{QUEUE}}
    265 is empty an error is signaled
    266 
    267 
    268 ==== queue-push-back!
    269 
    270  [procedure] (queue-push-back! QUEUE ITEM)
    271 
    272 Pushes an item into the first position of a queue, i.e. the next
    273 {{queue-remove!}} will return {{ITEM}}.
    274 
    275 
    276 ==== queue-push-back-list!
    277 
    278  [procedure] (queue-push-back-list! QUEUE LIST)
    279 
    280 Pushes the items in item-list back onto the queue,
    281 so that {{(car LIST)}} becomes the next removable item.
    282 
    283 
    284 
    285 === Sorting
    286 
    287 
    288 ==== merge
    289 
    290  [procedure] (merge LIST1 LIST2 LESS?)
    291  [procedure] (merge! LIST1 LIST2 LESS?)
    292 
    293 Joins two lists in sorted order. {{merge!}} is the destructive
    294 version of merge. {{LESS?  }} should be a procedure of two arguments,
    295 that returns true if the first argument is to be ordered before the
    296 second argument.
    297 
    298 
    299 ==== sort
    300 
    301  [procedure] (sort SEQUENCE LESS?)
    302  [procedure] (sort! SEQUENCE LESS?)
    303 
    304 Sort {{SEQUENCE}}, which should be a list or a vector. {{sort!}}
    305 is the destructive version of sort.
    306 
    307 
    308 ==== sorted?
    309 
    310  [procedure] (sorted? SEQUENCE LESS?)
    311 
    312 Returns true if the list or vector {{SEQUENCE}} is already sorted.
    313 
    314 
    315 
    316 === Random numbers
    317 
    318 
    319 ==== random-seed
    320 
    321  [procedure] (random-seed [SEED])
    322 
    323 Seeds the random number generator with {{SEED}} (an exact integer) or
    324 {{(current-seconds)}} if {{SEED}} is not given.
    325 
    326 
    327 ==== random
    328 
    329  [procedure] (random N)
    330 
    331 Returns an exact random integer from 0 to {{N}}-1.
    332 
    333 
    334 ==== randomize
    335 
    336  [procedure] (randomize [X])
    337 
    338 Set random-number seed. If {{X}} is not supplied, the current time is used.
    339 On startup (when the {{extras}} unit is initialized), the random number generator
    340 is initialized with the current time.
     94; {{#f}} : {{sprintf}}
     95; {{#t}} : {{printf}}
     96; {{output-port}} : {{fprintf}}
     97; : {{sprintf}}
    34198
    34299
     
    428185false. Returns a string with the accumulated characters.
    429186
    430 
    431 
    432 === Strings
    433 
    434 
    435 ==== conc
    436 
    437  [procedure] (conc X ...)
    438 
    439 Returns a string with the string-represenation of all arguments concatenated
    440 together. {{conc}} could be implemented as
    441 
    442 <enscript highlight=scheme>
    443 (define (conc . args)
    444   (apply string-append (map ->string args)) )
    445 </enscript>
    446 
    447 
    448 
    449 ==== ->string
    450 
    451  [procedure] (->string X)
    452 
    453 Returns a string-representation of {{X}}.
    454 
    455 
    456 ==== string-chop
    457 
    458  [procedure] (string-chop STRING LENGTH)
    459 
    460 Returns a list of substrings taken by ''chopping'' {{STRING}} every {{LENGTH}}
    461 characters:
    462 
    463 <enscript highlight=scheme>
    464 (string-chop "one two three" 4)  ==>  ("one " "two " "thre" "e")
    465 </enscript>
    466 
    467 
    468 
    469 ==== string-chomp
    470 
    471  [procedure] (string-chomp STRING [SUFFIX])
    472 
    473 If {{STRING}} ends with {{SUFFIX}}, then this procedure returns a copy of its first argument with the suffix
    474 removed, otherwise returns {{STRING}} unchanged. {{SUFFIX}} defaults to {{"\n"}}.
    475 
    476 
    477 ==== string-compare3
    478 
    479  [procedure] (string-compare3 STRING1 STRING2)
    480  [procedure] (string-compare3-ci STRING1 STRING2)
    481 
    482 Perform a three-way comparison between the {{STRING1}} and {{STRING2}},
    483 returning either {{-1}} if {{STRING1}} is lexicographically less
    484 than {{STRING2}}, {{0}} if it is equal, or {{1}} if it s greater.
    485 {{string-compare3-ci}} performs a case-insensitive comparison.
    486 
    487 
    488 ==== string-intersperse
    489 
    490  [procedure] (string-intersperse LIST [STRING])
    491 
    492 Returns a string that contains all strings in {{LIST}} concatenated
    493 together.  {{STRING}} is placed between each concatenated string and
    494 defaults to {{" "}}.
    495 
    496 <enscript highlight=scheme>
    497 (string-intersperse '("one" "two") "three")
    498 </enscript>
    499 
    500 is equivalent to
    501 
    502 <enscript highlight=scheme>
    503 (apply string-append (intersperse '("one" "two") "three"))
    504 </enscript>
    505 
    506 
    507 ==== string-split
    508 
    509  [procedure] (string-split STRING [DELIMITER-STRING [KEEPEMPTY]])
    510 
    511 Split string into substrings separated by the given delimiters. If
    512 no delimiters are specified, a string comprising the tab, newline and space characters
    513 is assumed. If the
    514 parameter {{KEEPEMPTY}} is given and not {{#f}}, then empty
    515 substrings are retained:
    516 
    517 <enscript highlight=scheme>
    518 (string-split "one  two  three") ==> ("one" "two" "three")
    519 (string-split "foo:bar::baz:" ":" #t) ==> ("foo" "bar" "" "baz" "")
    520 </enscript>
    521 
    522 
    523 ==== string-translate
    524 
    525  [procedure] (string-translate STRING FROM [TO])
    526 
    527 Returns a fresh copy of {{STRING}} with characters matching
    528 {{FROM}} translated to {{TO}}.  If {{TO}} is omitted, then
    529 matching characters are removed. {{FROM}} and {{TO}} may be
    530 a character, a string or a list. If both {{FROM}} and {{TO}}
    531 are strings, then the character at the same position in {{TO}}
    532 as the matching character in {{FROM}} is substituted.
    533 
    534 
    535 ==== string-translate*
    536 
    537  [procedure] (string-translate* STRING SMAP)
    538 
    539 Substitutes elements of {{STRING}} according to {{SMAP}}.
    540 {{SMAP}} should be an association-list where each element of the list
    541 is a pair of the form {{(MATCH \. REPLACEMENT)}}. Every occurrence of
    542 the string {{MATCH}} in {{STRING}} will be replaced by the string
    543 {{REPLACEMENT}}:
    544 
    545 <enscript highlight=scheme>
    546 (string-translate*
    547   "<h1>this is a \"string\"</h1>"
    548   '(("<" . "&lt;") (">" . "&gt;") ("\"" . "&quot;")) )
    549 =>  "&lt;h1&gt;this is a &quot;string&quot;&lt;/h1&gt;"
    550 </enscript>
    551 
    552 
    553 ==== substring=?
    554 
    555  [procedure] (substring=? STRING1 STRING2 [START1 [START2 [LENGTH]]])
    556  [procedure] (substring-ci=? STRING1 STRING2 [START1 [START2 [LENGTH]]])
    557 
    558 Returns {{#t}} if the strings {{STRING1}} and {{STRING2}} are equal, or
    559 {{#f}} otherwise.
    560 The comparison starts at the positions {{START1}} and {{START2}} (which default
    561 to 0), comparing {{LENGTH}} characters (which defaults to the minimum of the remaining
    562 length of both strings).
    563 
    564 
    565 ==== substring-index
    566 
    567  [procedure] (substring-index WHICH WHERE [START])
    568  [procedure] (substring-index-ci WHICH WHERE [START])
    569 
    570 Searches for first index in string {{WHERE}} where string
    571 {{WHICH}} occurs.  If the optional argument {{START}} is given,
    572 then the search starts at that index.  {{substring-index-ci}}
    573 is a case-insensitive version of {{substring-index}}.
    574 
    575 
    576 
    577 === Combinators
    578 
    579 
    580 ==== any?
    581 
    582  [procedure] (any? X)
    583 
    584 Ignores its argument and always returns {{#t}}. This is actually useful sometimes.
    585 
    586 
    587 ==== none?
    588 
    589  [procedure] (none? X)
    590 
    591 Ignores its argument and always returns {{#f}}. This is actually useful sometimes.
    592 
    593 
    594 ==== always?
    595 
    596  [procedure] (always? ...)
    597 
    598 Ignores its arguments and always returns {{#t}}. This is actually useful sometimes.
    599 
    600 
    601 ==== never?
    602 
    603  [procedure] (never? ...)
    604 
    605 Ignores its arguments and always returns {{#f}}. This is actually useful sometimes.
    606 
    607 
    608 ==== constantly
    609 
    610  [procedure] (constantly X ...)
    611 
    612 Returns a procedure that always returns the values {{X ...}} regardless of the number and value of its arguments.
    613 
    614 <enscript highlight=scheme>
    615 (constantly X) <=> (lambda args X)
    616 </enscript>
    617 
    618 
    619 ==== complement
    620 
    621  [procedure] (complement PROC)
    622 
    623 Returns a procedure that returns the boolean inverse of {{PROC}}.
    624 
    625 <enscript highlight=scheme>
    626 (complement PROC) <=> (lambda (x) (not (PROC x)))
    627 </enscript>
    628 
    629 
    630 ==== compose
    631 
    632  [procedure] (compose PROC1 PROC2 ...)
    633 
    634 Returns a procedure that represents the composition of the
    635 argument-procedures {{PROC1 PROC2 ...}}.
    636 
    637 <enscript highlight=scheme>
    638 (compose F G) <=> (lambda args
    639                       (call-with-values
    640                          (lambda () (apply G args))
    641                          F))
    642 </enscript>
    643 
    644 {{(compose)}} is equivalent to {{values}}.
    645 
    646 
    647 ==== conjoin
    648 
    649  [procedure] (conjoin PRED ...)
    650 
    651 Returns a procedure that returns {{#t}} if its argument satisfies the
    652 predicates {{PRED ...}}.
    653 <enscript highlight=scheme>
    654 ((conjoin odd? positive?) 33)   ==>  #t
    655 ((conjoin odd? positive?) -33)  ==>  #f
    656 </enscript>
    657 
    658 
    659 ==== disjoin
    660 
    661  [procedure] (disjoin PRED ...)
    662 
    663 Returns a procedure that returns {{#t}} if its argument satisfies any
    664 predicate {{PRED ...}}.
    665 <enscript highlight=scheme>
    666 ((disjoin odd? positive?) 32)    ==>  #t
    667 ((disjoin odd? positive?) -32)   ==>  #f
    668 </enscript>
    669 
    670 
    671 ==== each
    672 
    673  [procedure] (each PROC ...)
    674 
    675 Returns a procedure that applies {{PROC ...}} to its arguments, and returns the result(s)
    676 of the last procedure application. For example
    677 
    678 <enscript highlight=scheme>
    679 (each pp eval)
    680 </enscript>
    681 
    682 is equivalent to
    683 
    684 <enscript highlight=scheme>
    685 (lambda args
    686   (apply pp args)
    687   (apply eval args) )
    688 </enscript>
    689 
    690 {{(each PROC)}} is equivalent to {{PROC}} and {{(each)}} is equivalent to
    691 {{noop}}.
    692 
    693 
    694 ==== flip
    695 
    696  [procedure] (flip PROC)
    697 
    698 Returns a two-argument procedure that calls {{PROC}} with its
    699 arguments swapped:
    700 <enscript highlight=scheme>
    701 (flip PROC) <=> (lambda (x y) (PROC y x))
    702 </enscript>
    703 
    704 
    705 ==== identity
    706 
    707  [procedure] (identity X)
    708 
    709 Returns its sole argument {{X}}.
    710 
    711 
    712 ==== project
    713 
    714  [procedure] (project N)
    715 
    716 Returns a procedure that returns its {{N}}th argument (starting from 0).
    717 
    718 
    719 ==== list-of
    720 
    721  [procedure] (list-of PRED)
    722 
    723 Returns a procedure of one argument that returns {{#t}} when
    724 applied to a list of elements that all satisfy the predicate procedure
    725 {{PRED}}, or {{#f}} otherwise.
    726 
    727 <enscript highlight=scheme>
    728 ((list-of even?) '(1 2 3))   ==> #f
    729 ((list-of number?) '(1 2 3)) ==> #t
    730 </enscript>
    731 
    732 
    733 ==== noop
    734 
    735  [procedure] (noop X ...)
    736 
    737 Ignores it's arguments, does nothing and returns an unspecified value.
    738 
    739 
    740 ==== o
    741 
    742  [procedure] (o PROC ...)
    743 
    744 A single value version of {{compose}} (slightly faster). {{(o)}} is equivalent
    745 to {{identity}}.
    746 
    747 
    748 ==== left-section
    749 
    750  [procedure] (left-section PROC ARG0 ...)
    751 
    752 Returns an n-ary procedure that partially applies its' arguments {{ARG0 ...}}
    753 from the left (normal order). Sort of a n-ary curry.
    754 
    755 
    756 ==== right-section
    757 
    758  [procedure] (right-section PROC ARG0 ...)
    759 
    760 Returns an n-ary procedure that partially applies its' arguments {{ARG0 ...}}
    761 from the right (reverse order). Sort of a n-ary curry.
    762 
    763 
    764 === Binary searching
    765 
    766 
    767 ==== binary-search
    768 
    769  [procedure] (binary-search SEQUENCE PROC)
    770 
    771 Performs a binary search in {{SEQUENCE}}, which should be a sorted
    772 list or vector.  {{PROC}} is called to compare items in the sequence,
    773 should accept a single argument and return an exact integer: zero if the
    774 searched value is equal to the current item, negative if the searched
    775 value is ''less'' than the current item, and positive otherwise.
    776 Returns the index of the found value or {{#f}} otherwise.
    777 
    778187---
    779188Previous: [[Unit files]]
  • chicken/trunk/runtime.c

    r13756 r13831  
    716716  callback_continuation_level = 0;
    717717  timer_start_gc_ms = 0;
     718#if defined(C_NONUNIX)
    718719  C_randomize(time(NULL));
     720#elif defined(C_GNU_ENV)
     721  srandomdev();
     722#else
     723  srandom(time(NULL));
     724#endif
    719725  return 1;
    720726}
Note: See TracChangeset for help on using the changeset viewer.