[plt-scheme] lisp sans parentheses

From: hendrik at topoi.pooq.com (hendrik at topoi.pooq.com)
Date: Sun Jul 30 09:50:00 EDT 2006

On Sun, Jul 30, 2006 at 10:06:44AM +0800, Srikumar Subramanian wrote:
> Hi all,
> 
> Off and on we hear complaints about lisp being "parentheses hell".
> Though I now believe that with enough familiarity, parenthetical
> expressions are very readable and elegant, we could pay more
> attention to those (potential stud programmers) who can't be
> bothered with lisp purely for syntactic reasons.
> 
> So .. I've written a syntax translator that some of you might be
> interested in, that converts expressions written in a whitespace
> dependent notation to the usual list-based expressions. Its rather
> minimal and the whole of scheme/lisp is accessible through
> this notation.
> 
> If you're interested, check this out -
> http://web.mac.com/srikumarks/programming
(actually 
http://web.mac.com/srikumarks/iWeb/Site/programming/programming.html
)
> 
> I've described the notation with examples, as well as linked to
> source code for the translator.
>
Interesting.

My notation for reducing parentheses (which I used successfully in a 
large project in the 80's) was to treat
  ( a c f / f r t / d f t / t y u)
as 
  ( a c f ( f r t ( d f t ( t y u))))

This eliminates enough parentheses to escape hell.
It cen be written vertically as

  ( a c f
  / f r t
  / d f t
  / t y u
  )
 
The reason this works is that parentheses in List tend to accumulate in 
close strings )))))) rather than open strings ((((((.

> hmmm .... it'll be nice to see the translator written in Scheme,
> but I just wrote it in C 'cause it was easier for me to brain dump.

Last year I notices that C++ can be written mostly without curly 
brackets -- at least, that a rather simple program can insert them
automatically (except for non-statement-like constructs like 
initializers)

Here's part of program I used to insert them, written in its notation.
I find it just a readable as the curly bracket version -- I usually use 
indentation as my main visual clue as to program structure anyway.  I no 
longer get misled by indentation that doesn't match the bracketing.

#include <stdio.h>
#include "readindentx.hh"

bool line_directives = true;
int outlineno = 0;

void nl(int count)
  printf("\n");
  int i = count;
  while(i > 1)
    printf("    ");
    --i;
  if(count > 0) printf("  ");
  ++outlineno;

void print(Line * line, int nest)

  if(line_directives && line->lineno != outlineno)
    if(line->lineno == outlineno + 1)
      printf("\n");
    else
      printf("\n#line %d", line->lineno);

    outlineno = line->lineno;
  if(line->contents && line->length != 0)
    nl(nest);
    printf("%s", line->contents);
    
  if(line->daughters != NULL)
    if(nest >= 0)
      nl(nest);
      if(nest > 0) printf("  ");
      printf("{");
    for(Line * d = line->daughters; d != NULL; d = d->sister)
      print(d, nest + 1);
    if(nest >= 0)
      nl(nest);
      if(nest > 0) printf("  ");
      printf("}");

void print(Line * line)
  print(line, -1);

int main()
  Line * l = readlines();
  print(l);
  nl(0);
  return 0;

-- hendrik


Posted on the users mailing list.