flofriday / Moose

🐐 A new fun programming language
MIT License
6 stars 1 forks source link

Alternative function, variable suggestion #40

Closed flofriday closed 1 year ago

flofriday commented 1 year ago

It would be lovely if we could suggest another (similar) variable or function if we cannot find the one the user selected.

I think this is especially necessary with our functions as our current error is kinda misleading and we could easily list all functions with the same name but with different signature.

Finding similar variables might be more tricky as we would need to have word distance implementation finding similar words, but it is certainly doable and would be really impressive.

flofriday commented 1 year ago

image

In this example for example we say that there is no such function like exit(Bool) which is true, however there is exit(Int) which might be what the user meant. This would be very handy to show the user.

flofriday commented 1 year ago

And similar variables could be found by calculating the Levenshtein distance between the unfound variable and (all others?, depending on how slow this is).

flofriday commented 1 year ago

Functions with the same name are now being recommended by the interpreter, however similarly named functions or variables are not.

flofriday commented 1 year ago
image

So I added fuzzy suggestions for strings. For functions the scoring function (needed to sort by relavance) is a bit trickier but I thing I have an idea that might work.

flofriday commented 1 year ago

Now also implemented for functions.

image
flofriday commented 1 year ago

I am quite pleased with the results so far, however I made some educated guesses I validated with only a handful of examples. So maybe we will have to update them in the future. However, I don't think there is a perfect answer till we have a general AI 😉