Skip to content

Commit

Permalink
Fix: a couple of demos;
Browse files Browse the repository at this point in the history
  • Loading branch information
daokoder committed Oct 10, 2016
1 parent 122b2d0 commit a28017b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
20 changes: 7 additions & 13 deletions demo/errors.dao
Expand Up @@ -63,24 +63,18 @@ Test2()
# if the "block" raises an exception, the default "value" is returned
# instead, and the exception is suppressed.

fout = io::stdio
ls = { "A", "B", "C" }
it = "X";

std.exec {
defer ( any ) { return none }
fout = io.open( "NonExistentFile.txt", "r+" )
defer ( any ) { return "X" }
it = ls[3] # Index out of range;
}

if( fout != io::stdio ) defer{ fout.close() }

fout.writeln( "hello" )
io.writeln( it )


# A simpler way to write the above codes:
fout = std.exec( io::stdio ){ io.open( "NonExistentFile.txt", "r+" ) }

# Or using the assertion operator ??:
# fout = io.open( "NonExistentFile.txt", "r+" ) ?? io::stdio

if( fout != io::stdio ) defer{ fout.close() }
it = std.exec( "X" ){ ls[3] }

fout.writeln( "hello" )
io.writeln( it )
12 changes: 6 additions & 6 deletions demo/interface.dao
Expand Up @@ -2,11 +2,11 @@
interface AA
{
routine Meth( a = 0 );
routine[]( index: int )=>int;
routine.name()=>string;
routine []( index: int )=>int;
routine .name()=>string;

routine for( iter: tuple<bool,int> );
routine[]( iter: tuple<bool,int> )=>int;
routine []( iter: tuple<bool,int> )=>int;
}
routine Test( o: AA )
{
Expand All @@ -20,14 +20,14 @@ routine Test( o: AA )
class BB
{
routine Meth( a = 0 ){ io.writeln( a ) }
routine[]( index: int ){ return index }
routine.name(){ return "BB" }
routine []( index: int ){ return index }
routine .name(){ return "BB" }

routine for( iter: tuple<bool,int> ){
iter[0] = true;
iter[1] = 0;
}
routine[]( iter: tuple<bool,int> ){
routine []( iter: tuple<bool,int> ){
id = iter[1];
iter[0] = iter[1] + 1 < 5;
iter[1] += 1;
Expand Down

0 comments on commit a28017b

Please sign in to comment.