liberty-eiffel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: default or foo


From: Raphael Mack
Subject: Re: default or foo
Date: Sun, 03 Jul 2022 20:30:18 +0200
User-agent: Evolution 3.38.3-1

in principle I like the idea, but if you compare your proposal with the
implementations in other languages - e. g. "or" operator in python its
logic is inverted. You proposal requires the default in the first
operand and the normally (if not Void) taken one as second. Wouldn't it
be better to choose "instead" in this case.

Anyhow I would propose we get curtiss release out and discuss such new
features for dennis. Maybe someone can check in ISE whether there is a
similar thing or ask the community there what they think...

Best regards,
Rapha

Am Donnerstag, dem 30.06.2022 um 08:14 +0200 schrieb Paolo Redælli:
> I propose to add a feature to ANY.
> 
> infix "or" (another: like Current): like Current
> 
>      do
> 
>          if another=Void then
> 
>              Result:=Current
> 
>          else
> 
>              Result:=another
> 
>          end
> 
>      ensure Result/=Void
> 
>      end
> 
> 
> to allow writing things like
> 
>      print("a default answer" or something_that_can_be_void)
> 
> instead of
> 
>      local temp: STRING
> 
>      do
> 
>          temp := something_that_can_be_void
> 
>          if temp=Void then
> 
>              print("a default answer")
> 
>          else
> 
>              print(temp)
> 
>          end
> 
>      end
> 
> 
> Inspired by the coalescing operators. See 
> https://en.wikipedia.org/wiki/Null_coalescing_operator
> 
> Initially I thought of proposing to allow to write "foo or default"
> like 
> in many other languages but this would require to add to the language
> a 
> special case to avoid an exception for a Void call.
> 
> Using a pattern "default or foo" just avoid this.
> 
> I think it will help writing expressive yet concise code. Think of it
> as 
> an Eiffel-style coalescing operator.
> 
> An altertive naming would be to use a free operator but I couldn't
> find 
> one that I like.
> 
> 
> 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]