Example of Rust code

simendsjo simendsjo at gmail.com
Sat Aug 11 04:47:42 PDT 2012


On Sat, 11 Aug 2012 13:24:12 +0200, Marco Leise <Marco.Leise at gmx.de> wrote:

> Am Fri, 10 Aug 2012 15:56:53 +0200
> schrieb Timon Gehr <timon.gehr at gmx.ch>:
>
>> int eval(scope Expr* e){
>>      final switch(e.tag) with(Expr.Tag){
>>          case val:   return e.i;
>>          case plus:  return eval(e.a) + eval(e.b);
>>          case minus: return eval(e.a) - eval(e.b);
>>      }
>> }
>
> Can you quickly explain the use of scope here? Does that mean "I wont  
> keep a reference to e"?
> What are the implications? Does scope change the method signature? Does  
> the compiler enforce something? Will generated code differ? Does it  
> prevent bugs or is it documentation for the user of the function?
> Thanks in advance for some insight!
>

If I'm not mistaken, scope will enforce that the reference never escapes  
the function.
So you cannot pass it to other functions that might keep it's reference or  
store it in any way.


More information about the Digitalmars-d mailing list