Changeset 38667 in project


Ignore:
Timestamp:
04/29/20 22:36:43 (6 months ago)
Author:
Kon Lovett
Message:

add (not unreasonable) optional arguments for `plot', add tests

Location:
release/5/slib-charplot/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • release/5/slib-charplot/trunk/slib-charplot.egg

    r38456 r38667  
    33
    44((synopsis "The SLIB character plotting library")
    5  (version "1.0.6")
     5 (version "1.1.0")
    66 (author "Aubrey Jaffer")
    77 (maintainer "[[kon lovett]]")
     
    1515  (extension slib-charplot
    1616    (types-file)
     17    ;no "-strict-types" due to `charplot.scm:309' npts set!
    1718    (csc-options
    18       "-O3" "-d1" "-local"
     19      "-O3" "-d1"
    1920      "-no-procedure-checks-for-toplevel-bindings") ) ) )
  • release/5/slib-charplot/trunk/slib-charplot.scm

    r38404 r38667  
    2121(import (only (chicken base)
    2222  include
    23   let-values
     23  let-values let-optionals
    2424  error identity
    2525  warning make-parameter))
     
    5555(: curves-chars (#!optional (or boolean string) -> string))
    5656
    57 (: plot (or (plotdata string string #!optional boolean -> void)
     57;only works due to slib plot . args (?)
     58(: plot (or (plotdata #!optional string string boolean -> void)
    5859            ((number -> float) number number #!optional fixnum -> void)))
    5960
     
    6566
    6667(include "charplot")
     68
     69;;
     70
     71;optional axis labels
     72(set! plot
     73  (let ((slib:plot plot))
     74    (lambda (data . args)
     75      (if (procedure? data)
     76        (let-optionals args ((lo 0) (hi 1) (npts 64))
     77          (slib:plot data lo hi npts))
     78        (let-optionals args ((xaxis "") (yaxis "") (histogram? #f))
     79          (slib:plot data xaxis yaxis histogram?))))))
    6780
    6881;; Parameters (replacements for SLIB graph part globals)
  • release/5/slib-charplot/trunk/tests/slib-charplot-test.scm

    r38526 r38667  
    6464    (plot (make-points 40) "x" "Sin(x)" #t) ) )
    6565
     66;default labels
     67(print)
     68(print "*** Plot w/ default labels")
     69(print)
     70
     71(time
     72  (parameterize (
     73    (plot-left-margin #f)
     74    (plot-dimensions '(20 55)) )
     75    (plot (make-points 40)) ) )
     76
    6677;;
    6778
     
    8091    (plot sin 0 (* 2 pi)) ) )
    8192
     93(print)
     94(print "*** Plot w/ default range")
     95(print)
     96
     97(time
     98  (parameterize (
     99    (plot-left-margin #f)
     100    (plot-dimensions '(20 55)) )
     101    (plot sin) ) )
     102
    82103;;
    83104
    84105;srfi-27
    85106(define-type random-f64-function  (-> float))
    86 
    87107;fortran "real"
    88108(define-type random-real-function random-f64-function)
     
    90110;; Knuth's "The Art of Computer Programming", Vol. II, 2nd ed.,
    91111;; Algorithm P of Section 3.4.1.C.
    92 (: *make-random-normals (float float random-real-function --> random-real-function))
     112;
     113;silly experiment
     114(: *make-random-normals (number number random-real-function --> random-real-function))
    93115;
    94116(define (*make-random-normals mu sigma randoms)
     
    100122          (+ mu (* sigma result)))
    101123        (let loop ()
    102           (let* (
    103             (v1 (- (* 2.0 (randoms)) 1.0) )
    104             (v2 (- (* 2.0 (randoms)) 1.0) )
    105             (s (+ (* v1 v1) (* v2 v2)) ) )
    106             ;
    107             (if (<= 1.0 s)
    108               (loop)
    109               (let ((scale (sqrt (/ (* -2.0 (log s)) s))))
    110                 (set! next (* scale v2))
    111                 (+ mu (* sigma scale v1))))))))) )
     124          (let (
     125            (v1 (- (* 2 (inexact->exact (randoms))) 1))
     126            (v2 (- (* 2 (inexact->exact (randoms))) 1)) )
     127            (let (
     128              (s (+ (* v1 v1) (* v2 v2))) )
     129              ;
     130              (if (<= 1 s)
     131                (loop)
     132                (let (
     133                  (scale (inexact->exact (sqrt (/ (* -2 (inexact->exact (log s))) s)))) )
     134                  (set! next (* scale v2))
     135                  (+ mu (* sigma scale v1)) ) ) ) ) ) ) ) ) )
    112136
    113137;SLIB wrapper
     
    117141      (let ()
    118142        (import (only (chicken random) pseudo-random-real))
    119         (*make-random-normals 0.0 1.0 pseudo-random-real))) )
     143        (*make-random-normals 0 1 pseudo-random-real))) )
    120144    (lambda ()
    121145      (random-normal) ) ) )
     
    127151
    128152(print)
    129 (print "*** Histograph (Random) w/ dimensions 20x55 & left-margin <minimum> (#f)")
     153(print "*** Histograph (Normals) w/ dimensions 20x55 & left-margin <minimum> (#f)")
    130154(print)
    131155
Note: See TracChangeset for help on using the changeset viewer.