Changeset 37002 in project


Ignore:
Timestamp:
12/16/18 18:01:05 (6 months ago)
Author:
kon
Message:

xC shuffle

Location:
release/4/amb/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/4/amb/trunk/amb.scm

    r35572 r37002  
    158158;;;
    159159
    160 (: shuffle ((list-of *) procedure -> (list-of *)))
     160(cond-expand
     161  (chicken-5
     162    (import
     163      (only (chicken fixnum) fx<)
     164      (only (chicken random) pseudo-random-integer)
     165      (only (chicken sort) sort!)
     166      (only (srfi 1) map!))
     167    (define platform-random pseudo-random-integer) )
     168  (chicken-4
     169    (use
     170      chicken
     171      (only extras random)
     172      (only data-structures sort!)
     173      (only (srfi 1) map!))
     174    (define platform-random random) ) )
     175
     176(: fx<car ((pair fixnum *) (pair fixnum *) --> boolean))
    161177;
    162 (define (shuffle ls random)
     178(define (fx<car a b) (fx< (car a) (car b)))
     179
     180(: shuffle ((list-of *) #!optional (procedure (fixnum) fixnum) -> (list-of *)))
     181;
     182(define (shuffle ls #!optional (rand platform-random))
    163183  (let* (
    164184    (len (length ls))
    165     (tagged-ls (map (lambda (x) (cons (random len) x)) ls)) )
    166     (map! cdr (sort! tagged-ls (lambda (a b) (fx< (car a) (car b)))) ) ) )
     185    (tagged-ls (map (lambda (x) (cons (rand len) x)) ls)) )
     186    (map! cdr (sort! tagged-ls fx<car) ) ) )
    167187
    168188) ;module amb
  • release/4/amb/trunk/amb.setup

    r35572 r37002  
    55(verify-extension-name "amb")
    66
    7 (setup-shared+static-extension-module 'amb (extension-version "2.3.1")
     7(setup-shared+static-extension-module 'amb (extension-version "2.3.2")
    88  ;#:inline? #t
    99  #:types? #t
     
    1111  #:install-options '((examples "amb-dwelling.scm" "amb-kalotan.scm" "amb-money.scm")))
    1212
    13 (setup-shared+static-extension-module 'amb-extras (extension-version "2.3.1")
     13(setup-shared+static-extension-module 'amb-extras (extension-version "2.3.2")
    1414  ;#:inline? #t
    1515  #:types? #t
Note: See TracChangeset for help on using the changeset viewer.