Feedback You don't need to solve the printout problem 

Forum: Com Sci 12500, U Chicago, Autumn 2002, Discuss Classwork
Re: News Project Step #1, due Friday 8 November
Re: Question how do we represent intervals? (Alison Lanski)
Date: 2002, Nov 07
From: Mike O'Donnell <odonnell@cs.uchicago.edu>

First, a bit of pickiness about terminology. We "represent" rational intervals internally in computations as S-expressions of the form (<r1> <r2>). Scheme may "print" or "output" these internal representations in various ways as sequences of characters. The dictionary meaning of the word "represent" can refer to all sorts of representations, including either the internal form or the output form, but it's more common in computing projects for the word "represent" by itself to refer to internal data representation. The Scheme manual refers to the forms in which expressions are typed as inputs and printed as outputs as "external representations." It's clear that you are referring to the external representation, or printed form, of rational intervals.

For Step #1 of the project (and probably for the remainder of the project as well), I'm not requiring that you adjust Scheme's external representations for ratintvls. So, if you just evaluate (make_ratintvl 1/3 1/2) in your ratpair implementation, Scheme should just print out (1/3 1/2):


make_ratintvl 1/3 1/2)
;value: (1/3 1/2)
That is the external representation of your internal representation of the interval [1/3,1/2] in the ratpair implementation.

std_ratintvl->string is intended to solve the computationally interesting part of printing out a nicer presentation of a rational interval, and one that can be uniform across different implementations of ratintvl. Among other things, it will allow you to do more of your testing above the abstraction barrier, by comparing values of expressions of the form (std_ratintvl->string <expr>) to correct strings that you have constructed by hand. (You still need to do some testing below the abstraction barrier: particularly your testing of std_ratintvl->string itself). But std_ratintvl->string only returns a string, which may then be printed by Scheme according to the standard external representation of strings. For example:


(std_ratintvl->string (make_ratintvl 1/3 1/2))
;Value: "[1/3,/12]"

(std_ratintvl->string (make_ratintvl 4/2 8/2))
;Value: "[2,4]"

If we decided to integrate the square-bracketed notation for intervals into Scheme's external representations, we would have to do some more work, based on the instructions in Section 14.7 of the MIT Scheme Reference. It appears from a quick look that we would have to tag our rational intervals in some way to make this work. For a complete integration of rational intervals into Scheme, we would also want to allow square-bracketed notation as input in an S-expression to be evaluated. That is described in Sections 14.10 and 14.11. It's probably harder than output.

I don't expect to require this sort of integration of our project work into Scheme. This task is available for those who would like to go beyond the project requirements. If anyone wants to do it, I recommend that you do it as an open project, and share the results with everybody.




Mike O'D.


to: "You don't need to solve the printout problem"