cognate
cognate copied to clipboard
Word synonyms for binary operators
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)
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(?)
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:
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
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.
You should already be able to do
Def Product as (*);
right? That's almost as good as isYes, 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
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.
The compiler will already inline this when defined as
(*)
btwGood, 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.