Reputation: 645
Is there in Scala some language construction like lisp's progn
?
Thanks!
Upvotes: 0
Views: 210
Reputation: 62835
Yep, curly braces.
progn evaluates forms, in the order in which they are given.
The values of each form but the last are discarded.
Examples:
(progn) => NIL
(progn 1 2 3) => 3
(progn (values 1 2 3)) => 1, 2, 3
(setq a 1) => 1
(if a
(progn (setq a nil) 'here)
(progn (setq a t) 'there)) => HERE
a => NIL
Now the same, but in scala:
scala> {}
// Unit is not written explicitly, but it is here
scala> {1; 2; 3}
// warnings omitted
// res1: Int = 3
scala> {(1, 2, 3)}
// res2: (Int, Int, Int) = (1,2,3)
// no direct analog for setq, skipping other examples
And to ensure you that evaluates forms, in the order in which they are given:
scala> {println('1'); println('2'); println('3')}
1
2
3
Upvotes: 5