0

Is there in Scala some language construction like lisp's progn?
Thanks!

The Architect
  • 665
  • 9
  • 22
  • 3
    Please 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
  • 1
    Or describe what `progn` does with natural language. – ziggystar Jan 14 '14 at 13:15

1 Answers1

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