Stream: cull-os

Topic: Language design philosophy


view this post on Zulip RGBCube (Jul 06 2024 at 09:57):

Currently in Cab, there are only 3 keywords that aren't defined as infix/postfix operators: if, then and else. (and and, or which are infix, not which is a prefix opetator, just like -)

I believe a this doesn't fit the language because there are no other "special cased" keywords. I want to change their behavior, also removing the if keyword in the process of redesigning this approach. The new syntax for "if else" will be:

cond then y else n

then has higher binding power, so you can chain then and else.

Another benefit of this is that you will be able to do setThatDoesNotHaveFoo.foo else "foo didn't exist" without special casing (like the or in Nix), as .foo is undefined.

Thoughts?

view this post on Zulip RGBCube (Jul 07 2024 at 19:49):

I think I'll keep the normal if else then right now. Have some doubts about precendence and the general ergonomics of it

view this post on Zulip RGBCube (Jul 07 2024 at 19:49):

But I'll definitely look into it later when more stuff is done

view this post on Zulip Tim DeHerrera (Jul 07 2024 at 19:56):

I was thinking about this a bit yesterday. FWIW, I think its a fairly nice idea. It's basically the "ternary" operation from other languages at that point, which I am fond of.

view this post on Zulip RGBCube (Jul 07 2024 at 20:05):

It is exactly like ? and :, but each operator is seperate

view this post on Zulip RGBCube (Jul 07 2024 at 20:05):

However this might require you to put () everywhere, which I'm not fond of. I'll look at some snippets inside nixpkgs lib and rewrite them to use this, seeing how it works


Last updated: Nov 21 2024 at 09:45 UTC