[plt-scheme] scribblings on PLT Scheme 4.0
Since I am certainly one of the set-car! and set-cdr! users that Jacob found in PLaneT, I guess I will weigh in on this one.
One place I use them is when dealing with association lists. At a fundamental level, they just use cons cells as a two element structure (i.e., and 'association'). While it might have been better to explicitly create that structure, that isn't an option in R5RS from which we get association lists. In that case, set-car! and set-cdr! are essentially just field setters for associations. [There is also the matter of the actual list structure for the associations, but you get the idea.]
I also use them, particularly in the Simulation Collection, for efficiency. Maintaining the various event lists and queues are a significant amount of the processing that takes place. I use set-cdr! in particular for efficiency there. A 2x performance hit would be significant. However, I also encapsulate all of that list manipulation (or mutilation, if you prefer) inside of my own modules to isolate them from user code.
I have objections at all to having the standard list constructors make immutable lists - the vast majority of mine are. As long as I can create mutable lists where I need them, I'll be quite happy - particularly if I get some GC performance improvement from it.
Doug
-----Original Message-----
From: plt-scheme-bounces at list.cs.brown.edu on behalf of Matthew Flatt
Sent: Mon 5/28/2007 4:29 AM
To: Paulo J. Matos
Cc: plt-scheme at list.cs.brown.edu
Subject: Re: [plt-scheme] scribblings on PLT Scheme 4.0
At Mon, 28 May 2007 11:17:52 +0100, "Paulo J. Matos" wrote:
> On 5/28/07, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> > At Mon, 28 May 2007 09:44:38 +1000, Andrew Reilly wrote:
> > > I'm new to scheme myself, so I probably sholdn't have been
> > > making such liberal use of append! in my own code. I will
> > > repent...
> >
> > Do you used them for performance reasons?
> >
> > I used `append!' and `reverse!' a lot in my early Scheming, too,
> > because they were faster. It bit me often enough (no surprise) that I
> > decided to stay away, though there are certainly cases where mutating
> > versions work fine.
> >
>
> I also use them for performance reasons sometimes. I use them for
> example when I want to sort a mapped list. I use (sort! (map f lst)).
> Or when I want to append a set of lists that results from map like
> (apply append! (map f lst)). I think using ! in these cases is good,
> afaik, because: 1. it's faster, 2. you know the list was just
> created, 3. you won't have problems.
I agree that you won't have problems, as long as you know that `f'
doesn't capture any continuations to be applied after the `sort!' or
`append!'.
How much time does `append!' save you in an actual application? My
guess is that the savings will be minor, but I'm interested in
measurements you might be able to take.
Matthew
_________________________________________________
For list-related administrative tasks:
http://list.cs.brown.edu/mailman/listinfo/plt-scheme
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070528/4b90264f/attachment.html>