OT: Punctuation-starved Programming Languages
spc at conman.org
Wed Jun 21 22:54:34 CDT 2006
It was thus said that the Great John R. once stated:
> On 6/21/06, Sean Conner <spc at conman.org> wrote:
> > Well, in Forth, functions are called "words" and + is a word. So is (.
> >As is @. And !. As well as 0 , 1  and 2 . There are only a few
> >words (in ANS Forth) that require looking ahead and they're well known.
> >Most of the words in Forth pull parameters off the stack.
> > -spc (And one can always rename @ as fetch)
> I could imagine a Forth-like language that has no readahead words and
> no punctuation that could still be recognized as forthish.
> Particularly if you use tail recursion to replace loop nesting like
> Colorforth and 4IM do.
Well, having written my own Forth-like language the only hack I found I
needed was a way of recognizing a quote terminated string and dumping it
(the string) on the stack. So I didn't have to read ahead into the input
stream ... well ... not in the way that : does in Forth. I did something
"foo" define ( the code for foo here ... ) ;
(only, it looked more like:
"foo" :' ( the code for foo here ... ) ;
There's no need to read ahead for loops either and I supported while,
until and just about any other type of loop you care to do. Here's the code
I had for supporting higher level loops (and yes, I did support the Forth
word : in my language anyway):
// '(barf)' '(brat)' '(bra)' 'here' and '(resolve)' are the low level routines to
// implement branches of various types.
: c(barf) '(barf)' find drop compile ; // compile a branch if false
: c(brat) '(brat)' find drop compile ; // compile a branch if true
: c(bra) '(bra)' find drop compile ; // compile a branch
: (mark) here -1 compile ; // leave fixup addr on stack
: resolve here swap (resolve) ; // resolve foreare/back branch
( the always popular if else then clause ... )
: if c(barf) (mark) ;imm
: ifnot c(brat) (mark) ;imm
: else c(bra) (mark) swap resolve ;imm
: then resolve ;imm // because it's been like this
: endif resolve ;imm // because some might like this better
( some otherwise neato control flow words ... )
: begin here ;imm
: until c(barf) here - compile ;imm
: notuntil c(brat) here - compile ;imm
: while c(barf) (mark) ;imm
: whilenot c(brat) (mark) ;imm
: repeat c(bra) swap here - compile resolve ;imm
-spc (Even used this language for a class in college for a project)
More information about the cctalk