0

In my OO World, I have an instance of "weapon" class called "max-damage". I asked to create a random number for a variable called "damage".

It says: The amount of "damage" suffered should be a random integer no more than the "max-damage", and at least 1.

I need some help to create that random integer, thanks!

PS: I can't ask more questions, in order to ask this question, I have changed the previous one, sorry..

4

1 回答 1

2

您的语法filter错误,有必要将过程作为第一个参数传递。具体来说,过程是一个谓词(意思是:它评估为布尔值),输出列表将只保留原始列表中#t传递给过程时评估为的元素。这就是我的意思:

(define (remove-divisible lst value)
  (filter (lambda (x) (not (zero? (remainder x value))))
          lst))

如果使用 alambda让您感到困扰,总是可以定义一个辅助过程,如下所示:

(define (remove-divisible lst value)
  (define (not-divisible? x)
    (not (zero? (remainder x value))))
  (filter not-divisible? lst))
于 2013-11-11T23:35:39.450 回答