cognate icon indicating copy to clipboard operation
cognate copied to clipboard

Word synonyms for binary operators

Open catb0t opened this issue 2 years ago • 7 comments

Cognate looks really cool. The one place I think the literate aspect can be improved is with the binary operators, which are hard to read in a sentence as prefix symbols.

Print * 3 by - 7 2;  

If the following looks nice, I will make a pull request to add synonyms like this:

Print Multiply 3 by Subtract 7 from 2;

and so on, + would be Add, Inequal? and Equal? for != and ==, because of the same for While (!= "done" Twin Input)

catb0t avatar Dec 05 '22 05:12 catb0t

This is definitely an interesting idea. A long while ago (might be in commit history somewhere) I had all the binary operators as words, although more declarative variants. IE you could write Print the Product of X and Y; instead of Print Multiply X by Y;.

However I felt that was a tad too verbose and made code rather more difficult to scan through, so I added the symbol variants. I think the problem is that mathematical expressions are just very difficult to convey in english.

I'm definitely open to the idea of adding synonyms, but I do worry that it would make the language more difficult to learn and could potentially be overwhelming(?)

StavromulaBeta avatar Dec 05 '22 16:12 StavromulaBeta

One idea I had from this (borrowed form Scheme) is you could allow the user to write something like Let Product be &* -- the & forcing the symbol to be treated like a var even though it is a function (and the definition of * will be pushed to the stack instead of * evaluated), and then when Multiply is looked up, it will see the definition of * as the value of Multiply and voìla. Although if Cognate is a "Lisp-2" kind of language, this might be hard to implement.

dragoncoder047 avatar Dec 05 '22 16:12 dragoncoder047

@dragoncoder047: Let Product be &* -- the & forcing the symbol to be treated like a var even though it is a function (and the definition of * will be pushed to the stack instead of * evaluated)

You should already be able to do Def Product as (*); right? That's almost as good as is

catb0t avatar Dec 05 '22 18:12 catb0t

You should already be able to do Def Product as (*); right? That's almost as good as is

Yes, but that incurs another layer of stack recursion. My "redirected definition" idea is like inline in C -- inlined functions don't use any extra stack space to call them. It's an optimization. Tail-call optimization may be higher priority than this.

dragoncoder047 avatar Dec 05 '22 19:12 dragoncoder047

You should already be able to do Def Product as (*); right? That's almost as good as is

Yes, but that incurs another layer of stack recursion. My "redirected definition" idea is like inline in C -- inlined functions don't use any extra stack space to call them. It's an optimization. Tail-call optimization may be higher priority than this.

The compiler will already inline this when defined as (*) btw

StavromulaBeta avatar Dec 05 '22 19:12 StavromulaBeta

The compiler will already inline this when defined as (*) btw

Good, I didn't know that.

Maybe all that is needed is to add these things to the standard library.

dragoncoder047 avatar Dec 05 '22 19:12 dragoncoder047

The compiler will already inline this when defined as (*) btw

Good, I didn't know that.

Maybe all that is needed is to add these things to the standard library.

Yes, I think that was catb0t's original intention.

StavromulaBeta avatar Dec 05 '22 19:12 StavromulaBeta