PaddiM8 / kalker

Scientific calculator with math syntax that supports user-defined variables and functions, complex numbers, and estimation of derivatives and integrals
https://kalker.xyz
MIT License
1.64k stars 74 forks source link

Custom built-in functions #100

Open NatanFreeman opened 2 years ago

NatanFreeman commented 2 years ago

I would like to define custom built in functions from Rust call-backs. This makes the functions more extendable as you have access to Rust's functionality like println! along with other Rust math libraries. Is this currently possible? If not I think this should be considered. It allows fore greater extendibility without the need of another parser.

PaddiM8 commented 2 years ago

I've been thinking about implementing some way to have custom built-in functions. This sounds like a good way to do it. Would love to implement this at some point.

Yusuto commented 1 year ago

This would be something that would need to be implemented in the kalk crate, right? I am very new to all of this, but this seems somewhat straightforward, would I be allowed to try to implement this?

PaddiM8 commented 1 year ago

@Yusuto Correct, that would be done in kalk. Feel free to give it a try! Function calls are evaluated in interpreter.rs#L330.

Yusuto commented 1 year ago

@PaddiM8 Okai, Thank you! I looked around a bit and this stuff seems to be significantly more complex that I first imagined. In hindsight it makes sense, since it's in essence somewhat of a tiny programming language >< Am I correct in that kalk as of now has pretty much no documentation? If so I could offer to write some rustdoc as I go about understanding everything, if that is desired!

PaddiM8 commented 1 year ago

@Yusuto Yeah it basically turned into a small languages, woops. You're right, it does lack documentation. That would be great!

Yusuto commented 1 year ago

Yep! I think it's actually quite interesting and sounds pretty powerful, it's sadly not Wolfram Alpha, but I have come to use kalker as my day-to-day calculator to the point where I aliased it to just k in my shell.

I have very little experience with that, but it seems like it could be turned into a good PWA? I'd very thrilled to have a proper calculator on my phone, not sure if that's just me but it seems like all the alternatives are just kind of- ugly. I mean they do their job but not really much more. And kalker already works quite decently in a mobile browser, so ^^

I saw some project files for Android, I suppose a native app would be even better, you could maybe even have things such as a widget for quickly calculating or something, that sounds convenient

PaddiM8 commented 1 year ago

@Yusuto It's great to hear that you're finding it useful! There is an apk for Android that basically just loads it as a website, but works quite well for me at least. A PWA would be a good solution for iPhones actually, didn't think of that.

Yusuto commented 1 year ago

@PaddiM8 Yep! they even support stuff like Push-Notifications using Service Workers, and if you have a modern browser that allows you install a PWA, I think they are even guaranteed by the browser to work without an internet connection (provided the devs didn't mess something up).