Changeset 35484 in project


Ignore:
Timestamp:
04/29/18 21:11:51 (4 weeks ago)
Author:
kon
Message:

types for sources

Location:
release/4/srfi-27/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • release/4/srfi-27/trunk/composite-random-source.scm

    r34780 r35484  
    3333  composite-random-source)
    3434
    35 (import scheme)
     35(import scheme chicken)
    3636
    37 (import chicken)
    38 
    39 (import
     37(use
    4038  (only data-structures conc reverse-string-append ->string intersperse)
    41   (only type-errors error-argument-type))
    42 (require-library data-structures type-errors)
    43 
    44 (use srfi-1)
    45 (use numbers)
    46 (use random-source srfi-27-vector-support srfi-27)
     39  (only type-errors error-argument-type)
     40  srfi-1
     41  numbers
     42  random-source
     43  srfi-27-vector-support
     44  srfi-27)
    4745
    4846;;
     
    8179      (srcs0
    8280        (if (null? rest)
    83           (error 'composite-random-source "no random-sources to combine")
     81          (error 'composite-random-source "empty random-sources")
    8482          (map (cut check-random-source 'composite-random-source <>) rest) ) ) )
    8583    ;collect features
     
    138136                ;randomize!
    139137                (lambda (es)
    140                   (for-each
    141                     (lambda (rs)
    142                       ((@random-source-randomize! rs) es) )
    143                     srcs) )
     138                  (for-each (lambda (rs) ((@random-source-randomize! rs) es)) srcs) )
    144139                ;pseudo-randomize!
    145140                (lambda (i j)
    146                   (for-each
    147                     (lambda (rs)
    148                       ((@random-source-pseudo-randomize! rs) i j) )
    149                     srcs) )
     141                  (for-each (lambda (rs) ((@random-source-pseudo-randomize! rs) i j)) srcs) )
    150142                ;make-integers
    151143                (lambda ()
     
    155147                (lambda (unit)
    156148                  (let (
    157                       (makrels
    158                         (map
    159                           (lambda (rs)
    160                             ((@random-source-make-reals rs) unit) )
    161                           srcs)))
     149                    (makrels (map (lambda (rs) ((@random-source-make-reals rs) unit)) srcs)) )
    162150                    (lambda ()
    163151                      (comb-real (map (cut <>) makrels) unit) ) ) ) ) ) ) ) )
  • release/4/srfi-27/trunk/entropy-source.scm

    r35456 r35484  
    3939;;
    4040
     41(: *make-entropy-source (procedure entropy-source-name string procedure procedure procedure procedure --> entropy-source))
     42(: entropy-source? (* -> boolean : entropy-source))
     43(: @entropy-source-constructor (entropy-source --> procedure))
     44(: *entropy-source-name (entropy-source --> entropy-source-name))
     45(: *entropy-source-documentation (entropy-source --> string))
     46(: @entropy-source-u8 (entropy-source --> procedure))
     47(: @entropy-source-f64 (entropy-source --> procedure))
     48(: @entropy-source-u8vector (entropy-source --> procedure))
     49(: @entropy-source-f64vector (entropy-source --> procedure))
     50;
    4151(define-record-type entropy-source
    4252  (*make-entropy-source ctor name docu u8 f64 u8vec f64vec)
     
    5464;;
    5565
     66(: entropy-source-integer (entropy-source --> number))
     67;
    5668(define (entropy-source-integer es)
    5769  ;ugly but ...
    58   (let ((genf64 (@entropy-source-f64 es)))
     70  (let (
     71    (genf64 (@entropy-source-f64 es)) )
    5972    (let loop ((x (genf64)))
    6073      (if (integer? x)
     
    6275        (loop (genf64)) ) ) ) )
    6376
     77(: entropy-source-f64-integer (entropy-source --> number))
     78;
    6479(define entropy-source-f64-integer entropy-source-integer)
    6580
     
    6883(define +reg+ (make-source-registration 'entropy-source '()))
    6984
     85(: registered-entropy-sources (--> list))
     86;
    7087(define (registered-entropy-sources)
    7188  ((@source-registration-key +reg+)) )
    7289
     90(: registered-entropy-source (entropy-source-name --> (or boolean random-source)))
     91;
    7392(define (registered-entropy-source name)
    7493  ((@source-registration-ref +reg+) name) )
    7594
     95(: unregister-entropy-source (entropy-source-name -> void))
     96;
    7697(define (unregister-entropy-source name)
    7798  ((@source-registration-deref! +reg+) name) )
    7899
     100(: register-entropy-source! (entropy-source-name procedure -> void))
     101;
    79102(define (register-entropy-source! name ctor)
    80103  ((@source-registration-register! +reg+) name ctor) )
  • release/4/srfi-27/trunk/random-source.scm

    r35456 r35484  
    4242
    4343#; ;NO YOU 'EFFING MORON
    44 (define:-record-type random-source
     44(define:-record-type random-source ...)
     45
     46(: *make-random-source (procedure random-source-name string number number random-source-entropy-source procedure procedure procedure procedure procedure procedure --> random-source))
     47(: random-source? (* -> boolean : random-source))
     48(: @random-source-constructor (random-source --> procedure))
     49(: *random-source-name (random-source --> random-source-name))
     50(: *random-source-documentation (random-source --> string))
     51(: *random-source-log2-period (random-source --> number))
     52(: *random-source-maximum-range (random-source --> number))
     53(: *random-source-entropy-source (random-source --> random-source-entropy-source))
     54(: *random-source-entropy-source-set! (random-source random-source-entropy-source -> void))
     55(: @random-source-state-ref (random-source --> procedure))
     56(: @random-source-state-set! (random-source -> procedure))
     57(: @random-source-randomize! (random-source --> procedure))
     58(: @random-source-pseudo-randomize! (random-source --> procedure))
     59(: @random-source-make-integers (random-source --> procedure))
     60(: @random-source-make-reals (random-source --> procedure))
     61;
     62(define-record-type random-source
    4563  (*make-random-source
    4664    ctor
    4765    name docu
    48     log2-period maxrng
     66    log2. maxrng
    4967    es
    5068    state-ref state-set!
     
    5573  (name               *random-source-name)
    5674  (docu               *random-source-documentation)
    57   (log2-period        *random-source-log2-period)
    58   (maxrng             *random-source-maximum-range)
    59   (es                 *random-source-entropy-source *random-source-entropy-source-set!)
    60   (state-ref          @random-source-state-ref)
    61   (state-set!         @random-source-state-set!)
    62   (randomize!         @random-source-randomize!)
    63   (pseudo-randomize!  @random-source-pseudo-randomize!)
    64   (make-integers      @random-source-make-integers)
    65   (make-reals         @random-source-make-reals) )
    66 
    67 (define-record-type random-source
    68   (*make-random-source
    69     ctor
    70     name docu
    71     log2-period maxrng
    72     es
    73     state-ref state-set!
    74     randomize! pseudo-randomize!
    75     make-integers make-reals)
    76   random-source?
    77   (ctor               @random-source-constructor)
    78   (name               *random-source-name)
    79   (docu               *random-source-documentation)
    80   (log2-period        *random-source-log2-period)
     75  (log2.              *random-source-log2-period)
    8176  (maxrng             *random-source-maximum-range)
    8277  (es                 *random-source-entropy-source *random-source-entropy-source-set!)
     
    9489(define +reg+ (make-source-registration 'random-source '()))
    9590
     91(: registered-random-sources (--> list))
     92;
    9693(define (registered-random-sources)
    9794  ((@source-registration-key +reg+)) )
    9895
     96(: registered-random-source (random-source-name --> (or boolean random-source)))
     97;
    9998(define (registered-random-source name)
    10099  ((@source-registration-ref +reg+) name) )
    101100
     101(: unregister-random-source (random-source-name -> void))
     102;
    102103(define (unregister-random-source name)
    103104  ((@source-registration-deref! +reg+) name) )
    104105
     106(: register-random-source! (random-source-name procedure -> void))
     107;
    105108(define (register-random-source! name ctor)
    106109  ((@source-registration-register! +reg+) name ctor) )
  • release/4/srfi-27/trunk/srfi-27-common-types.scm

    r35477 r35484  
    1313(define-type random-source-name symbol)
    1414
     15;FIXME random-source-state is really type *
    1516(define-type random-source-state list)
     17
     18(define-type boolean-function (--> boolean))
     19
     20(define-type number-function (--> number))
     21
     22;FIXME cannot restrict number domain w/ type system
    1623
    1724(define-type random-integer-function (number --> number))
    1825
     26;fortran "real"
    1927(define-type random-real-function (--> float))
     28
     29(define-type random-u8-function  (--> fixnum))
     30
     31(define-type random-f64-function  (--> float))
    2032
    2133(define-type random-u8vector-function (fixnum --> u8vector))
     
    2335(define-type random-f64vector-function (fixnum --> f64vector))
    2436
    25 (define-type random-u8-function  (--> fixnum))
    26 
    27 (define-type random-f64-function  (--> float))
    28 
    29 (define-type boolean-function (--> boolean))
    30 
    31 (define-type number-function (--> number))
     37(define-type random-source-entropy-source (or boolean entropy-source))
  • release/4/srfi-27/trunk/srfi-27.scm

    r35473 r35484  
    271271    (check-random-source 'random-source-maximum-range rs)) )
    272272
    273 (: random-source-entropy-source (random-source --> (or boolean entropy-source)))
     273(: random-source-entropy-source (random-source --> random-source-entropy-source))
    274274;
    275275(define (random-source-entropy-source rs)
Note: See TracChangeset for help on using the changeset viewer.