teaching alloc and free in Scheme 
Author Message
 teaching alloc and free in Scheme

Quote:
> Date: 5 Feb 92 09:02:01 GMT

> What I'm going to do this semester is that I continue using Scheme,
> but introduce examples using Standard ML and C++. (To prevent flames:
> Scheme and ML are not much use when you want to talk about freeing and
> reserving memory etc., which IMHO are worthy things to know).

1. This doesn't explain why you use SML?  (I'm not saying you
   shouldn't; but I'm interested in the reasons.)

2. You can do something with allocating and freeing in Scheme by
   doing what I think Zetalisp called resources.  You have a pool
   of objects of some type that are allocated, freed, and reused,
   rather than making new objects all the time.

   Or you could have an object that represented a pointer into
   a giant vector and do all the alloc stuff you wanted from
   that.  (This could be hidden from the students, whoi just see
   some alloc proimitives.)

   Also look at the storage management section of SICP.

-- jd



Sat, 30 Jul 1994 02:48:05 GMT  
 teaching alloc and free in Scheme
   > What I'm going to do this semester is that I continue using Scheme,
   > but introduce examples using Standard ML and C++. (To prevent flames:
   > Scheme and ML are not much use when you want to talk about freeing and
   > reserving memory etc., which IMHO are worthy things to know).

   1. This doesn't explain why you use SML?  (I'm not saying you
      shouldn't; but I'm interested in the reasons.)

I'm using SML partly because of the background of the students (we
have an introductory course here that uses SML), and partly because of
its strong abstract data type facilities. I am also trying to
emphasize the point that a programming language is just a vehicle for
expressing algorithms, and that sometimes you express the same thing
in different ways in different languages.

   2. You can do something with allocating and freeing in Scheme... [etc.]

I ould do that, but somehow I feel a bit uneasy about that, because
everybody knows that there is a garbage collector underneath anyway.
It is also pretty difficult to produce a stray pointer that will crash
your program in Scheme. That is something I would like to make my
students experience at least once, and understand afterwards what hit
them. A lot of them will be writing code for embedded systems, which
means that they will be programming in C or C++.

Teaching dynamic data structures using Scheme -- or SML for that
matter -- is great fun, because the structures are so easy to create
and dispose of. However, that leaves out an important aspect of using
them in "real life" (read: C, Pascal, Ada etc.), namely the allocation
and freeing of memory.

It seems that a great source of C++ source code for trees, hash tables
and so on is the GNU class library. Does anyone have opinions or
experience about the quality of the code? (This should propably not be
discussed here, so you can just email me).

--
Pertti Kellom\"aki (TeX format)  #       These opinions are mine,
  Tampere Univ. of TeXnology     #              ALL MINE !
      Software Systems Lab       #  (but go ahead and use them, if you like)



Sat, 30 Jul 1994 17:05:00 GMT  
 teaching alloc and free in Scheme

Quote:


>   2. You can do something with allocating and freeing in Scheme... [etc.]

>I ould do that, but somehow I feel a bit uneasy about that, because
>everybody knows that there is a garbage collector underneath anyway.
>It is also pretty difficult to produce a stray pointer that will crash
>your program in Scheme.

The equivalent of a dangling pointer in a Lisp/Scheme "resource" system
occurs when you keep a reference to an object after it's been returned to
the resource and allocated for some other use, e.g.

        ;; Assume allocate-vector and free-vector access the vector resource
        (set! foo1 (allocate-vector 1))
        (vector-set! foo1 0 (cons x y))
        (set! other-thing foo1)
        ...
        (free-vector foo1)
        ...
        (set! foo2 (allocate-vector 1)) ; this could return the same vector
        (vector-set! foo2 0 1)
        ...
        (car (vector-ref other-thing 0)) ; error!

And unlike C malloc()/free(), you can make such error happen reliably, and
you can experiment with various ways to implement resources and see how
they affect such problems.  For instance, should ALLOCATE-VECTOR or
FREE-VECTOR zero or null out the vector?
--
Barry Margolin, Thinking Machines Corp.


{uunet,harvard}!think!barmar



Mon, 01 Aug 1994 06:48:13 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Translations from Scheme to C++ as aid to teaching C++ after Scheme

2. Scheme and the teaching of Scheme

3. Memory alloc/free

4. memory alloc and free

5. Scheme implementation strategies (was: Free Macintosh Scheme)

6. UMB Scheme -- Free Scheme Interpreter

7. MswLogo 3.4 is ready to Teach (Free software doesn't get much better)

8. LOGO-L> Free Logo Teaching Materials

9. Eiffel/C++ (was Re: teaching and learning with LISP/Scheme)

10. Scheme for Teaching

11. Teaching Scheme (Q)

12. Who is teaching Scheme?

 

 
Powered by phpBB® Forum Software