Lambda the Ultimate

inactiveTopic Generators and Abstraction
started 5/6/2002; 12:11:22 AM - last post 5/10/2002; 3:49:06 AM
Ehud Lamm - Generators and Abstraction  blueArrow
5/6/2002; 12:11:22 AM (reads: 2739, responses: 3)
Generators and Abstraction
(via Keith Devens)

If you are reading LtU, you obviously know that programming languages are first and foremost abstraction mechanisms. They provide us with ways to express our algorithmic intent.

If your software is built from useful abstractions, it is easier to replace a component with a plugin compatible - but different - component. This can help you improve efficiency, enhance relaiblity and so on, simply by replacing and evolving components, without the need to change the design of the application.

In this sense, abstractions simply express a behaves-like property. For example, in some software systems a web page abstaction behaves-like a file object.

This is mostly a software design issue (think coupling) - but the kinds of abstractons you can express depends on the features of the programming language. This short example shows how a list of strings and a generator can be plugin compatible. This allows the programmer to gain some of the advnatages of lazy evaluation.

Nothing very exciting here. Except perhaps that the support for important languages features in Python may lead to their adoption by more mainstream languages.

One more thing. Building abstractions is nice, but in order to build a working system you must also be concerned with the kinds of glue the language provides for connecting the various components. In fact, this glue ultimately controls what abstractions are going to be useful. Generators are obviously a kind of glue.


Posted to Python by Ehud Lamm on 5/6/02; 12:19:34 AM

Dan Shappir - Re: Generators and Abstraction  blueArrow
5/6/2002; 3:03:49 AM (reads: 1255, responses: 1)

Using generators as a means to parse files is one of the techniques introduced by the Beyond JavaScript library. In a file not yet included in the distribution we create a lazy collection of all the lines in a text file. As it's a lazy collection, the lines are only read as they are required. The following sample demonstrates reading a text file and retaining only the lines that contain a reference to JavaScript:

File.read("in.txt").filter(/JavaScript/i).feed(File.write("out.txt"));

File.read and File.write are implemented using the file system objects provided by the Windows Scripting Host. This means that they can be used in HTA files and standalone script files. This functionality can be easily extended to support the Java I/O functions provided to JavaScript by Rhino.

Ehud Lamm - Re: Generators and Abstraction  blueArrow
5/6/2002; 4:32:15 AM (reads: 1344, responses: 0)
I always found it ironic that this classic use of lazy evulation is so un-functional (it's about side effects after all).

Ehud Lamm - Re: Generators and Abstraction  blueArrow
5/10/2002; 3:49:06 AM (reads: 1137, responses: 0)
But can too much abstraction be a Bad Thing?

(In this case the answer is no. It is just a matter of getting used to new language features.)