[gambit-list] Idiomatic Scheme

Adrien Piérard pierarda at iro.umontreal.ca
Wed Jan 18 23:07:32 EST 2012


> Hi,

Hi,

Just a few comments, not really answering your question (I don't have
enough time for that now, sorry)

>         ; Assign each name a random number and then sort them
>         (map (lambda (x) (blob-name-random-set! x (random-integer 65536)))
> unused-name-list)

If you want to do side effects only, use FOR-EACH instead of MAP.
It's way more meaningful for those who read the code (and also, the
order is guaranteed left to right, though you do not seem to care
here)

>         (sort! unused-name-list (lambda (x y)
>             (if (< (blob-name-random x) (blob-name-random y)) #t #f))))

(sort! u-n-l (lambda (x y) (< (b-n-r x) (b-n-r y))))
No need to return #t and #f


>       ;; Put all the seed names in the list
>       (map (lambda (x) (push (make-blob-name x) unused-name-list))
> seed-names)

FOR-EACH too.

>       (lambda (message . arguments)
>         (cond ((eq? message ':get-name!)

Maybe a newline after COND would help reading a bit here.

>               (if (null? unused-name-list)
>                 "No names available"
>                 (begin
>                   (let ((name (blob-name-name (car unused-name-list))))
>                     (set! unused-name-list (cdr unused-name-list))
>                     name))))

Useless BEGIN, since you have only one expression, the LET

> How can I improve the code?

I'll let the others give more comments.

Cheers,

P!

-- 
Français, English, 日本語, 한국어



More information about the Gambit-list mailing list