In different Lisp it is possible to create a sequence of functions as if they were only normal values:
(def ops [+ - * /])
What can I repeat, again, as if they were just normal values:
(doseq [op ops] // (doseq (op ops) is like for (op <- ops) in scala (println (op 1 2 3 4)))
Now I tried several things in Scala, and all of them failed:
scala> List(+, -, *, /) <console>:1: error: illegal start of simple expression List(+, -, *, /) ^ scala> List[Double => Double](+, -, *, /) <console>:1: error: illegal start of simple expression List[Double => Double](+, -, *, /) ^ scala> List[Double => Double](+_, -_, *_, /_) <console>:8: error: not found: value * List[Double => Double](+_, -_, *_, /_) ^ <console>:8: error: not found: value / List[Double => Double](+_, -_, *_, /_) ^
So, what is the correct procedure for defining a list of functions / operators in Scala?
source share