[racket] Exploratory programming?
Hi Matthias,
> It isn't clear to me whether you have tried
>
> > (help "lambda")
>
> in your emacs repl. If so, do you object to the browser coming up with intensively hyperlinked documentation? Or do you not like the format?
(Evidently I had not. Now that is embarrassing. I could swear I had
tried it before, maybe back when I just had the PLT Scheme packages
installed, with only an unbound name error as the result...Is this
perhaps a recent addition? Or could I have inadvertently done some
configuration that makes "help" available in my Racket REPL when it
wasn't before?)
> Let us know what's wrong with that.
There's nothing wrong with it; it's great! Thanks for pointing this out
to me.
If I had my druthers, the help function would also be a tool for
introspection. (Is there another function designed for this? (help
"introspection") doesn't turn up any results... :) [See examples below]
But I realize that this may be asking for precisely the kind of REPL
interaction that Racket has consciously chosen to avoid.
> I have done a lot of bottom up programming in Emacs (Scheme and Lisp) and I still do in DrRacket. But I learned that bottom-up programming is the norm and that what makes it successful is some amount of top-down planning. If you meet somewhere in the middle and explore from there, you can grow into a super-programmer.
Indeed; I know that this is sound advice. (I didn't mean to imply that I
didn't want to do any top-down programming -- just that I wasn't sure
how to use the Racket docs in the complementary, bottom-up way.)
Thanks, Matthias, for the advice and guidance that you (and so many
others on this!) list so consistently offer.
Best,
Richard
====================
Examples: comparing Python's help function to Racket's as a tool for
introspecting objects at the REPL
Compare:
>>> def f(x, y):
... "Add x and y"
... return x + y
...
>>> help(f)
Help on function f in module __main__:
f(x, y)
Add x and y
to:
> (define (f x y)
(+ x y))
> (help f)
Not found in any library's documentation: f
Or compare:
>>> help(3)
Help on int object:
class int(object)
| int(x[, base]) -> integer
| # ...
| Methods defined here:
|
| __abs__(...)
| x.__abs__() <==> abs(x)
|
| __add__(...)
| x.__add__(y) <==> x+y
| # ...
to:
> (help 3)
stdin::257: help: expects any number of literal strings, a single identifier, an identifier followed by a #:from clause, or a #:search clause; try `(help help)' for more information in: (help 3)
; ...
(Or, for the sake of comparing apples to something more resembling
apples, compare:)
> (define my-int
(class object%
(init-field the-integer)
(define/public (f n)
(new this% [the-integer (+ n the-integer)]))
(super-new)))
> (define three (new my-int [the-integer 3]))
> (help three)
Not found in any library's documentation: three