[plt-scheme] padding numbers

From: Jens Axel Soegaard (jensaxel at soegaard.net)
Date: Thu Oct 16 10:43:22 EDT 2008

David Vanderson wrote:
> #lang scheme
> (require srfi/13)
> (apply string-append (map (lambda (e)
>                               (string-pad (format "~x" e) 2 #\0))
>                           '(0 255 0)))

This was the best I could think of.  Is there a simpler way?

Not really. I'd probably make a little helper function,
but basically it is the same solution.

    (define (pad2 s) (string-pad (format "~x" s) 2 #\0))
    (apply format "~a~a~a" (map pad2 (list 0 255 0)))

Jens Axel

Posted on the users mailing list.