if-expressions
Bent Rasmussen
incredibleshrinkingsphere at gmail.com
Mon May 28 05:47:30 PDT 2007
"David B. Held" <dheld at codelogicconsulting.com> wrote in message
news:f3e2fn$2h7$1 at digitalmars.com...
>
> The advantage of having a statement-form of 'if' is that it creates a
> scope (expressions never create a scope). Also, if allows you declare a
> variable in the condition, which is also not possible in expressions. See
> if your other languages can do that. ;)
You mean something like this? :-)
public static function mapPartial<S,T>(f: S -> Option<T>, s: Stream<S>):
Stream<T>
{
return if (empty(s))
znone
else {
var e = f(hd(s));
if (Options.empty(e))
mapPartial(f,tl(s))
else
some(Options.get(e),callback(mapPartial,f,tl(s)));
}
}
No variable in the condition though.
But thinking about it some more, this would be a very disruptive change for
existing D programs, so it would be better to just try and use ?:.
R.
Bent
More information about the Digitalmars-d
mailing list