[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scheme acceptance [no flames]



Shriram Krishnamurthi wrote:
>   Paul Fernhout has been playing with a new Scheme syntax.  Hopefully
>   he will respond with some notification of its status.  I should
>   warn, though, that lots of people have tried to come up with a
>   better syntax for Scheme (including, blush, Matthias and I).  I've
>   never seen a success (ditto).

Sorry I didn't notice this sooner -- I just started a contract in 
Scheme-with-training-wheels (Java/XML) and so I've not been following 
the list that closely (sorry).

As far as I'm concerned, the indentational syntax works fine. 
I'm quite satisfied with it and have written a couple short things in it.

An example module for the main part of a file viewer application:

========================================================
; The next lines autorun this file through the IndentReader.scm
; The "eval-indented-file" skips the first eight lines on reading)
; Note that Scheme will then error out on the define with:
; "reference to undefined identifier: fail-at-end-of-loader-not-defined"
; that is expected. It would be nice to have a better termination
(load "IndentReader.scm")
(eval-indented-file "C:/pdfscheme/FileViewerIndented.scm" 8)
(fail-at-end-of-loader-not-defined)

; parse as indented Scheme v1.0
; reads all files in a directory and lets you view them

load "IndentWriter.scm"

define (directory-chooser)
 get-file "Pick a directory by choosing a file" #f #f #f #f null

define windowFrame (make-object frame% "File Viewer" #f 200 200) 
 
define (choice-callback widget event)
 load-file-contents (open-input-file (send widget get-string-selection) 'text)

define scheme-style-delta 
 send (make-object style-delta% 'change-family 'modern) set-delta 'change-smaller 3

define (load-file-contents file)
 send windowText insert (read-string 100000 file) 0 100000 #f
 send windowText change-style scheme-style-delta 0 100000
 
define (directoryButton-callback a b ) 
 let
  .
   choice (directory-chooser)
  if choice
   begin
    send directoryChoice append choice
    load-file-contents (open-input-file choice 'text)
  
define directoryButton 
 make-object button% "Choose file" windowFrame directoryButton-callback
                              
define (convertButton-callback a b ) 
 let
  .
   choice (send directoryChoice get-string-selection)
   string-port (open-output-string)
  if choice
   begin
    indent-print-file choice string-port
    load-file-contents (open-input-string (get-output-string string-port))
  
define convertButton 
 make-object button% "Show indented" windowFrame convertButton-callback
                              
define directoryChoice
 make-object choice% "File:" null windowFrame choice-callback null

send directoryChoice stretchable-width #t 

send windowFrame set-control-font (make-object font% 12 "Courier" 'modern 'normal 'normal #f)

define windowText (make-object text%) 

define windowCanvas (make-object editor-canvas% windowFrame)

; set up edit menu and font menu
define menu-bar (make-object menu-bar% windowFrame)
define menu-edit (make-object menu% "Edit" menu-bar)
append-editor-operation-menu-items menu-edit
define menu-font (make-object menu% "Font" menu-bar)
append-editor-font-menu-items menu-font

send windowCanvas set-editor windowText
send windowFrame show #t

=================================================================

What I discovered doing this (and it's obvious now with or without parentheses) 
is that Scheme/Lisp relies heavily on the physical structure of code
to denote meaning (as opposed to tagged fields). There are few reminders
in Scheme/Lisp of what the structure should be. PLT Scheme improves on
this with language level checks. Perhaps more could be done here
to make the coding process easier, to to somehow indicate these
patterns more strongly. That might be in a fancy editor with hints?

One of the reasons I like Smalltalk is the keyword syntax 
(required and thus used consistently, not just occasionally) 
serves  to remind what the arguments are opposed to mean. 
For example: 
  Display lineFrom: (10 @ 20) to: (20 @ 30).
Or:
  Display drawRectangleX1: 10 y1: 20 x2: 30 y2: 40.

-Paul Fernhout
Kurtz-Fernhout Software 
=========================================================
Developers of custom software and educational simulations
Creators of the Garden with Insight(TM) garden simulator
http://www.kurtz-fernhout.com