Re: Is the dangling else a syntax bug?

"Mike Dimmick" <mike@dimmick.demon.co.uk>
30 Jul 2001 01:18:44 -0400

          From comp.compilers

Related articles
[14 earlier articles]
Re: Is the dangling else a syntax bug? esmond.pitt@bigpond.com (Esmond Pitt) (2001-07-18)
Re: Is the dangling else a syntax bug? jcrens@earthlink.net (Jack Crenshaw) (2001-07-23)
Re: Is the dangling else a syntax bug? marcov@toad.stack.nl (2001-07-23)
Re: Is the dangling else a syntax bug? joachim_d@gmx.de (Joachim Durchholz) (2001-07-23)
Re: Is the dangling else a syntax bug? vbdis@aol.com (2001-07-27)
Re: Is the dangling else a syntax bug? wb@vestein.arb-phys.uni-dortmund.de (2001-07-30)
Re: Is the dangling else a syntax bug? mike@dimmick.demon.co.uk (Mike Dimmick) (2001-07-30)
Re: Is the dangling else a syntax bug? wclodius@aol.com (2001-07-30)
Re: Is the dangling else a syntax bug? joachim_d@gmx.de (Joachim Durchholz) (2001-07-30)
Re: Is the dangling else a syntax bug? marcov@toad.stack.nl (2001-08-02)
Re: Is the dangling else a syntax bug? vbdis@aol.com (2001-08-02)
Re: Is the dangling else a syntax bug? stephen_bevan@yahoo.com (2001-08-06)
| List of all articles for this month |
From: "Mike Dimmick" <mike@dimmick.demon.co.uk>
Newsgroups: comp.compilers
Date: 30 Jul 2001 01:18:44 -0400
Organization: Compilers Central
References: 01-07-133 01-07-153
Keywords: syntax, design
Posted-Date: 30 Jul 2001 01:18:44 EDT

"VBDis" <vbdis@aol.com> wrote in message news:01-07-153@comp.compilers...
> "Joachim Durchholz" <joachim_d@gmx.de> schreibt:
>
> >An interesting variation of this is the use of unindentation as "end"
> >marker. This has been done e.g. in Python and Haskell.
>
> Did you ever see source code with a mix of tab and space characters?
> Such text becomes unreadable to both a human and a compiler, when the
> tab size is changed to some user defined value. The whole source code
> then is bound to a specific editor :-(


The Miranda functional programming system uses what is termed the 'offside
rule' (actually, I can't remember the term, but it was something like that)
which determined whether a line of source was a continuation of the above
expression, or the beginning of a new expression.


My notes (from Programming Language Concepts and Paradigms course) read:


"Layout is syntactically significant in Miranda. An equation right-part
(the part _after_ '=') is terminated by (and only by) a symbol that _begins
to the left_ of the right-part's first nonblank character. In Miranda
terminology, the terminating symbol is said to be _offside_."


CORRECT WRONG


fare age = 40, if age < 16 fare age = 40, if age < 16
                  = 80, otherwise = 80, otherwise


fib n = fib (n - 1) + fib n = fib (n - 1) +
                fib (n - 2) fib (n - 2)


This matters because of 'where' clauses - this function calculates the
distance between two points, given in (x,y) pairs:


distance (x1, y1) (x2, y2)
        = sqrt (sqr xgap + sqr ygap)
              where
              xgap = x1 - x2
              ygap = y1 - y2


If the offset is incorrect for the line beginning 'ygap' it will be
considered a global function, not a calculation subordinate to 'distance'.


These rules are much the same for Haskell (another functional programming
system). I don't have experience with Python, but I know that indentation
is also significant in the Occam language to mark subordinate code.


I seem to recall that the interpreted tab size could be changed in Miranda
(which doesn't have a built-in editor) by setting some environment variable.
The nearly-compatible Amanda (which is free) has a built-in editor.


> But perhaps I misunderstood your point. When the editor inserts the
> appropriate End keyword whenever a line is outdented, then everything
> is okay. But then it's a feature of the editor, not of the language.


True. But as I've said, some languages do use indentation alone to indicate
grouping and subordination.


--
Mike Dimmick


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.