Lambda the Ultimate

inactiveTopic Language Evaluations
started 2/27/2003; 4:39:57 AM - last post 3/9/2003; 6:24:52 AM
Carson Reynolds - Language Evaluations  blueArrow
2/27/2003; 4:39:57 AM (reads: 1377, responses: 2)
Programming language evaluation is an art in itself. In addition to traditional academic approaches, various websites provide different takes on language comparison. The Great Computer Language Shootout, for instance, allows comparisons of space, time, and lines of code on a variety of tasks. The Programming Community Index uses Google to estimate "world-wide availability of skilled engineers, courses and third party vendors." A somewhat similar approach but very different representation is used by Programming Languages: The Internet's Current Opinion. Not satisfied with a mere popularity contest, Programming Language Comparison provides a matrix of features of various popular languages.

Dan Shappir - Re: Language Evaluations  blueArrow
3/9/2003; 5:39:31 AM (reads: 890, responses: 1)
I'm not a believer in the concept of language evaluations as a means of resolving any type of serious PL debate. I do, however, find it interesting to compare the different ways distinct languages accomplish the same task. For example, I start thinking: "how would I do this using BeyondJS?" and often end up adding a feature or two to the library.

One of the benchmarks used in The Great Language Shootout is a Word Frequency calculator. I wrote the following implementation for it using the Windows Scripting Host and BeyondJS:

<job id="WordFrequency">
  <script language="JScript" src="beyond.js"/>
  <script language="JScript" src="beyondLazy.js"/>
  <script language="JScript" src="beyondStreams.js"/>
  <script language="JScript" src="beyondWindows.js"/>
  <script language="JScript">
    Object.toArray(
      File.StdIn.
        collect("toLowerCase").
        collect("split".asMethod("separator").curry([,/W+/])).
        spread().
        coalesce({}, function(freq, word) {
          freq[word] = freq[word] ? freq[word] + 1 : 1;
      })).
      inverse().
      order().
      reverse().
      feed(File.StdOut);
  </script>
</job>

A quick synopsis:

  1. The surrounding XML declares this as WSF (Windows Scripting File) and includes the relevant BeyondJS files.
  2. File.StdIn is a lazy list of lines read from the standard input. Lazy in this context means the lines are read on demand.
  3. The first collect() applies the toLowerCase() method to each element in the list.
  4. The second collect() breaks each line into an array of words using the string split() method with its argument bound to the RegExp /W+/
  5. spread() converts the list from a list of arrays to a longer list of elements (2D -> 1D).
  6. coalesce() uses a JavaScript object as map of words to frequency
  7. Object.toArray() converts the object/map into an array of key/value pairs
  8. inverse() switches the order of the elements in the array (key/value -> value/key)
  9. order() does introspective sorting of elements in an array
  10. reverse() reverses the array
  11. feed() pushes the elements into the File.StdOut stream
Use cscript.exe to run this file. Please note that this code relies on some features that are as yet unavialble in the online version of BeyondJS.

I like this implementation because:

  1. Lazy lists are used so resource usage is kept at a minimum (for obvious reasons nobody should expect this version to be as efficient as the C++ one ;-)
  2. The whole program is just 20 lines, 12 lines if you count only lines of code, and I have spaced it out so that there is no more than one instruction per line.
  3. The whole program is written as an expression, without declaring any variables (almost, there are the freq and word function arguments)
  4. It's a very straightforward implementation of exactly what needs to be done.

Is also quit obvious that this isn't JavaScript anymore. So BeyondJS appears to have graduated from being a JavaScript library to being a new PL implemented on top of JavaScript.

Ehud Lamm - Re: Language Evaluations  blueArrow
3/9/2003; 6:24:52 AM (reads: 924, responses: 0)
Great write up. We could use with a few more like it.