The most literal translation is

#lang racket
(define select-room (lambda (number rooms)
                      (let loop ((l (mcar rooms)))
                        (if (not (null? l))
                            (if (= (mcar(mcar l)) number)
                                (mcar l)
                                (loop (mcdr l)))
                            (void)))))  ;<-- explicit "else" branch

You can replace (void) with whatever you want to signal that nothing
is found, like 'not-found, but the more idiomatic versions is to
return #f.

(define select-room (lambda (number rooms)
                      (let loop ((l (mcar rooms)))
                        (if (not (null? l))
                            (if (= (mcar(mcar l)) number)
                                (mcar l)
                                (loop (mcdr l)))
                            #f))))  ;<-- explicit "else" branch

It's not possible to return "nothing", you must return something, like
(void) or #f or 'not-found. When you are going to ignore the result,
it's better to return (void), but if you want to signal that something
is not found it's better to return #f, or raise an error. (Actually,
you can return "nothing", but let's hide that under the carpet for few
months, because it doesn't play nice with most racket code.)

But now set-symbol has to check that traps is not #f:

(define set-symbol!
  (lambda (symbol number_of_room)
    (let ((traps (mcdr(select-room number_of_room environment))))
          (if traps
             (set-mcdr! traps (mcons symbol (mcdr traps)))
             (void)))) ;<-- explicit "else" branch

Here, it's better to return (void) because you are going to ignore the
result, and set-mcdr! returns also (void). The default printer ignore
voids results and prints "nothing", so (void) will be better here.

(I renamed set-symbol as set-symbol!, because the name of most
functions that mutate their argument have bang. It's not a rule, only
a style recommendation.)

A more idiomatic version use when, unless, and and or, but I'm triying
to make the minimal changes to your code.

Gustavo



On Sun, Apr 10, 2016 at 11:30 AM, Joan Martin <joanmar1...@gmail.com> wrote:
> Thank for your answer,
> but how should I change the procedure and ged rid of Racket warning?
> I cant figure it out.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to