[plt-scheme] problem with string

From: besson baptiste (baptistebesson3 at yahoo.fr)
Date: Sun Jan 9 11:48:39 EST 2005

This is suppose to  cast val into a string padded to
the length of exp.
for ex:
(str$ 176 4) should return \0176
instead I always get two zero 00 before val
> (str$ 176 4)
"\000176"

but I get

> (string-length (str$ 176 4))
4

which is what I want.
I don't understand why is these 00  appear for any
value of val and exp.

> (str$ 1  2)
"\0001"

Thanks.

(define (str$ val exp)
  (let* 
      ((s (make-string exp ))   
       (s2 (number->string val))
       (l (string-length s2)))
    (let loop ((write (- exp l))
               (red 0))
      (if (= red l)  
          s
          (begin
            (string-set! s 
                         
                         write 
            (string-ref s2 red ))
    (loop (+ write 1)(+ red 1)))))))
  
        


	

	
		
Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour vos mails ! 
Créez votre Yahoo! Mail sur http://fr.mail.yahoo.com/



Posted on the users mailing list.