Rich kids are into COBOL
Peter Corlett
abuse at cabal.org.uk
Sat Feb 28 05:35:06 CST 2015
On Fri, Feb 27, 2015 at 04:48:07PM -0800, Chuck Guzis wrote:
[...]
> APL certainly encouraged thinking about things in a different way. I wonder
> what today would look like if APL was used as a "first language" to teach
> programming.
It's a special-purpose language for mathematical manipulation. As such, it's
not actually a very good choice for a first language.
When I was a wee nipper, everybody's first language was BASIC because that's
what came with the machine. These days, it's more likely to be Java or perhaps
Python. Python's the better of the two and supports similar manipulations to
APL. For example, Python forms of the examples in
https://en.wikipedia.org/wiki/APL_%28programming_language%29#Design are:
>>> n = [4, 5, 6, 7]
>>> n
[4, 5, 6, 7]
>>> map(lambda x: x+4, n)
[8, 9, 10, 11]
>>> sum(n)
22
>>> m = sum([i + 3 for i in range(1,5)]); m
22
And in Scala, which runs on the JVM and thus interoperates with Java:
scala> val n = Vector(4, 5, 6, 7)
n: scala.collection.immutable.Vector[Int] = Vector(4, 5, 6, 7)
scala> n
res0: scala.collection.immutable.Vector[Int] = Vector(4, 5, 6, 7)
scala> n map (_+3)
res1: scala.collection.immutable.Vector[Int] = Vector(7, 8, 9, 10)
scala> n.sum
res2: Int = 22
scala> val m = 1 to 4 map (_ + 3) sum; m
warning: there was one feature warning; re-run with -feature for details
m: Int = 22
res3: Int = 22
The "feature warning" is that I used postfix "sum", which is an ambiguous parse
in some cases. It wants me to write it as the uglier (1 to 4).map(_ + 3).sum
Functional programming idioms have crept into many OO and imperative languages
to give them APL-like power. APL's cryptic syntax is not a feature; if you want
that, you know where to find Perl or Clojure.
More information about the cctalk
mailing list