1

I'm trying to (and failing) find references to languages or environments or maybe editor plugins, where the programmer doesn't have to correctly spell methods/objects/etc....

Instead, the language uses smart heuristics during look up and chooses the most likely interpretation for the call, given context.

This is without changing the source code! Ie. not a spell checker - the source code gets saved as is.

Has anyone built something approximately like this, and where/how might I find it?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
blueberryfields
  • 45,910
  • 28
  • 89
  • 168
  • 2
    I don't think anything like this exists - programming is about telling the computer what to do, and being exact about it. Allowing typos is the opposite of being exact. It's also ambiguous - when I have functions `bar()` and `baz()`, and try to call `bat()`, which one does it pick? – Clashsoft Aug 20 '20 at 16:01
  • ICL built a compiler that did this in the 1960s. The performance was abysmal and I don't think it ever got into production. – user207421 Aug 22 '20 at 06:27

4 Answers4

1

Yes. DWIM mode, Teitelman, 1966.

(Note that for LISP systems, the boundary between programming language and user interface is not necessarily a crisp one)

user13784117
  • 1,124
  • 4
  • 4
1

Well there is this code I originally saw in this tweet:

>>> def method_missing(n, *a, &b); send(methods.min_by { |m| levenshtein(n.to_s, m.to_s) }, *a, &b); end
>> p [1, 2, 3].elngth
3

What that code is doing is overriding ruby's method_missing method which is called if an object is called with a method that does not exist on the object. Inside the overridden method_missing method it is looking at all the methods on the given object, and finding one whose name has the shortest Levenshtein distance, and then calling it, assuming that it is what the programmer meant!

The second line then demonstrates that this causes the length method on Array to be called when the non-existent elngth method is called.

Whether or not the code actually works instead of going into an infinite recursive loop appears to depend heavily on your particular ruby environment, according to this answer.

Ryan1729
  • 940
  • 7
  • 25
0

I would not dare to trust the computer with this at compiling time.

Some IDEs do detect misspellings and provide suggestions before letting you compile and I think that's the best way to deal with such cases.

Lately I have been thinking about creating a development environment where you actually tell the computer what application you have in mind, what features and interface and it creates it for you, guessing the best it can what you actually say and want. I am in the research phase, learning more about NLP and machine learning.

alexmro
  • 563
  • 4
  • 16
0

I think by applying a simple recursive Bayesian theorem on the conditional probability map build from a dataset of words (functions as well as keywords), we can design a useful code spell corrector on the line of spell.pi by Peter Norvig.

Khattak
  • 3
  • 3