Heron-Centric: Ruminations of a Language Designer

A Brief Description of Cat

by Christopher Diggins

April 24, 2007



Summary

The Cat programming language version 0.11 has just been released. I thought I'd take a moment to talk a bit about what Cat is all about.


The Cat programming language has just released version 0.11.0 at Google code hosting. The interpreter is released under the MIT license (due to restrictions imposed by Google code hosting) while the source code for the interpreter is public domain C# code.

Cat as an Intermediate Language

My original motivation for designing Cat was as an intermediate programming language. I had studied the .NET Common Intermediate Language (CIL) and Java bytecode and I noticed a similarity between these languages and the functional programming language Joy . The big difference between Joy and most intermediate stack-based languages is the fact that instructions in Joy can all be pushed onto the stack as data. A trait also shared with the Postscript language.

More Compact/Expressive Code

define map_reduce { [map flatten self_join] dip map }

Improved Concurrency

define add_one_to_all_items { [1 +] map }

Type System

Cat as a Teaching Language

Allowing instructions to be pushed onto the stack as data and executed is very powerful. You can express very complex algorithms using very few commands. For example a simple version of the Google MapReduce algorithm in just one-line of Cat code:One advantage of functional languages, is that they make it much easier to express algorithms without specifying superflous sequential dependencies. In other words it is easier to run functional code concurrently. For example if I want to express the algorithm for adding one to each element in a list, the assembly code usually specifies a sequence which is not neccessary. Using higher-order functions we can express the algorithm more accurately as:The map instruction can be easily implemented to take advantage of multi-core or multi-processor machines.Joy lacks a type-system, so I designed the Cat language based on Joy but with type-checking in mind. This restricts some of the operations that are available, but improves the safety and verifiability of code. Admittedly the current Cat implementation lacks a type-checker but I have formally defined the Cat type system in a technical report . Having a type-system makes it possible for Cat code to be verified before execution thus improving security and enabling many optimizations. Types are also very useful as a form of documentation of stack effects, but are not mandatory since they can be inferred by the compiler.The other role I envision for the Cat language is as a language for teaching programming. I used as my inspiration the fact that many people first learned programming using RPL on Hewlett Packard calculators. Stack-based languages have very simple semantics and are very easy to teach. A popular teaching language for kids is Logo, so I've added a logo-style graphics library to Cat (see http://cat-language.googlecode.com/svn/trunk/cat/graphics.cat ).

You can see a screen-shot of the graphics engine in action at http://cat-language.com/screen.png

Talk Back!

Have an opinion? Be the first to post a comment about this weblog entry.

RSS Feed

If you'd like to be notified whenever Christopher Diggins adds a new entry to his weblog, subscribe to his RSS feed.

About the Blogger

Christopher Diggins is a software developer and freelance writer. Christopher loves programming, but is eternally frustrated by the shortcomings of modern programming languages. As would any reasonable person in his shoes, he decided to quit his day job to write his own ( www.heron-language.com ). Christopher is the co-author of the C++ Cookbook from O'Reilly. Christopher can be reached through his home page at www.cdiggins.com.

This weblog entry is Copyright © 2007 Christopher Diggins. All rights reserved.