cognate icon indicating copy to clipboard operation
cognate copied to clipboard

Documentation for Cognate words??

Open dragoncoder047 opened this issue 3 years ago • 8 comments

There isn't any documentation on each builtin word, and so for the ones that take and/or return blocks, the semantics are very confusing. Case in particular. What are the semantics of that, and everything else? Writing it as Forth stack-effect diagrams or just some example code would help.

dragoncoder047 avatar Oct 27 '22 19:10 dragoncoder047

i can try to help with documentation, if only the admins will want to

shreder95ua avatar Oct 29 '22 15:10 shreder95ua

I'm currently at university so I'm a tad busy, but I'll be able to write some more documentation once the term finishes - as well as actually finish the compiler rewrite!

StavromulaBeta avatar Oct 29 '22 15:10 StavromulaBeta

Also, the behaviour of some combinators such as Case might change in future, as the current iteration is very difficult to optimise and can be a bit confusing.

StavromulaBeta avatar Oct 29 '22 15:10 StavromulaBeta

I might use the "old" (i.e. current) behavior of Case in TEHSSL, because then you don't have to write ( ) around a function that is comprised entirely of a large Case switch.

dragoncoder047 avatar Oct 29 '22 16:10 dragoncoder047

Well that part of the behavior I'm keeping. The bit I'm concerned about is the fact that you can do this, maxing blocks and value types.

Def F as
   Case 1 is 2
   Case (> 3) is (+ 1)
   Case -1 is (+ 3)
   otherwise 5;

The problem with this being that it has to do dynamic dispatch on the type passed to it, and it's very difficult to generate good code from this.

StavromulaBeta avatar Oct 29 '22 16:10 StavromulaBeta

Well that part of the behavior I'm keeping. The but I'm concerned about is the fact that you can do this, maxing blocks and value types.

Def F as
   Case 1 is 2
   Case (> 3) is (+ 1)
   Case -1 is (+ 3)
   otherwise 5;

The problem with this being that it has to do dynamic dispatch on the type passed to it, and it's very difficult to generate good code from this.

Perhaps a better solution would be to have variants of Case that take differing combinations of blocks and values.

StavromulaBeta avatar Oct 29 '22 16:10 StavromulaBeta

This is uglier but generates much better code, since types are more deterministic:

Def F as
   Case (== 2) then (3 Drop)
   Case (> 3) then (+ 1)
   Case (== -1) then (+ 3)
   otherwise (5 Drop);

StavromulaBeta avatar Oct 29 '22 16:10 StavromulaBeta

Unfortunately I can't find any other languages that implement anything like the Case combinator here (closest is probably Factor) so I haven't got much to work with.

StavromulaBeta avatar Oct 29 '22 16:10 StavromulaBeta