## Re: [langsmiths] Powerpoint Slides for Cat Presentation at Lang. NET 2006

Expand Messages
• Thank you very much for generating the PDF for us.
Message 1 of 11 , Aug 1, 2006
Thank you very much for generating the PDF for us.

On 7/31/06, Steve Dekorte <steve@...> wrote:

On 31 Jul 2006, at 08:57 am, John Nowak wrote:
> On Jul 31, 2006, at 10:30 AM, Christopher Diggins wrote:
>
>> I'm presenting Cat at Lang .NET 2006 ( http://
>> www.langnetsymposiu m.com
>> ). The powerpoint slides describe the most recent version of the Cat
>> language and are online at
>> http://www.cdiggins.com/cat/cat_lang_net.ppt
>>
>> The focus of the presentation is on using Cat as an intermediate
>> language for performing functional optimizations.
>
> Can you export these is a version that does not require powerpoint?
> We don't all own office. :-)

Here's a PDF export of it:

• Q: What does the quadratic formula look like in Cat? takes: a b c leaves: (b+sqrt(b*b-4*a*c))/2*a (b-sqrt(b*b-4*a*c))/2*a In Joy it looks pretty bad.
Message 2 of 11 , Aug 1, 2006
Q: What does the quadratic formula look like in Cat?

takes: a b c leaves: (b+sqrt(b*b-4*a*c))/2*a (b-sqrt(b*b-4*a*c))/2*a

In Joy it looks pretty bad.
• ... oops, should be: takes: a b c leaves: (-b+sqrt(b*b-4*a*c))/2*a (-b-sqrt (b*b-4*a*c))/2*a
Message 3 of 11 , Aug 1, 2006
On Aug 1, 2006, at 10:02 AM, James McCartney wrote:

>
> Q: What does the quadratic formula look like in Cat?
>
> takes: a b c leaves: (b+sqrt(b*b-4*a*c))/2*a (b-sqrt
> (b*b-4*a*c))/2*a

oops, should be:

takes: a b c leaves: (-b+sqrt(b*b-4*a*c))/2*a (-b-sqrt
(b*b-4*a*c))/2*a

>
>
> In Joy it looks pretty bad.
>
>
• Hi Steve, Cat offers a few useful features above and beond Joy, specifically nested function definitions, and a local stack for storing variables. Store adds a
Message 4 of 11 , Aug 1, 2006
Hi Steve,

Cat offers a few useful features above and beond Joy, specifically
nested function definitions, and a local stack for storing variables.

This is what it will look like in the next version of Cat ( when it is

define quad : (a:float b:float c:float)
{
store_float
store_float
store_float
define a : { load#2 }
define b : { load#1 }
define c : { load#0 }
define d : { b b * 4 a * c * - sqrt }
b neg d + 2 / a *
b neg d - 2 / a *
}

This can be converted to use only dip like Joy would do, but as you
point out it is rather unpleasant.

On 8/1/06, James McCartney <asynth@...> wrote:
> On Aug 1, 2006, at 10:02 AM, James McCartney wrote:
>
> >
> > Q: What does the quadratic formula look like in Cat?
> >
> takes: a b c leaves: (-b+sqrt(b*b-4*a*c))/2*a (-b-sqrt
> (b*b-4*a*c))/2*a
• On Aug 1, 2006, at 7:40 PM, Christopher Diggins wrote: define quad : (a:float b:float c:float) { store_float store_float store_float define a : { load#2 }
Message 5 of 11 , Aug 1, 2006
On Aug 1, 2006, at 7:40 PM, Christopher Diggins wrote:
define quad : (a:float b:float c:float)
{
store_float
store_float
store_float
define a : { load#2 }
define b : { load#1 }
define c : { load#0 }
define d : { b b * 4 a * c * - sqrt }
b neg d + 2 / a *
b neg d - 2 / a *
}

actually I made another error in posting the formula, so this should
really be:

b neg d + 2 a * /
b neg d - 2 a * /

thanks.

Since you are already declaring a b c in the type signature, why
doesn't the compiler handle storing them on the aux stack and
defining locals for you?
i.e. why not just:

define quad : (a:float b:float c:float)
{
define d : { b b * 4 a * c * - sqrt }
b neg d + 2 a * /
b neg d - 2 a * /
}

If you have local definitions, or any lexical environment, then code
can no longer strictly concatenative according to Manfred von Thun's
definition due to the problems of concatenation of fragments
belonging to different lexical environments. Is that why you
distinguish between square bracketed and curly braced code fragments?
• ... what does this code (assuming I ve written it correctly) do in Cat? define foo : () - ((int)- (int)) { define x : { 3 } [x +] } define bar : () - (int) {
Message 6 of 11 , Aug 2, 2006

On Aug 1, 2006, at 10:15 PM, James McCartney wrote:

If you have local definitions, or any lexical environment, then code

can no longer strictly concatenative according to Manfred von Thun's

definition due to the problems of concatenation of fragments

belonging to different lexical environments.

what does this code (assuming I've written it correctly) do in Cat?

define foo : () -> ((int)->(int))
{
define x : { 3 }
[x +]
}

define bar : () -> (int)
{
define x : { 10 }
[x] foo cat_fxn i  // returns what?
}

the result of cat_fxn should be [x x +] , but the two x's are from different lexical scopes.

..or this (but I'm not sure if/how your store/load scheme handles nested lexical scopes?) :

define foo : (int) -> ((int)->(int))
{
store_int
define x : { load#0 }
[x +]
}

define bar : (int) -> (int)
{
store_int
define x : { load#0 }
[x] 3 foo cat_fxn i
}

10 bar // returns what?

• I forgot something important, 3 pop_locals from the top. Unfortunately, I don t see the problem that lexical enivornments introduce in Cat. Every function can
Message 7 of 11 , Aug 2, 2006
I forgot something important, 3 pop_locals from the top.
Unfortunately, I don't see the problem that lexical enivornments
introduce in Cat. Every function can just be replaced with its
definition (and recursive patterns can be rewritten using
combinators).

Curly braces mark lexical scoping, while square blocks delimit lambda
expressions (anonymous functions / quotations / etc.)

The reason for not inferring the movement from main stack to auxiliary
stack, is that Cat is more flexible. I did a lot of superfluous stack
shuffling, just to simplify the problem. But if someone (e.g. a
program generating Cat code) doesn't want to use the auxiliary stack,
they don't have to.

Consider the following:

define f : (a:int b:int) { swap }

Here, there is no reason to declare local variables, etc.

However, maybe it is possible for the compiler to perfectly optimize
code which uses the auxiliary stack.

On 8/1/06, James McCartney <asynth@...> wrote:
> On Aug 1, 2006, at 7:40 PM, Christopher Diggins wrote:
> define quad : (a:float b:float c:float)
> {
> store_float
> store_float
> store_float
> define a : { load#2 }
> define b : { load#1 }
> define c : { load#0 }
> define d : { b b * 4 a * c * - sqrt }
> b neg d + 2 / a *
> b neg d - 2 / a *
> }
>
>
> actually I made another error in posting the formula, so this should
> really be:
>
>
> b neg d + 2 a * /
>
> b neg d - 2 a * /
>
> thanks.
>
> Since you are already declaring a b c in the type signature, why
> doesn't the compiler handle storing them on the aux stack and
> defining locals for you?
> i.e. why not just:
>
>
> define quad : (a:float b:float c:float)
> {
>
> define d : { b b * 4 a * c * - sqrt }
> b neg d + 2 a * /
>
> b neg d - 2 a * /
> }
>
> If you have local definitions, or any lexical environment, then code
> can no longer strictly concatenative according to Manfred von Thun's
> definition due to the problems of concatenation of fragments
> belonging to different lexical environments. Is that why you
> distinguish between square bracketed and curly braced code fragments?
>
>
>
>
• ... It s as if you wrote: define foo { [3 +] } ... define bar { [10] [3 +] cat_fxn i } - define bar { 13 } ... Yes so internally it actually is: [foo.x bar.x
Message 8 of 11 , Aug 2, 2006
> what does this code (assuming I've written it correctly) do in Cat?
>
>
> define foo : () -> ((int)->(int))
> {
> define x : { 3 }
> [x +]
> }

It's as if you wrote:

define foo { [3 +] }

> define bar : () -> (int)
> {
> define x : { 10 }
> [x] foo cat_fxn i // returns what?
> }

define bar { [10] [3 +] cat_fxn i }

->

define bar { 13 }

> the result of cat_fxn should be [x x +] , but the two x's are from different lexical scopes.

Yes so internally it actually is:

[foo.x bar.x +]

> ..or this (but I'm not sure if/how your store/load scheme handles nested lexical scopes?) :
>
>
> define foo : (int) -> ((int)->(int))
> {
> store_int
> define x : { load#0 }
> [x +]
> }
>
> define bar : (int) -> (int)
> {
> store_int
> define x : { load#0 }
> [x] 3 foo cat_fxn i
> }
>
> 10 bar // returns what?

So to be precise, we are missing "pop_local" at the end, to assure
that nothing is left on the auxiliary stack.

define foo : (int) -> ((int)->(int))
{
store_int
define x : { load#0 }
[x +]
pop_local
}

define bar : (int) -> (int)
{
store_int
define x : { load#0 }
[x] 3 foo cat_fxn i
pop_local
}

So the question becomes, do you want foo to leave something on the
auxiliary stack? Or do you want it to take something from the
auxiliary stack?

But I see the problem is one of my own creation: my definition of
"store_int" is not clear. It actually means to push a value onto the
auxiliary stack. So when you push a new value onto the auxiliary
stack, load#0 and store#0 now refer to that value (0th item from the
top of the auxiliary stack).

I am sorry I wasn't clear, and I appreciate you pointing this out. I
will have to clean up my spec quite a bit, and make some changes to
the semantics.

I plan on enforcing the labelling of subroutines using "sub" and
functions using "fun" and changing the name of "store_int" to
"push_local_int".