2013/4/1 Nala Ginrut <[email protected]>:
> I've tried to implement a function to mimic string multiply like Python:
> "asdf" * 10
>
> --------------code----------------
> (define (str* str n)
> (format #f "~{~a~}" (make-list n str)))
>
> or
>
> (define (str* str n)
> (string-join (make-list n str) ""))
> --------------end-----------------
>
>
Those are both very general mechanisms, it does not suprise me that
they are less than efficient for very large N. Although I can not
comment whether this is a worthwhile issue to address, I offer this
snippet as a hint of something perhaps better for your specific case:
(define (str* str n)
(call-with-output-string
(lambda (p)
(let lp ((n n))
(unless (zero? n)
(display str p)
(lp (1- n)))))))
Out of curiousity, how does the performance figures you showed compare
to the Python operator for similarly large values of N?