The Artima Developer Community
Sponsored Link

Weblogs Forum
Cat: Namespaces and Type Annotations

2 replies on 1 page. Most recent reply: Jul 18, 2006 7:30 AM by Christopher Diggins

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Christopher Diggins

Posts: 1215
Nickname: cdiggins
Registered: Feb, 2004

Cat: Namespaces and Type Annotations (View in Weblogs)
Posted: Jul 16, 2006 11:00 PM
Reply to this message Reply
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
}


Tim LS

Posts: 37
Nickname: parchandri
Registered: Jul, 2005

Re: Cat: Namespaces and Type Annotations Posted: Jul 17, 2006 6:16 PM
Reply to this message Reply
I am curious about why Clear is annotated as (any*) ~> (), and not (any*) -> ().

Christopher Diggins

Posts: 1215
Nickname: cdiggins
Registered: Feb, 2004

Re: Cat: Namespaces and Type Annotations Posted: Jul 18, 2006 7:30 AM
Reply to this message Reply
> I am curious about why Clear is annotated as (any*) ~> (),
> and not (any*) -> ().

My reasoning is because it consumes a variable number of stack elements. If it called as part of a conditional, it would leave the stack in an unstable state.

Maybe this is not the right thing to do?

Flat View: This topic has 2 replies on 1 page
Topic: Cat: Namespaces and Type Annotations Previous Topic   Next Topic Topic: Macros and Domain Specific Languages

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use