[racket-dev] Search by example (was Re: Roogle?)

From: Tony Garnock-Jones (tonyg at ccs.neu.edu)
Date: Sat Aug 6 15:13:41 EDT 2011

On 2011-08-05 12:13 AM, Robby Findler wrote:
> So I wonder if anyone has a positive experience with this kind of
> searching in an "in anger" kind of setting?

Not with search by type, but at the risk of derailing the thread, I have
had quite a few positive experiences with search by example.

For instance, many's the time I've been unable to remember the name of
the selector that tells me whether a string starts with some other
substring in Smalltalk. So I open the "method finder", and enter

  'abcde'. 'abc'. true

for the first and second arguments and the expected result,
respectively, and start it ticking, and it answers with suggested
methods such as

  'abc' < 'abcde' --> true
  'abcde' > 'abc' --> true
  'abcde' beginsWith: 'abc' --> true
  'abcde' includesSubString: 'abc' --> true

and so on. See attached picture. Clicking on the "beginsWith:" entry in
the results shows me all the classes implementing that method, in a
list. Clicking on an entry of that list opens up the relevant source code.

It has been useful to me on more than one occasion (e.g. entering
"'cbabad'. $a. 2" gives #occurrencesOf:).

There's nothing magic about Smalltalk either. It's implemented as a
giant hackish crock rather than as anything remotely viewable as elegant
:-) The implementation simply has a list of "safe" methods that it runs
through in order, collecting non-erroring results that compare equal to
the expected output, which it then displays in a list.

Something similar could work for Racket. Useful for students and others
learning or transitioning to the language, perhaps.

You could even use contracts, perhaps: check each given argument against
the positional arguments of a candidate's contract, check the given
result; you don't even have to run the contracted procedure, which could
after all be dangerous, and thus you get to avoid some of the
crockishness of the Squeak implementation.

(You could also, in both Squeak's and this imagined Racket solution,
permit additional examples to be given to narrow the field after some
first candidate is found. #('abcde' 'xyz' false), for instance, for the
original example.)

Cheers,
  Tony
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen shot 2011-08-06 at 3.01.24 PM.png
Type: image/png
Size: 33386 bytes
Desc: not available
URL: <http://lists.racket-lang.org/dev/archive/attachments/20110806/949a1274/attachment.png>

Posted on the dev mailing list.