[gambit-list] (no subject)
repleffect at gmail.com
Sat Oct 6 23:21:02 EDT 2012
What would it take to expose a procedure in the interpreter for
completing symbols in the symbol table. What I mean is, I'd like a
scheme procedure I could call with a string representing either a full
or a partial symbol, and the procedure would give me back a list of
the possible completions for currently defined symbols.
Essentially I want a procedure that does what the tab completion in
the interpreter's REPL does.
I'm using the partially-implemented swank backend that James Long was
working on a while back, and I found these procedures that Marc posted
to the list back in March of '09:
(define (symbol-table->list st)
(define (symbol-chain s syms)
(let loop ((s s) (syms syms))
(if (symbol? s)
(loop (##vector-ref s 2) (cons s syms))
(let loop ((lst (vector->list st)) (syms '()))
(if (pair? lst)
(loop (cdr lst) (symbol-chain (car lst) syms))
(pp (length (interned-symbols)))
(that was from this post:
>From that I cobbled together a very inefficient hash-table-based tab
completion (especially inefficient because of duplicating the entire
symbol table in a hash table, one key per symbol). I realize this is
a complete kludge and wastes tremendous amounts of memory. I'd like
to do it right and just query the symbol table itself, since the data
is obviously already there.
I found the complete_word(), lineeditor_word_completion(), and
visit_symbol() functions in os_tty.c, and I'm sure that the solution
is to write a similar set of C functions to act as a scheme interface
to do what I want. However, I suspect I don't understand the code
well enough at this point to do that correctly.
I'd be willing to give it a shot if I thought I had a sufficient
quantity of tips on how to get it done (I started to say 'pointers' on
how to get it done, but I suspected that would only lead to a long
string of programmer jokes that might derail this thread :-D ).
It seems to me that this would be a good thing to have available for
any application that might embed Gambit and/or communicate with a
process running the Gambit interpreter. I don't think the
applicability would be in any way limited to slime/swank (though,
admittedly, that is my primary motivation for having it).
More information about the Gambit-list