<div class="gmail_quote">On Fri, Sep 28, 2012 at 3:13 PM, <span dir="ltr"><<a href="mailto:heraklea@gmx.de" target="_blank">heraklea@gmx.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thank you,<br>
<br>
I write my first lambda ;o). What about this:<br>
(define string->mformat<br>
(lambda (str)<br>
(lambda (n)<br>
(lambda (filler) (if (equal? (string-length str) n)<br>
str<br>
(((string->mformat (string-append filler str)) n) filler))))))<br>
<br>
It only prepends, but is this style ok??<br></blockquote><div><br>It depends if you are required to have a particular style (for class, for example), but your code can be rewritten more conveniently (with some subtle differences though) to:<br>
(define (string->mformat str n filler)<br> (if (equal? (string-length str) n)<br> str<br> (string->mformat (string-append filler str) n filler)))<br><br>Equivalently:<br>(define string->mformat <br> (lamda (str n filler) ....<br>
))<br><br>Some would prefer to use cond instead of if, but in this particular case that's mainly a matter of taste I believe.<br><br>It is also possible to use build-string, without using explicit recursion:<br>(define (string->mformat str n filler)<br>
(string-append<br> (build-string (max 0 (- n (string-length str)))<br> (lambda (x) filler))<br> str))<br><br>Laurent<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Yours,<br>
<br>
-------- Original-Nachricht --------<br>
> Datum: Thu, 27 Sep 2012 16:26:00 +0200<br>
> Von: Laurent <<a href="mailto:laurent.orseau@gmail.com">laurent.orseau@gmail.com</a>><br>
> An: <a href="mailto:heraklea@gmx.de">heraklea@gmx.de</a><br>
> CC: racket <<a href="mailto:users@racket-lang.org">users@racket-lang.org</a>><br>
> Betreff: Re: [racket] Filling number<br>
<div class="HOEnZb"><div class="h5"><br>
> Hi,<br>
><br>
> Looking for a friend of real->decimal-string (which does only partly what<br>
> you want), I see that the nightly builds include a family of value<br>
> formatters like ~a, ~v, etc.<br>
> You probably want ~r, for example:<br>
> > (~r 42 #:min-width 5 #:pad-string "0")<br>
> "00042"<br>
><br>
> They have many options that should fit your needs.<br>
><br>
> Cheers,<br>
> Laurent<br>
><br>
> On Thu, Sep 27, 2012 at 4:11 PM, <<a href="mailto:heraklea@gmx.de">heraklea@gmx.de</a>> wrote:<br>
><br>
> > Hello friends,<br>
> ><br>
> > I search the docu, but I cannot find how I can fill a number with<br>
> leading<br>
> > zeros or trailing zeros.<br>
> ><br>
> > I am using number->string and would like fill the missing zeros.<br>
> ><br>
> > Yours,<br>
> > ____________________<br>
> > Racket Users list:<br>
> > <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
> ><br>
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</div></div></blockquote></div><br>