Re: [racket] Super basic question about strings

2010-11-17 Thread Neil Van Dyke
I'm also now curious whether the string port implementation could be sped up at all, perhaps in light of the JIT. Oh, I just looked at the string output-port C code in Racket 5.0.1, and I'm kinda wanting to do a pure Racket implementation that is accessible to the JIT, and see how it compare

Re: [racket] Super basic question about strings

2010-11-17 Thread Neil Van Dyke
Matthias Felleisen wrote at 11/17/2010 01:48 PM: Changing from ~s to ~a makes ALL of our versions almost twice as fast as Neil's. Not using format at all is still the fastest way to go. Functional programming remains better than imperative programming. I generally agree with the point abo

Re: [racket] Super basic question about strings

2010-11-17 Thread Matthias Felleisen
On Nov 17, 2010, at 1:17 PM, Eli Barzilay wrote: > 10 minutes ago, Matthias Felleisen wrote: >> >> The bottleneck is format. [...] > > The main bottleneck is using format with "~s" -- it's big enough to > shadow other changes. Eli is correct. Changing from ~s to ~a makes ALL of our versions

Re: [racket] Super basic question about strings

2010-11-17 Thread Eli Barzilay
9 minutes ago, namekuseijin wrote: > On Wed, Nov 17, 2010 at 4:00 PM, Matthias Felleisen > wrote: > > (define (alist->string.v5 alist) > >  (string-join (map (lambda (x) (string-append (symbol->string (car x)) "=" > > (number->string (cdr x alist) " ")) > > don't you guys think it would be s

Re: [racket] Super basic question about strings

2010-11-17 Thread Eli Barzilay
10 minutes ago, Matthias Felleisen wrote: > > The bottleneck is format. [...] The main bottleneck is using format with "~s" -- it's big enough to shadow other changes. IIRC, "~s" is implemented via a string port, and if so, one reason for Neil's version being faster is that it already outputs to

Re: [racket] Super basic question about strings

2010-11-17 Thread namekuseijin
On Wed, Nov 17, 2010 at 4:00 PM, Matthias Felleisen wrote: > (define (alist->string.v5 alist) >  (string-join (map (lambda (x) (string-append (symbol->string (car x)) "=" > (number->string (cdr x alist) " ")) don't you guys think it would be slightly more readable if string-join accepted the

Re: [racket] Super basic question about strings

2010-11-17 Thread Matthias Felleisen
On Nov 17, 2010, at 10:16 AM, Neil Van Dyke wrote: > For new students, I would show them examples like Eli and Matthias did. For > production work, I usually build up strings using string ports. > > Compared to various ways of building lists and doing "string-append", or to > simply doing lot

Re: [racket] Super basic question about strings

2010-11-17 Thread Neil Van Dyke
Richard Lawrence wrote at 11/17/2010 11:18 AM: It's nice to know that ports are the right thing to grow up into, though. Right now, string ports often seem the way to go. However, if we get lots of CPU cores in the future, I imagine that this might change, or that we'll want to make somet

Re: [racket] Super basic question about strings

2010-11-17 Thread Richard Lawrence
Neil Van Dyke writes: > For new students, I would show them examples like Eli and Matthias > did. For production work, I usually build up strings using string > ports. > > Compared to various ways of building lists and doing "string-append", > or to simply doing lots of incremental "string-appen

Re: [racket] Super basic question about strings

2010-11-17 Thread Richard Lawrence
Matthias Felleisen writes: > On Nov 17, 2010, at 2:40 AM, Eli Barzilay wrote: > >> (define (alist->string alist) >> (string-join >> (for/list ([a (in-list alist)]) >> (format "~a=~a" (car a) (cdr a))) >> " ")) > > > Somewhat more 'native': > > (define (alist->string l)

Re: [racket] Super basic question about strings

2010-11-17 Thread Neil Van Dyke
For new students, I would show them examples like Eli and Matthias did. For production work, I usually build up strings using string ports. Compared to various ways of building lists and doing "string-append", or to simply doing lots of incremental "string-append" or "format", using a string

Re: [racket] Super basic question about strings

2010-11-17 Thread namekuseijin
On Wed, Nov 17, 2010 at 5:34 AM, Richard Lawrence wrote: > Dear Racketeers: > For example, suppose I want to consume an association list like >  '((k1 . v1) (k2 . v2) ...) > and produce a string that looks like: >  "k1=v1 k2=v2 ..." (join " " (map (lambda (kv) (string-append

Re: [racket] Super basic question about strings

2010-11-17 Thread Matthias Felleisen
On Nov 17, 2010, at 2:40 AM, Eli Barzilay wrote: > (define (alist->string alist) > (string-join > (for/list ([a (in-list alist)]) > (format "~a=~a" (car a) (cdr a))) > " ")) Somewhat more 'native': (define (alist->string l) (string-join (map (lambda (x) (for

Re: [racket] Super basic question about strings

2010-11-16 Thread Eli Barzilay
Two minutes ago, Richard Lawrence wrote: > Dear Racketeers: > > Ok, I feel really silly asking this, because I feel like I am missing > something really conceptually basic, but the answer isn't apparent to me > from the examples in the Guide: > > What's the right way to programatically build up s

[racket] Super basic question about strings

2010-11-16 Thread Richard Lawrence
Dear Racketeers: Ok, I feel really silly asking this, because I feel like I am missing something really conceptually basic, but the answer isn't apparent to me from the examples in the Guide: What's the right way to programatically build up strings in Racket? For example, suppose I want to consu