I am trying to do exercise 2.78 in SICP, but the functions put and get are unknown. I have tried multiple languages, like pretty big, racket, r5rs, mit-scheme, mzscheme, etc. I even downloaded the SICP support (http://www.neilvandyke.org/sicp-plt/), to no avail. How can I get these functions to work?
相关问题
- Generating powerset in one function, no explicit r
- What is fixed point?
- unfold function in scheme
- returns the first n of list
- How to use (read) correctly in mit-scheme?
相关文章
- Does learning one Lisp help in learning the other?
- What is the definition of “natural recursion”?
- How do I define a sub environment in scheme?
- Why is it legal in a function definition to make s
- How to split list into evenly sized chunks in Rack
- Difference between OOP and Functional Programming
- Good simple algorithm for generating necklaces in
- Why is there no tail recursion optimization in Ema
Yes, I found SICP a little annoying sometimes because of stuff like this. Functions that are assumed to exist but don't actually exist make it harder to try to the examples. I wrote my own (get) and (put) like so (this was in GNU guile):
Probably a naive implementation from the perspective of later in the book, but fairly simple and worked fine.
mit-scheme has a built-in global table that you can use.
http://www.gnu.org/software/mit-scheme/documentation/mit-scheme-ref/The-Association-Table.html
simply define get and put to:
In subsection
Creating local tables
of3.3.3 Representing Tables
, there is an implementation.There is an implementation of put and get by Eli Bendersky. These functions could be implemented using builtin Basic Hash Table Operations. Here is my modified version of Eli's code to work properly with MIT-Scheme Release 9.1.1.
UPDATED:
I've found bug with above mentioned code after time. Empty lists are interpreted as
true
in conditional clauses by Scheme, so correctget
implementation should be following:If you use Racket programming language please use these: