[plt-scheme] should .scm's be text-only?

From: George Herson (gherson at snet.net)
Date: Sun Dec 24 12:30:53 EST 2006

Merry, Merry Christmas,

I'm new to Scheme with just one .scm of significant
size written but I've already run into an inability to
load it (and its auto'ly created backup, with error
"insert-file in text%: error loading the file"). 
Since the file was binary encoded, I'd of been SOL
were it not for the favor of a seasoned PLT
professional.  My purpose here is to ask if there's
really a good enough reason for the .scm to remain a
binary rather than a text format, and to propose a
text-only alternative.  This alternative should avoid
any changes to the DrScheme user interface and avoid
any loss of functionality.

It seems that the binary format was imposed for two
reasons: to allow the encoding of 1) images and 2) the
other items on DrScheme's Special menu.  

Regarding 1), I propose that images no longer be
embedded by default, but "inserted" by reference, as
they are in html.  Embedding a binary directly into an
.scm remains an option via uuencoding (as in email).

Advantages: In addition to allowing the .scm to be
text-only, the size of the code file would be greatly
reduced if images were only referred to (of course). 
Images that are part of the DrScheme installation can
be referenced there, and perhaps url image references
can also be enabled (as in html).

Regarding 2), DrScheme's other Special insertions may
be enabled by DrScheme at .scm load time by
interpreting special comments in the .scm.  Details
below.

Advantages:  In addition to allowing the .scm to be
text-only, portable .scm programs may be correctly
executed by other Scheme systems.

Two quick examples:

I. example-I.scm is fraction followed by a comment
box.  

Shown in DrScheme:
 4 
3-
 5 
┌─────────────────────────────────────────────────┐
│;(display "This line is commented out and in   
 │ 
│ DrScheme appears in a proper comment box.")   
 │            
└─────────────────────────────────────────────────┘

As written by DrScheme to file as text:

;«Insert-Fraction
(+ 3 (/ 4 5))
;»
;«Insert-Comment-Box
;(display "This line is commented out and in DrScheme 
; appears in a proper comment box.") 
;»

Discussion: 
a) The guillemet from Latin-1
(http://www.htmlhelp.com/reference/html40/entities/latin1.html)
serves as our special purpose, internal-use delimiter.
b) DrScheme, knowing what it means when a user clicks
Special - Insert Comment Box, writes
";«Insert-Comment-Box ... ;»" to the .scm
representation AND comments out the code so delimited.
When displaying same, DrScheme puts the code in a
comment box, as currently.

(small) downside: If a user enters ;» or ;« flush left
left in DrScheme, DrScheme can no longer write them as
such to file because they now have a special meaning. 
This should be easy to work around, perhaps by
DrScheme transparently inserting a null character
between them in the .scm representation (not on
screen). 
(A DrScheme expert (not me) is required to know
whether this particular trick will work, and suggest
another if it doesn't.)

II. example-II.scm is a comment box that includes a
fraction and image.  Shown in DrScheme:
┌────────────────────────────────────────────────┐
│;(display "Boxed by the Doc and ignored by the 
│
│ rest.")                                       
│
│  4                                            
│
│ 3-                                            
│
│  5                                            
│
&#9474; <plt lambda logo here (pretend)>              
&#9474;
&#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;

Shown by the operating system:

;«Insert-Comment-Box
;(display "Boxed by the Doc and ignored by the rest.")
;«Insert-Fraction
;(+ 3 (/ 4 5))
;«Insert-Image
"http://www.plt-scheme.org/plt-green.jpg"
;(display "http://www.plt-scheme.org/plt-green.jpg
([icon]")
;»»»

Discussion: 
a) The fraction and image are commented out because
they were entered within the comment box in DrScheme:
Special insertions remain nestable.
b) When not commented out, images are represented in
non-DrScheme Scheme systems as strings showing the
referenced filename and, for urls, the alternate image
text.

Feed me back?

best,
George Herson


Posted on the users mailing list.