Line-Oriented Scheme

Line-Oriented S-Code Input Filter

Preamble

This is an attempt to create an easier input format for Scheme. It works by defining two input modes that allow for much more readable and easily editted code. The modes are flow mode and line mode. Flow mode is merely the ordinary Scheme input format, with the possible exception of escaping into line mode. Line mode is a line-oriented entry modes for which the leading indent creates a hierarchy of lines as in Python, Haskell and the YAML file format. Indented lines are grouped together with the immediately preceding outdented line.

Line mode is the outermost mode for a file, and flow mode is used inside parentheses. Flow mode can also be entered by placing an opening curly brace ‘{’ as the last character on a line, ignoring any trailing whitespace or comments. Likewise line mode is entered using new levels of indentation by placing an opening square bracket ‘[’ at the end of a line. All bracketing characters nest as you would expect and return to the mode and the logical line from which they escaped immediately after the closing brace, bracket or parenthesis. Braces have no semantic significance in the underlying Scheme and exist merely a syntactic means to escape to flow mode from the line-oriented input mode without creating a new list; likewise for the brackets which re-enter line mode.

In line mode line endings and indents have syntactic significance. The use of an opening brace ‘{’ to enter a more general flow mode obviates the need for a line-extension character such as a backslash.

Exempli Gratia

;;just scheme stuff

define (product factors)
  call-with-current-continuation
    lambda (short-circuit-return)
      define (doproduct factor . factors) ;local factors
    	cond
          (= factor 0) ;may be short-circuited?
    	    short-circuit-return 0
    	  (null? factors) ;end of the line?
    	    values factor
    	  else ;recurse
    	    * factor (doproduct factors)
      doproduct (cons 1 factors)
;;just scheme stuff

(define (product factors)
  (call-with-current-continuation
    (lambda (short-circuit-return)
      (define (doproduct factor . factors) ;local factors
        (cond
          ((= factor 0) ;may be short-circuited?
            (short-circuit-return 0))
          ((null? factors) ;end of the line?
            (values factor))
          (else ;recurse
            (* factor (doproduct factors)))))
      (doproduct (cons 1 factors)))))