Hi,
Is there any way to get global symbol table from scheme? (Because I see that symbol completion is done in C).
Afficher les réponses par date
Nguyen Thai Ngoc Duy wrote:
Hi,
Is there any way to get global symbol table from scheme? (Because I see that symbol completion is done in C).
You can get the ___GSTATE->symbol_table by calling (##symbol-table); this is not a normal Gambit hash table (it predated Gambit's hash table implementation, and maybe there are reasons to leave it at what it is); it's a vector with some number in the first position -- so, how you work with that depends on what you want to do with it. For one, you can use ##object->global-var to map a procedure value back to a symbol holding it. Maybe there are a few more Scheme wrappers, I haven't looked closely enough, check _kernel.scm, setup.c, and maybe a few other files.
Check cj-symbol*scm from http://scheme.mine.nu/gambit/preview/ for how I did it. (And I welcome suggestions and patches to that file.)
Christian.
On 7/31/08, Christian Jaeger christian@pflanze.mine.nu wrote:
Nguyen Thai Ngoc Duy wrote:
Hi,
Is there any way to get global symbol table from scheme? (Because I see that symbol completion is done in C).
You can get the ___GSTATE->symbol_table by calling (##symbol-table); this is not a normal Gambit hash table (it predated Gambit's hash table implementation, and maybe there are reasons to leave it at what it is); it's a vector with some number in the first position -- so, how you work with that depends on what you want to do with it. For one, you can use ##object->global-var to map a procedure value back to a symbol holding it. Maybe there are a few more Scheme wrappers, I haven't looked closely enough, check _kernel.scm, setup.c, and maybe a few other files.
I needed it to (try to) implement swank backend for gambit: give a prefix, return a more exact prefix (if any) and a list of possible completions.
Check cj-symbol*scm from http://scheme.mine.nu/gambit/preview/ for how I did it. (And I welcome suggestions and patches to that file.)
Might not have time for a look today. Thanks.
Nguyen Thai Ngoc Duy wrote:
I needed it to (try to) implement swank backend for gambit:
cool
give a prefix, return a more exact prefix (if any)
What does "a more exact prefix" mean? Ignoring case sensitivity? Soundex based matching? ...
and a list of possible completions.
You should maybe tell more exactly how the api looks that swank expects. For really efficient matching you'll need to build some form of trees (tries, binary trees, or at least some sorted vectors), but on one hand swank might already contain those algorithms (I suppose you're porting the one for Scheme 48?), and if it doesn't, I think you could also get by with just walking the table vector and looking at every symbol string, if it's only for tab completion and similar functionality which is only checking the symbols at most once per each user input.
(filter (lambda (v) (and (symbol? v) (##global-var? v))) (vector->list (##symbol-table)))
Christian.
On 7/31/08, Christian Jaeger christian@pflanze.mine.nu wrote:
Nguyen Thai Ngoc Duy wrote:
I needed it to (try to) implement swank backend for gambit:
cool
Well it can start slime, but nothing more :(
give a prefix, return a more exact prefix (if any)
What does "a more exact prefix" mean? Ignoring case sensitivity? Soundex based matching? ...
Let's take an example. Assume you only have symbols "abc" and "abd", then you type "a" and do completion. It should return "more exact prefix" as "ab" along with two possible completions that are "abc" and "abd". That was what I observed from *slime-event* buffer.
and a list of possible completions.
You should maybe tell more exactly how the api looks that swank expects. For really efficient matching you'll need to build some form of trees (tries, binary trees, or at least some sorted vectors), but on one hand swank might already contain those algorithms (I suppose you're porting the one for Scheme 48?), and if it doesn't, I think you could also get by with just walking the table vector and looking at every symbol string, if it's only for tab completion and similar functionality which is only checking the symbols at most once per each user input.
Input: a string for intial prefix Output: `( (list of possible completions) <more exact prefix>)
I made something like that with bug 50 [1]. Unfortunately it was in C. I am looking at the table vector to see how can I traverse it.
[1] http://www.iro.umontreal.ca/~gambit/bugzilla/show_bug.cgi?id=50
(filter (lambda (v) (and (symbol? v) (##global-var? v))) (vector->list (##symbol-table)))
I still have not had time to look closely to what you suggested. But from the first look, it seems (vector->list (##symbol-table)) does not contain all symbols. Will look into this later.
Thanks.