Adding another Stack to Cat
Christopher Diggins — 2006-07-04 21:48:05
I'm planning on adding a second stack to the stack-based programming
language Cat so that it can be more directly translated to other languages
(like the MSIL). As a result I'm having to invent a syntax for
type-annotation of a multi-stack language, because later versions of Cat
will support type annotations. I've posted about it at
http://www.artima.com/weblogs/viewpost.jsp?thread=167276 .
I'd appreciate any comments or insights.
Thanks,
Christopher Diggins
http://www.cdiggins.com/cat/
[Non-text portions of this message have been removed]
William Tanksley, Jr — 2006-07-09 22:28:17
Christopher Diggins <
cdiggins@...> wrote:
> I'm planning on adding a second stack to the stack-based programming
> language Cat so that it can be more directly translated to other languages
> (like the MSIL). As a result I'm having to invent a syntax for
> type-annotation of a multi-stack language, because later versions of Cat
> will support type annotations. I've posted about it at
> http://www.artima.com/weblogs/viewpost.jsp?thread=167276 .
Looks fine, if a bit complex to write by hand. I can tell you're
imitating existing languages that do the same thing, so I have to
suspect that there's good reason for their complexity.
Out of curiosity, can the second stack also function as a return
stack, like in Forth? If so, your typechecking could be extremely
powerful -- you could typecheck control constructs.
> Christopher Diggins
-Billy
Christopher Diggins — 2006-07-10 15:33:43
> Out of curiosity, can the second stack also function as a return
> stack, like in Forth? If so, your typechecking could be extremely
> powerful -- you could typecheck control constructs.
Would you mind explaining futher? I don't follow completely.
Currently there are no control constructs in Cat.
An atomic program in Cat like "if" can be expressed as having the following
type:
def if : (bool program program) ~> (any*) { ... }
[Non-text portions of this message have been removed]
sa@dfa.com — 2006-07-10 16:36:33
do you get any practical mileage out of not requiring
that the two horns of the conditional have identical
types?
concatenative@yahoogroups.com wrote on 07/10/2006 11:33:43 AM:
> > Out of curiosity, can the second stack also function as a return
> > stack, like in Forth? If so, your typechecking could be extremely
> > powerful -- you could typecheck control constructs.
>
> Would you mind explaining futher? I don't follow completely.
> Currently there are no control constructs in Cat.
>
> An atomic program in Cat like "if" can be expressed as having the
following
> type:
>
> def if : (bool program program) ~> (any*) { ... }
>
>
> [Non-text portions of this message have been removed]
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
William Tanksley, Jr — 2006-07-11 19:06:29
Christopher Diggins <
cdiggins@...> wrote:
> > Out of curiosity, can the second stack also function as a return
> > stack, like in Forth? If so, your typechecking could be extremely
> > powerful -- you could typecheck control constructs.
> Would you mind explaining futher? I don't follow completely.
> Currently there are no control constructs in Cat.
Odd. How do you control program flow, then? I know it's possible to do
using list manipulation and 'i', but most languages prefer to use more
practical and safe methods.
A return stack is the location where you put return addresses when you
perform a non-tail-recursive call. Being able to manipulate the return
stack allows you to do extremely devious things to program execution,
like backtracking; being able to typecheck the return stack would mean
that you could actually do those devious things safely.
Forth has two stacks: a data stack (like Joy's stack); and a return
stack, which can also be used to temporarily store data (like Joy's
'dip' operator, which is itself in a sense also an implementation of a
stack).
-Billy