Is there in Scala some language construction like lisp's progn
?
Thanks!
Asked
Active
Viewed 201 times
0

The Architect
- 665
- 9
- 22
-
3Please add pseudo scala code with such `progn` you want to evaluate and the result of evaluation. Note that in scala `{a; b; c}` returns result of `c`. – senia Jan 14 '14 at 12:56
-
1Or describe what `progn` does with natural language. – ziggystar Jan 14 '14 at 13:15
1 Answers
5
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

om-nom-nom
- 62,329
- 13
- 183
- 228
-
-
I doubt there is built in mechanisms for both. For PROG1 there is an analog (in some sense) -- [function commonly called `tap` (aka kestrel combinator)](http://stackoverflow.com/q/16742060/298389) – om-nom-nom Jan 14 '14 at 18:29
-
1
-
@ghik yeah, but I don't think it is really needed, ordinary scala possibilities will do the job – om-nom-nom Jan 14 '14 at 21:10