🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #5453

Block Closure (was Re: FOR loops)

#5453
From: Tony Stuart
Date: Fri, 15 Apr 1988 19:08
90 lines
3473 bytes
In article <2400014@otter.hple.hp.com>, esh@otter.hple.hp.com (Sean Hayes) writes:
> The closing of blocks of code with a delimiter is a must. The only viable alternative is 
> Landins "offside rule", which forces the correct indentation. I don't know if this has been
> tried in an imperative language.

In Max, an extensible programming language, functions are used
to define new flow-of-control constructs. The argument list to the
function constitutes a block. The block may be delimited by three
different sets of symbols to support different degrees of block
closure.

Simple block closure uses parentheses to delimit the argument list
or block. They pair just as they do in conventional programming
languages such as C. An if-then-else construct could be written
as:

    if (boolean-expression
        then (
            true-function-list
        )
        else (
            false-function-list
        )
    )

A disadvantage to this type of closure in a language such as Max
is that it becomes difficult for the interpreter (or programmer)
to accurately identify the location of a missing parenthesis.

To accomodate this problem, Max provides "single named block
closure" which uses braces to delimit the argument list. The
right brace is followed by the function name that precedes
the corresponding left brace. The above example can be
rewritten as:

    if {boolean-expression
        then (
            true-function-list
        )
        else (
            false-function-list
        )
    } if

In this example, the "if" block uses single named block
closure and the "then" and "else" blocks use simple block
closure. The type of closure used is entirely up to the
programmer. The Max interpreter can detect block structure
errors (i.e. missing parentheses) within named blocks delimited
by braces. There is a tradeoff between the improved ability
to detect errors using single named block closure and the
readability of simple block closure.

Max also provides a shortcut to writing all of the right
parentheses or right braces. It is called "multiple named
block closure" and is specified using brackets:

    function-name [ function-list ] function-name

A right-bracket, function-name sequence pairs with the most
recent function-name, left-bracket sequence of the same name
and closes all intervening blocks. An example of this is:

    if [boolean-expression
        then (
            true-function-list
    ] if

The "then" block is closed by the multiple named block closure
of the "if" block.

Max provides a preprocessor to hide these details from the
programmer and make the source more readable. A set of
preprocessor replacements such as:

    $replace ("If"     "if [")
    $replace ("EndIf"  "] if")
    $replace ("Then"   "then (")

Allows one to write the more elegant:

    If boolean-expression
        Then
            true-function-list
    EndIf

-- 

        Anthony F. Stuart, {uunet|sundc)!rlgvax!tony
        CCI, 11490 Commerce Park Drive, Reston, VA 22091
Technical Details
Message-ID: <918@rlgvax.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!rlgvax!tony
References: <2853@enea.se> <2400014@otter.hple.hp.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!rlgvax!tony
From: tony@rlgvax.UUCP (Tony Stuart)
Newsgroups: comp.lang.misc
Subject: Block Closure (was Re: FOR loops)
Message-ID: <918@rlgvax.UUCP>
Date: 15 Apr 88 19:08:54 GMT
References: <2853@enea.se> <2400014@otter.hple.hp.com>
Organization: Computer Consoles Inc, Reston VA
Lines: 90
Summary: named blocks,multiple block closure,max