[nem-bug] [Nemerle 0000188]: try-in-unless syntax

feedback at nemerle.org feedback at nemerle.org
Tue Nov 22 12:19:46 CET 2005


The following issue has been CONFIRMED.
======================================================================
<http://nemerle.org/bugs/view.php?id=188> 
======================================================================
Reported By:                malekith
Assigned To:                
======================================================================
Project:                    Nemerle
Issue ID:                   188
Category:                   Language Feature
Reproducibility:            always
Severity:                   feature
Priority:                   low
Status:                     confirmed
======================================================================
Date Submitted:             07-06-2004 09:49 CEST
Last Modified:              11-22-2005 12:19 CET
======================================================================
Summary:                    try-in-unless syntax
Description: 
http://research.microsoft.com/~akenn/sml/ExceptionalSyntax.pdf

This paper introduces something like this to SML:

let val f = open_file ()
in read_file (f)
unless Io => ...

which is different from:

try {
  def f = open_file ();
  read_file (f)
} catch {
 _ : Io => ...
}

because read_file(f) is *not* covered by the try block (in the first
case).

I guess this could make exception handling cleaner in some cases, but the
syntax needs to be invented. Something along the lines of:

try {
  def f = open_file ();
} catch {
  | nothing => ...
  | _ : Io =>  ...
}

or something different ;-)
======================================================================

----------------------------------------------------------------------
 olszta - 08-29-04 22:36 
----------------------------------------------------------------------
Here goes my proposal for the syntax and semantics of the def/unless.

The following code:

  {
    [def|mutable] $val = $expr
    unless {
      | $catch_clause_0 => $catch_effect_0
      | $catch_clause_1 => $catch_effect_1
        ...
      | $catch_clause_n => $catch_effect_n
    };
    $body
  }

should be transformed to:
  
  {
    def $fresh_name =
      try { (Some ($expr), -1) }
      catch {
        | $catch_clause_0 => (None (), 0)
        | $catch_clause_1 => (None (), 1)
          ...
        | $catch_clause_n => (None (), n)
      };

    match ($fresh_name) {
      | (Some ($fresh_name), _) =>
        [def|mutable] $val = $fresh_name;
        $body

      | (_, 0) => $catch_effect_0
      | (_, 1) => $catch_effect_1
        ...
      | (_, n) => $catch_effect_n
    }        
  }

This will probably have to be done on the parser level and should be
pretty straightforward to implement. An optimization could be introduced
for the case when n = 1 -- we don't have to create the tuple in such a
situation.

After a thought, this isn't probably the most efficient way to compile
def/unless (we could avoid the tuple and option
construction/deconstruction by introducing two mutables), but this way it
looks more functional.

----------------------------------------------------------------------
 olszta - 08-30-04 10:43 
----------------------------------------------------------------------
Failed to implement this on parser-side, will either wait for the new
syntax extensions or add it to ParseTree and resolve it in typing phase. I
opt to wait.

Issue History
Date Modified  Username       Field                    Change              
======================================================================
07-06-04 09:49 malekith       New Issue                                    
08-29-04 22:36 olszta         Note Added: 0000276                          
08-30-04 10:43 olszta         Note Added: 0000279                          
08-30-04 18:07 olszta         Assigned To               => olszta          
08-30-04 18:07 olszta         Status                   new => confirmed    
08-30-04 18:08 olszta         Status                   confirmed => assigned
11-22-05 12:19 malekith       Assigned To              olszta =>           
11-22-05 12:19 malekith       Status                   assigned => confirmed
11-22-05 12:19 malekith       Category                 The Language => Language
Feature
11-22-05 12:19 malekith       Description Updated                          
======================================================================




More information about the bugs mailing list