<div dir="ltr">If I do this I get the results I need for <span style="font-family:arial,sans-serif;font-size:13px">(procedure-arity (select-random-safe-function)), but when I call </span><div><span style="font-family:arial,sans-serif;font-size:13px">(safe-function-set) or (select-random-safe-function) or any other function that returns a safe function I get for example:</span><span style="font-family:arial,sans-serif;font-size:13px"><br>
</span></div><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">>(safe-function-set)</span></div><div>'(#<procedure:$+> #<procedure:$-> #<procedure:$*> #<procedure:$/>)<span style="font-family:arial,sans-serif;font-size:13px"><br>
</span></div><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><font face="arial, sans-serif">></font><span style="font-family:arial,sans-serif;font-size:13px">(select-random-safe-function)</span><span style="font-family:arial,sans-serif;font-size:13px"> </span></div>
<div>#<procedure:$-><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><br></div><div>whereas when it was defined using quote as opposed to list I get:</div><div><br></div><div><div><span style="font-family:arial,sans-serif;font-size:13px">>(safe-function-set)</span></div>
<div>'($+ $- $* $/)<span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><font face="arial, sans-serif">></font><span style="font-family:arial,sans-serif;font-size:13px">(select-random-safe-function)</span><span style="font-family:arial,sans-serif;font-size:13px"> </span></div>
<div>'$-</div></div><div><br></div><div><b>How would I get rid of this <u>#<procedure:</u>$-<u>></u> part for readability, keeping only the $- part which is the actual function I defined, while still keeping it a function/procedure that gives me the function arity using <span style="font-family:arial,sans-serif;font-size:13px">(procedure-arity (select-random-safe-function))?</span></b></div>
<div><b><span style="font-family:arial,sans-serif;font-size:13px"><br></span></b></div><div><span style="font-family:arial,sans-serif;font-size:13px">Best,</span></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Fri, Jan 3, 2014 at 5:31 PM, Sam Tobin-Hochstadt <span dir="ltr"><<a href="mailto:samth@cs.indiana.edu" target="_blank">samth@cs.indiana.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Try replacing `safe-function-set` with:<br>
<br>
(define safe-function-set (list $+ $- $* $/))<br>
<br>
Sam<br>
<div><div class="h5"><br>
On Fri, Jan 3, 2014 at 5:28 PM, Rian Shams <<a href="mailto:rian.shams@gmail.com">rian.shams@gmail.com</a>> wrote:<br>
> Hello,<br>
><br>
> I am working with functions that I have defined to only take 1 or 2 operands<br>
> (called safe-functions) for the implementation of a genetic program.<br>
><br>
> (define ($+ augend addend) ;operation is addition<br>
>   (+ augend addend)) ; the result is the sum<br>
> (define ($- minuend subtrahend) ;operation is subtraction<br>
>   (- minuend subtrahend)) ;result is difference<br>
> (define ($* multiplicand multiplier) ;operation is multiplication<br>
>   (* multiplicand multiplier)) ;result is product<br>
> (define ($/ dividend divisor) ;operation is division<br>
>   (/ dividend divisor)) ;result is quotient<br>
><br>
> (define (infinity? x) (or (eq? x +Inf.0) (eq? x -Inf.0)))<br>
> (define ($sin x) (if (infinity? x) (* (sgn x) +Inf.0) (sin x)))<br>
> (define ($cos x) (if (infinity? x) (* (sgn x) +Inf.0) (cos x)))<br>
><br>
> (define safe-function-set<br>
>   '($+<br>
>     $-<br>
>     $*<br>
>     $/<br>
>     ;$sin<br>
>     ;$cos))<br>
><br>
> (define (select-random-safe-function)<br>
>   (list-ref safe-function-set (random (length safe-function-set))))<br>
><br>
> I would like to use procedure-arity (or a similar function) to determine the<br>
> arity of a randomly selected safe function but I get this error:<br>
><br>
>>(procedure-arity (select-random-safe-function))<br>
> error: procedure-arity: contract violation<br>
>   expected: procedure?<br>
>   given: '$+<br>
><br>
> I think the problem is that the safe-functions are passed to procedure-arity<br>
> quoted. Is there a way I can unquote the functions, or adjust<br>
> procedure-arity to make (procedure-arity (select-random-safe-function))<br>
> work?<br>
><br>
> Thanks,<br>
> --<br>
> Rian Shams<br>
><br>
</div></div>> ____________________<br>
>   Racket Users list:<br>
>   <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Rian Shams
</div>