[racket] Strange Behavior around memq、memv、and member

From: Justin Zamora (justin at zamora.com)
Date: Mon Dec 30 17:06:50 EST 2013

Your comment says that y-or-n? returns either #t or #f. I see the line
where you return #t. Where do you return #f?

Justin
On Dec 30, 2013 4:04 PM, "亀田馬志" <masashi.kameda at gmail.com> wrote:

> Hello.
>
> I think I understand how memq, memv, member works:
>
> > (memq 'y '(y yes n no))
> '(y yes n no)
> > (memq 'n '(y yes n no))
> '(n no)
> > (memq 'racket '(y yes n no))
> #f
> >
>
> By the way, I wrote a procedure as follows:
>
> (require srfi/13)
>
> (define (yes-or-no? arg)
>   ; expected it returns #t or #f
>   ; depending on input such as yes or no
>   (letrec ((y-or-n?
>             ; if argument is either Y or YES,
>             ; it returns #t otherwise #f
>             (lambda (sym)
>               (and (memq sym '(Y YES)) #t)))
>            (symbol-upcase
>             ; confirm any symbol into uppercase
>             (lambda (arg)
>               (if (symbol? arg)
>                   (string->symbol (string-upcase (symbol->string arg)))
>                   (yes-or-no? (read))))))
>     (let ((sym (symbol-upcase arg)))
>       (if (memq sym '(Y YES N NO))
>           (y-or-n? sym)
>           (yes-or-no? (read))))))
>
> I expected that (cond ((I input y or yes) returns #t)
>                                ((I input n or no) returns #f)
>                                (else this procedure waits something))
>
> However, result is sooooo strange:
>
> > (yes-or-no? (read))
> 3
> 2
> 4
> foo
> bar
> baz
> yes
> y
> no
> n
> #f
>
> Notice that even though yes, y or no is entered, the procedure ignores and
> it never returns #f until n is entered.
> Strange.
> Does anyone know why this doesn't work?
>
> Thanks.
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20131230/3edd5df9/attachment-0001.html>

Posted on the users mailing list.