logo       

Re: WHEN and UNLESS, if you will (was: [ANN] Introducing Scala, step 1): msg#00489

lang.scala

Subject: Re: WHEN and UNLESS, if you will (was: [ANN] Introducing Scala, step 1)

"Steven E. Harris" <seh@xxxxxxxxx> writes:
> From the comments,
>
> ,----
> | note that 'if' returns a value
> `----
>
> Has there been any discussion about augmenting "if" with its friends
> "when" and "unless"¹, as provided in Common Lisp? There,
>
> (when test-form consequent)
>

These only really seems to pay off if you have multiple statements in
the consequent. In Lisp, it is nice to write things like:

(when test
statement1
statement2)

If you wrote it with an if, it would be significantly longer:

(if test
(begin
statement1
statement2))


Scala just writes {} instead of (begin ), so the saving is not worth
it.


Incidentally, there is something analogous in Scala: cases in a
pattern match do not need to have braces around them multiple
statements.


case Foo =>
statement1
statement2
statement3

case Bar =>
statement4
statement5



-Lex




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise