Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Word synonyms for binary operators #20

Open
catb0t opened this issue Dec 5, 2022 · 7 comments
Open

Word synonyms for binary operators #20

catb0t opened this issue Dec 5, 2022 · 7 comments

Comments

@catb0t
Copy link

catb0t commented Dec 5, 2022

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 catb0t changed the title Word syonyms for binary operators Word synonyms for binary operators Dec 5, 2022
@StavromulaBeta
Copy link
Collaborator

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(?)

@dragoncoder047
Copy link
Contributor

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.

@catb0t
Copy link
Author

catb0t commented Dec 5, 2022

@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 catb0t closed this as completed Dec 5, 2022
@catb0t catb0t reopened this Dec 5, 2022
@dragoncoder047
Copy link
Contributor

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.

@StavromulaBeta
Copy link
Collaborator

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

@dragoncoder047
Copy link
Contributor

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.

@StavromulaBeta
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants