On Fri, Mar 2, 2012 at 5:04 PM, Jim Ursetto
<address@hidden> wrote:
eqv?, to be exact. Your case statement works fine for me, with for example (comp->text '=). (eq? comp =) compares against the value of the procedure =, whereas the case compares against the symbol =. So you are doing two different comparisons.
I'm trying to convert a comparison operator to the equivalent text. These are not symbols. I think case treats the target list as if it was created with a quote: '(>). Thus things are all symbols in the list and the eqv? returns false.
> (case > ((>) "yup")(else "nope"))
"nope"
> (cond ((eqv? > >) "yup")(else "nope"))
"yup"
>
The cond does what I need just fine, I just didn't understand why case didn't also work.
Is there a more schemeish way to convert any of the operators to the text representation?
(define gt >)
(op->string gt)
=> ">"
You can use ,x (case ...) at the REPL to see what the case expands to.
Fake edit: Kon said this more succinctly than I did.
Jim
On Mar 2, 2012, at 5:52 PM, Matt Welland wrote:
I expected this to work:
(define (comp->text comp)
(case comp
((=) "=")
((>) ">")
((<) "<")
((>=) ">=")
((<=) "<=")
(else "unk")))
But had to convert to a cond with (eq? comp =) etc...
I thought case was supposed to use eq? to do the compare?