This is the mail archive of the guile@cygnus.com mailing list for the guile project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
On 30 Oct 1998, Russ McManus wrote:
> Jay-
>
> I'm very sorry that I assumed that you didn't know much Scheme,
> obviously I was wrong.
>
no, I was a jack-ass to get my back up at what you said. I'd just settled
down at my desk after some horrific meeting and I was in a bad mood.
I must confess that although I've been studying Scheme for a while now, I
really am a bit rusty at practical Scheme programming; you guessed
correctly.
> > > > In my experience, functional style Scheme code is concise and, unless
> > > > you're careful, slow.
> > >
> > > This is an attribute of a particular implementation, not an intrinsic
> > > property of the language.
> >
> > no, purely functional code is intrinsically slow.
>
> Hmm. I think your definition of slow and mine are different. Could
> you clarify what you mean when you say 'slow'? How do you account for
> the performance of Stalin?
>
a while back I posted something like this:
hash->keys could be written in Scheme like this
(define entry->key cadr)
(define hash->keys
(lambda (mytab)
;; maybe do some type-checking here
(let* ((vec (cdr mytab))
(vec-len (vector-length vec)))
(do ((keys '())
(i 0 (+ i 1))
(bucket (vector-ref vec 0) (vector-ref vec i)))
((>= i vec-len) keys)
(do ((entry-list bucket (cdr entry-list)))
((null? entry-list))
(let* ((entry (car entry-list))
(key (entry->key entry)))
(set! keys (cons key keys))))))))
here's what I would call a functional version:
(define hash->keys
(lambda (mytab)
(let ((bucket->keys (lambda (bucket) (map entry->key bucket)))
(entry->key cadr))
(apply append (map bucket->keys (vector->list (cdr mytab)))))))
the functional guy is sleek and pretty, but those "vector->list" and
"append" bits are performance killers.
> -russ
>
> --
> "C makes it easy to shoot yourself in the foot. C++ makes it
> harder, but when you do, it blows away your whole leg."
> -- Bjarne Stroustrup on C++
>