Racket: argument is non-null error

会有一股神秘感。 提交于 2019-12-25 14:32:33

问题


At first I defined HALF, QUARTER and EIGHT to their values with define and with it the quoted symbols would get introduced as arguments in the note function thus making an error. Then I used let and now I get the error

stream-rec->C: argument is not non-null `stream-rec' pointer
  argument: #f

My theory is that stream still processes HALF as 'HALF instead of 30000. I tried putting it into an eval list in note , in random-length in let bindings and in random-note and neither worked. What can I do?

#lang racket

(require rsound
     rsound/piano-tones)

;Where notes are made.
(define stream (make-pstream))
(define count 10000)
(define (note y x)
  (pstream-queue stream (clip (piano-tone y) 0 20000) count)
  (set! count (+ count x)))

;Defining length of notes.
(let ([HALF 30000]) 30000)
(let ([QUARTER 15000]) 15000)
(let ([EIGHT 7500]) 7500)

(define (random-element list)
  (list-ref list (random (length list))))

;Getting a random note length. 
(define (random-length)
  (random-element '(HALF QUARTER QUARTER EIGHT)))

;Getting a random note and note length.
(define (random-note)
  (note (random-element '(40 42 43 45 47 48 50 52 54 55 57 59 60 62 64))   (random-length)))


;Main loop for creating the notes.
(for ([i (in-range 32)])
  (random-note))


;For the program not to close itself before runing loop, only after pstream-  queue is emptied.
(define ok-to-exit? #f)
(pstream-queue-callback stream (lambda () (set! ok-to-exit? #t)) count)

(let loop ()
  (sleep 0.1)
  (unless ok-to-exit?
    (loop)))

来源:https://stackoverflow.com/questions/34968953/racket-argument-is-non-null-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!