【问题标题】:stream exercises in scheme计划中的流式练习
【发布时间】:2013-04-01 15:47:25
【问题描述】:

有一个答案如下。 编写一个名为 avg3 的 Scheme 过程,它接受一个数字流,并生成一个数字流,其中包含输入流的三元组元素的平均值。例如,表达式 (avg2 s1to9) 产生流 2、5、8(s1to9 是从 1 到 9 的数字流)。

【问题讨论】:

  • 到目前为止你尝试过什么?你不能在没有先展示一些努力的情况下在这里发布作业,你写的代码

标签: stream scheme


【解决方案1】:

显然是一个家庭作业,如果你尝试自己解决问题会更好。我给你一些提示,填空:

(define (avg2 stream)
  (if <???>            ; if the stream is null
      <???>            ; then return the null stream
      (stream-cons     ; else cons 
       (/ (+ <???>     ; add first element in stream
             <???>     ; with second
             <???>)    ; with third
          3)           ; and divide the addition by 3
       (avg2 <???>)))) ; advance the recursion, to the next 3 elements

【讨论】:

    猜你喜欢
    • 2013-04-15
    • 1970-01-01
    • 2015-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-07
    相关资源
    最近更新 更多