Re: DD: Cookbook procedure markup sample (Was: DD: Status)

Subject: Re: DD: Cookbook procedure markup sample (Was: DD: Status)
From: Dave Love <>
Date: 02 Jul 1997 23:38:57 +0100
I noticed the substitute-char function.  I don't know about Jade, but
in a typical Scheme interpreter I wouldn't expect it to be efficient
because of undue consing.

For example, compare:
(define (subs s old new)
  (list->string (map (lambda (c)
		       (if (char=? c old)
		     (string->list s))))

Here's a session in the SCM Scheme interpreter.  Note the timings for
each evaluation and amount of storage allocated (`cells').  Ignore the
Scheme-specific `begin' wrapper which just avoids printing the long
result.  (The amount of substitution actually done doesn't matter,
BTW.)  `substitute-char' is from the marked-up example with the typpo
corrected (`+1').

> (define s (make-string 1000 #\a))
;Evaluation took 0 mSec (0 in gc) 12 cells work, 1034 bytes other
> (begin (subs s #\a #\b) #t)
;Evaluation took 10 mSec (0 in gc) 5018 cells work, 1032 bytes other
> (begin (substitute-char s #\a #\b) #t)
;Evaluation took 180 mSec (60 in gc) 10027 cells work, 503531 bytes other

This example may not show the same timing ratio in Jade because you'd
have to define non-built-in functions, but it's worth bearing in mind
the possible effect of constructing and throwing away intermediate
data structures if they're not `lazy' like node lists and there's a
fair amount of them.


 DSSSList info and archive:

Current Thread