Version 0 of Looking at LISP's SERIES extension

Updated 2006-05-09 09:02:21 by AM

Arjen Markus Inspired by a message from Andreas Kupries, regarding a macro package available for Common LISP, I wrote the script below. But let's start with the description of SERIES:

The original package http://lambda-the-ultimate.org/node/1451

The benefits of programming in a functional style are well known. In particular, algorithms that are expressed as compositions of functions operating on series/vectors/streams of data elements are much easier to understand and modify than equivalent algorithms expressed as loops. Unfortunately, many programmers hesitate to use series expressions. In part, this is due to the fact that series expressions are typically implemented very inefficiently.

A Common Lisp macro package (called Series) has been implemented that can evaluate a wide class of series expressions very efficiently by transforming them into iterative loops. When using this class of series expressions, programmers can obtain the advantages of expressing computations as series expressions without incurring any run-time overhead.

http://series.sourceforge.net/

My translation into Tcl

Reading the documentation on SERIES, I started off with what they call scanners. The script below presents Tcl procedures that create a "series". For the sake of this page: a series is a procedure that returns the next value in an (in principle) endless series of values.

Currently they have two subcommands:

  • next: return the next value
  • restart: start from the beginning

I have implemented two kinds:

  • simple arithmetic progressions, like 1, 3, 5, 7, 9, 11, ... or 1, 3, 5, 1, 3, 5, ...
  • function-based series, like the Fibonaci series

This is a first attempt only - ideas are welcome.