www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - name guess by the compiler

reply spir <denis.spir gmail.com> writes:
PS: for got to ask: is there any kind of namespace in D -- especially one k=
ind usable for module export?

Hello,


dmd has a helpful feature, trying to guess which id may have been wrongly t=
yped -- provided the error actually was a typo:
	__trials__.d(20): Error: undefined identifier goo, did you mean variable f=
oo?

But in numerous cases, the source of the error is not a typo, which leads t=
o confusing messages such as:
	__trials__.d(19): Error: undefined identifier i, did you mean alias to?

I have no idea how dmd guesses possible names. But surely there is a kind o=
f probability evaluation used to rank possible guesses. If I'm right, then =
dmd should not output its best guess in every case, but only when its proba=
bility value is higher than a given threshold (to be carefully defines).

Also, the case above probably reveals some kind of bug, since it is hard to=
 imagine how "to" can ever be the best guess for "i" (and there is no alias=
 in the test case). PS: "alias to" is only guessed when the module imports =
std.conv:to. Still, how to guess "to" from "i"? Finally, should the guessin=
g feature exclude (unqualfied) imported symbols?


Denis
-- -- -- -- -- -- --
vit esse estrany =E2=98=A3

spir.wikidot.com
Nov 25 2010
next sibling parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
On Thu, 25 Nov 2010 11:10:29 +0100, spir <denis.spir gmail.com> wrote:

 PS: for got to ask: is there any kind of namespace in D -- especially  
 one kind usable for module export?

D does not have namespaces per se. However, modules introduce a sort of namespace, templates create parametrized namespaces, and final abstract classes may be used to fake namespaces, should the other features not be sufficient: final abstract class MyNamespace { static: // stuffs }
 I have no idea how dmd guesses possible names. But surely there is a  
 kind of probability evaluation used to rank possible guesses. If I'm  
 right, then dmd should not output its best guess in every case, but only  
 when its probability value is higher than a given threshold (to be  
 carefully defines).

This sounds reasonable, but hardly top of the list on urgency.
 Also, the case above probably reveals some kind of bug, since it is hard  
 to imagine how "to" can ever be the best guess for "i" (and there is no  
 alias in the test case). PS: "alias to" is only guessed when the module  
 imports std.conv:to. Still, how to guess "to" from "i"? Finally, should  
 the guessing feature exclude (unqualfied) imported symbols?

Absolutely not. -- Simen
Nov 25 2010
prev sibling next sibling parent Jason House <jason.james.house gmail.com> writes:
I believe dmd looks for up to two errors when looking for a candidate match. I
agree that for single letter variables that doesn't make a lot of sense. Even
for two letter symbols it probably doesn't make much sense either.

spir Wrote:

 PS: for got to ask: is there any kind of namespace in D -- especially one kind
usable for module export?
 
 Hello,
 
 
 dmd has a helpful feature, trying to guess which id may have been wrongly
typed -- provided the error actually was a typo:
 	__trials__.d(20): Error: undefined identifier goo, did you mean variable foo?
 
 But in numerous cases, the source of the error is not a typo, which leads to
confusing messages such as:
 	__trials__.d(19): Error: undefined identifier i, did you mean alias to?
 
 I have no idea how dmd guesses possible names. But surely there is a kind of
probability evaluation used to rank possible guesses. If I'm right, then dmd
should not output its best guess in every case, but only when its probability
value is higher than a given threshold (to be carefully defines).
 
 Also, the case above probably reveals some kind of bug, since it is hard to
imagine how "to" can ever be the best guess for "i" (and there is no alias in
the test case). PS: "alias to" is only guessed when the module imports
std.conv:to. Still, how to guess "to" from "i"? Finally, should the guessing
feature exclude (unqualfied) imported symbols?
 
 
 Denis
 -- -- -- -- -- -- --
 vit esse estrany ☣
 
 spir.wikidot.com
 

Nov 25 2010
prev sibling next sibling parent Nick Treleaven <nospam example.net> writes:
On Thu, 25 Nov 2010 09:08:11 -0500, Jason House wrote:

 I believe dmd looks for up to two errors when looking for a candidate
 match. I agree that for single letter variables that doesn't make a lot
 of sense. Even for two letter symbols it probably doesn't make much
 sense either.

It's perhaps a minor quirk, but dmd could be changed to look for names with a Levenshtein distance of MIN(2, variable_name.length). That would prevent 'to' being suggested for 'i', but could still match 'ii' or 'j'.
Nov 25 2010
prev sibling parent Nick Treleaven <nospam example.net> writes:
On Thu, 25 Nov 2010 19:36:32 +0000, Nick Treleaven wrote:

 On Thu, 25 Nov 2010 09:08:11 -0500, Jason House wrote:
 
 I believe dmd looks for up to two errors when looking for a candidate
 match. I agree that for single letter variables that doesn't make a lot
 of sense. Even for two letter symbols it probably doesn't make much
 sense either.

It's perhaps a minor quirk, but dmd could be changed to look for names with a Levenshtein distance of MIN(2, variable_name.length).

Actually a distance of 1 is probably best for variable_name.length == 2 too, thus preventing 'i' for 'to'.
 That would prevent 'to' being suggested for 'i', but could still match
 'ii' or 'j'.

Nov 27 2010