DreamBerd icon indicating copy to clipboard operation
DreamBerd copied to clipboard

Add operator overloading

Open ysthakur opened this issue 2 years ago • 7 comments

Many modern programming languages have operator overloading, so DreamBerd ought to have it too. In fact, users should be given the freedom to make any operator they want.

ysthakur avatar Jun 10 '23 17:06 ysthakur

It's lacking the specification of operator operator.

stohrendorf avatar Jun 10 '23 17:06 stohrendorf

I think this has legs! The "twist" of being able to define all operators is fun. Could also do it with the , operator for arrays. I wonder if there's a way of coming up with some simpler examples so that we don't have to put a "...". That would make it more fun I think :)

TodePond avatar Jun 10 '23 17:06 TodePond

What about operator ...() => { print("hello world")! }?

stohrendorf avatar Jun 10 '23 17:06 stohrendorf

Ohhh... maybe too advanced, but imagine


You may have noticed that the examples above use ... to represent the body of each function. This isn't pseudo-code. Instead, ... is an operator that we've defined later on.

operator ...<-Infinity>() => {
   return ... // Function body goes here
}

TodePond avatar Jun 10 '23 17:06 TodePond

I like the idea of defining ... itself as an operator. Perhaps instead of the implementation being recursive (return ...), it should use DreamBerd's AI feature to implement whatever the original function wanted? Maybe something like

postfix operator !(foo) => {
    return ... // Factorial
}

unfix operator ...<-Infinity>() => {
    const const code = email("Lu Wilson", "Subject: give me teh codez", getOuterFunction())!
    exec(code)!
}

ysthakur avatar Jun 10 '23 17:06 ysthakur

Yeah you could place ... at the very end of the file(s) so that it reliably triggers AI

TodePond avatar Jun 10 '23 17:06 TodePond

assigning this to myself to remind me to review at some point

TodePond avatar Jun 13 '23 07:06 TodePond