<div dir="ltr">Hello,<div><br></div><div>I am working with functions that I have defined to only take 1 or 2 operands (called safe-functions) for the implementation of a genetic program.</div><div><br></div><div><div>(define ($+ augend addend) ;operation is addition</div>
<div> (+ augend addend)) ; the result is the sum</div><div>(define ($- minuend subtrahend) ;operation is subtraction</div><div> (- minuend subtrahend)) ;result is difference</div><div>(define ($* multiplicand multiplier) ;operation is multiplication</div>
<div> (* multiplicand multiplier)) ;result is product</div><div>(define ($/ dividend divisor) ;operation is division</div><div> (/ dividend divisor)) ;result is quotient</div><div><br></div><div><div>(define (infinity? x) (or (eq? x +Inf.0) (eq? x -Inf.0)))</div>
<div>(define ($sin x) (if (infinity? x) (* (sgn x) +Inf.0) (sin x)))</div><div>(define ($cos x) (if (infinity? x) (* (sgn x) +Inf.0) (cos x)))</div></div><div><br></div><div><div>(define safe-function-set</div><div> '($+ </div>
<div> $- </div><div> $* </div><div> $/</div><div> ;$sin</div><div> ;$cos))</div></div><div><br></div><div><div>(define (select-random-safe-function)</div><div> (list-ref safe-function-set (random (length safe-function-set))))</div>
</div><div><br></div><div>I would like to use procedure-arity (or a similar function) to determine the arity of a randomly selected safe function but I get this error:</div><div><br></div><div>>(procedure-arity (select-random-safe-function))</div>
<div><div>error: procedure-arity: contract violation</div><div> expected: procedure?</div><div> given: '$+</div></div><div><br></div><div><b>I think the problem is that the safe-functions are passed to procedure-arity quoted. Is there a way I can unquote the functions, or adjust procedure-arity to make (procedure-arity (select-random-safe-function)) work?</b></div>
<div><br></div><div>Thanks,</div>-- <br>Rian Shams
</div></div>