views:

218

answers:

2

How can I use arrays in scheme?

In particular, I'm attempting to implement a recursive fibonacci procedure using memoization. Do arrays even exist in scheme?

If not, how can I implement memoization?

+2  A: 

There are arrays in Scheme, but they are called vectors. Be aware that they don't resize like they do in other languages like Perl and Javascript, or the like-named C++ thing; you have to make a bigger one and copy the contents of the obsolete one over.

If you want to know more about memoization and dynamic programming in particular, you can read chapter 12 of the free book Concrete Abstractions.

Cirno de Bergerac
`they don't resize; you have to make a bigger one and copy the contents of the obsolete one over.` Sounds exactly like an array from any other language. Are there any subtle differences I should be aware of (let's say, between scheme vectors and c arrays)? Thanks!
Cam
I guess just that scheme vector elements can contain any object like any other variable or cons cell, and not limited to "array of _____".
Cirno de Bergerac
A: 

This is not a direct answer, so feel free to downvote etc: if you're using PLT and you need memoization then you should look at Dave Herman's memoize package. Also, you could grab the memoize function from the swindle library.

Eli Barzilay
Is pretty big scheme PLT? I'm a bit confused with regards to what 'PLT Scheme' is.
Cam
Yes, "Pretty big" is the name of a language level in DrScheme, all part of the PLT Scheme language which is what you're using. (And the project is being renamed these days to Racket, partly to avoid such confusions.)
Eli Barzilay