The Artima Developer Community
Sponsored Link

Heron-Centric: Ruminations of a Language Designer
Cat: Namespaces and Type Annotations
by Christopher Diggins
July 17, 2006
Summary
The next version of the Cat programming language, contains namespaces and type annotations.

Advertisement

The upcoming version of Cat, which is still undergoing testing, implements type annotations and namespaces.

The type annotation of Cat is based on the idea that every program, or subprogram, is a transition from one stack to another. For example the following is the type annotation for several of the atomic programs of Cat (the primitives if you prefer):

  + : (int int) -> (int)
  - : (int int) -> (int)
  and : (bool bool) -> (bool)
  > : (int int) -> (bool)
  pop : (any) -> ()
  dup : (any) -> (any any)
Some programs have side-effects, and these are annotated differently:
  rnd : () ~> (int)
  write : (any) ~> (any)  
A program which has no side-effects, is called a function, whereas a program with side-effects is called a subroutine.

Cat now also supports scopes. A namespace is just a named scope. This addition makes it much easier to write non-trivial software using Cat.

Here is what some sample programs look like in the upcoming Cat:

define clear : (any*) ~> ()
{
  [pop] [is_stack_empty not] while
}

define simple_test : () -> (int)
{
  0 1 +
}

define nested_test : () -> (int)
{
  define f : () -> (int)
  {
    1
  }

  define plus_one : (int) -> (int)
  {
    1 +
  }

  f plus_one
}

namespace X
{
  define f : (int) -> (int)
  {
    2 +
  }
}

namespace Y
{
  define f : (int) -> (int)
  {
    3 +
  }
}

define main : () ~> ()
{
  "expect 1" write simple_test write clear
  "expect 2" write nested_test write clear
  "expect 3" write 1 X.f write clear
  "expect 4" write 1 Y.f write clear
}

Talk Back!

Have an opinion? Readers have already posted 2 comments about this weblog entry. Why not add yours?

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 © 2006 Christopher Diggins. All rights reserved.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us