my-test-8   xtlang


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/examples/core/extempore_lang.xtm

Implementation

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; some array code with *casting*
;; this function returns void
(bind-func my-test-8
  (lambda ()
    (let ((v1:|5,float|* (alloc))
          (v2:|5,float|* (alloc))
          (i 0)
          (k 0))
      (dotimes (i 5)
        ;; random returns double so "truncate" to float
        ;; which is what v expects
        (array-set! v1 i (dtof (random))))
      ;; we can use the afill! function to fill an array
      (afill! v2 1.1 2.2 3.3 4.4 5.5)
      (dotimes (k 5)
        ;; unfortunately printf doesn't like floats
        ;; so back to double for us :(
        (printf "val: %lld::%f::%f\n" k
                (ftod (array-ref v1 k))
                (ftod (aref v2 k)))))))


Back to Index