s c h e m a t i c s : c o o k b o o k

/ Cookbook.MiscSICP

This Web


WebHome 
WebChanges 
TOC (with recipes)
NewRecipe 
WebTopicList 
WebStatistics 

Other Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Schematics


Schematics Home
Sourceforge Page
SchemeWiki.org
Original Cookbook
RSS

Scheme Links


Schemers.org
Scheme FAQ
R5RS
SRFIs
Scheme Cross Reference
PLT Scheme SISC
Scheme48 SCM
MIT Scheme scsh
JScheme Kawa
Chicken Guile
Bigloo Tiny
Gambit LispMe
GaucheChez

Lambda the Ultimate
TWiki.org

How To Run SICP Programs in DrScheme

Problem

Getting a program from SICP to run in DrScheme.

Solution

Choose the Proper Language

Streams

SICP? uses a primitive named cons-stream. Paste the following at the top of the definition window to make this primitive available.

(require (lib "defmacro.ss"))

; cons-stream : obj stream ->  stream
;   construct a stream whose first element is obj and whose tail is stream
;   [cons-stream is a special form]
(define-macro cons-stream
  (lambda (car cdr)
    `(cons ,car (delay ,cdr))))

For other SICP stream functions, see: http://list.cs.brown.edu/pipermail/plt-scheme/2003-March/001945.html.

Non-deterministic programming

Chapter 4.3 on non-deterministic programming uses the special form amb. Insert the following at the top of the definition window.

(require (lib "defmacro.ss"))

(define amb-fail '*)

(define initialize-amb-fail
  (lambda ()
    (set! amb-fail
      (lambda ()
        (error "amb tree exhausted")))))

(initialize-amb-fail)

(define-macro amb
  (lambda alts...
    `(let ((+prev-amb-fail amb-fail))
       (call/cc
        (lambda (+sk)

          ,@(map (lambda (alt)
                   `(call/cc
                     (lambda (+fk)
                       (set! amb-fail
                         (lambda ()
                           (set! amb-fail +prev-amb-fail)
                           (+fk 'fail)))
                       (+sk ,alt))))
                 alts...)

          (+prev-amb-fail))))))

The Picture Language

The picture language is available as a .plt?-file from Michael Sperber.

For instruction on installing it, see ee HowToInstallPLTFile.

To use it, read on.

07:58:14 <soegaard> You were asking about the picture language in SICP, right?
07:58:38 <jim> soegaard: yes
07:58:58 <soegaard> Mike Sperber implemented it for PLT Scheme.
07:59:18 <jim> cool :)

07:59:45 <soegaard> In DrScheme go to the file menu, and choose "Install .plt file"
08:00:07 <soegaard> Then enter
08:00:08 <soegaard> http://www-pu.informatik.uni-tuebingen.de/users/sperber/software/picture.plt

08:06:33 <soegaard> jim: I am looking for documentation to start it, it must be there somewhere

08:13:45 <soegaard> ah!
08:14:22 <soegaard> jim: In the "Language" menu choose "Add TeachPack".
08:15:24 <soegaard> jim: Then choose the file picture.ss hidden in the TeachPack directory (on my machine: C:/documents
and settings/js/Application Date/PLT 208.1/teachpack/picture.ss
08:15:38 <soegaard> jim: Press "Go"
08:15:56 <soegaard> jim: Then try: (paint (corner-split einstein 1))
08:16:30 <jim> soegaard: trying to find the teachpack (I installed the file as root in linux)

08:31:19 <soegaard> jim: And (paint (corner-split einstein 1)) works?
08:32:51 <jim> we're getting there. it knows paint but not corner-split
08:33:19 <jim> hah! it works
08:33:28 <soegaard> jim: ah! I loaded one of the example files first
08:33:32 <jim> (paint einstein)
08:34:08 <soegaard> jim: I loaded example.scm first and corner-split is defined there.
08:34:50 <jim> are there stick figures?

08:36:01 <soegaard> jim: Open the file collects/painters.ss and see all the provided procedures.
08:36:14 <jim> ahh
08:36:21 <soegaard> jim: There is a segments->painter which can be used to make stick figures.
08:37:45 <jim> soegaard: ok, good enough... now how can I make the imagelarger?
08:38:00 <soegaard> use paint-hi-res
08:39:41 <jim> soegaard: -very- good :) thank you very much :)
08:39:51 <soegaard> no problem

Discussion

The amb -macro was taken from "Teach Yourself Scheme in a Fixnum of Days" by Dorai Sitaram. This book is integrated in DrScheme - to read it open the HelpDesk, click at manuals, then click at its title.


Comments about this recipe

Contributors

-- JensAxelSoegaard - 16 Jan 2005

CookbookForm
TopicType: Other
ParentTopic:
TopicOrder: 999

 
 
Copyright © 2004 by the contributing authors. All material on the Schematics Cookbook web site is the property of the contributing authors.
The copyright for certain compilations of material taken from this website is held by the SchematicsEditorsGroup - see ContributorAgreement & LGPL.
Other than such compilations, this material can be redistributed and/or modified under the terms of the GNU Lesser General Public License (LGPL), version 2.1, as published by the Free Software Foundation.
Ideas, requests, problems regarding Schematics Cookbook? Send feedback.
/ You are Main.guest