[racket] racket newbie question on quoting and the built in procedure-arity function
Hello,
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.
(define ($+ augend addend) ;operation is addition
(+ augend addend)) ; the result is the sum
(define ($- minuend subtrahend) ;operation is subtraction
(- minuend subtrahend)) ;result is difference
(define ($* multiplicand multiplier) ;operation is multiplication
(* multiplicand multiplier)) ;result is product
(define ($/ dividend divisor) ;operation is division
(/ dividend divisor)) ;result is quotient
(define (infinity? x) (or (eq? x +Inf.0) (eq? x -Inf.0)))
(define ($sin x) (if (infinity? x) (* (sgn x) +Inf.0) (sin x)))
(define ($cos x) (if (infinity? x) (* (sgn x) +Inf.0) (cos x)))
(define safe-function-set
'($+
$-
$*
$/
;$sin
;$cos))
(define (select-random-safe-function)
(list-ref safe-function-set (random (length safe-function-set))))
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:
>(procedure-arity (select-random-safe-function))
error: procedure-arity: contract violation
expected: procedure?
given: '$+
*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?*
Thanks,
--
Rian Shams
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140103/216d3945/attachment.html>