[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Benchmarks of guile-www against HB's Guile module.
From: |
Neil Jerram |
Subject: |
Re: Benchmarks of guile-www against HB's Guile module. |
Date: |
15 Feb 2002 11:45:48 +0000 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 |
>>>>> "Alejandro" == Alejandro Forero Cuervo <address@hidden> writes:
Alejandro> Hey. :)
Alejandro> Thanks for your cooperation, Neil.
I'm getting there, slowly :-) (And I also appreciate that thi has
given you useful answers to your questions in another thread.)
Alejandro> You suggest the following: [...]
Alejandro> I can't see a difference with doing the following:
Alejandro> SCM hb_register (SCM name, SCM proc)
Alejandro> {
Alejandro> HB_FILE *hb_file = hb_get_current_file();
Alejandro> hb_file = hb_get_current_file();
Alejandro> ...;
Alejandro> }
Alejandro> init_hb ()
Alejandro> {
Alejandro> gh_new_procedure2_0 ("hb-register", hb_register);
Alejandro> }
I agree, there's no difference.
Alejandro> Does your answer mean I'm forced to declare a global variable
(where is
Alejandro> hb_get_current_file going to get the current file from?) if I
want to
Alejandro> have it passed to my function? Is there no way to
register a new
Alejandro> procedure associating it a void pointer?
OK, I think I finally get it. There is only one "current file" at any
moment, but it changes from time to time. And, whenever it changes,
you want to redefine `hb-register' by calling, ideally,
gh_new_procedure2_0_data. And you'd prefer not to keep a global
variable around in C to remember what the current file is.
If I'm now understanding correctly, you can achieve this using the
general idea of closure, but you have to involve the Scheme level, as
C primitives don't support closure. [Aside: so what is a "C closure"
then? I may be missing something here.] And it is more tricky than
the example I referred to in the manual.
Suppose the C function that does all the work is
SCM hb_register_internal (SCM file, SCM name, SCM proc)
and is exported to the Scheme level as `hb-register-internal'.
Now take this Scheme code:
(set! hb-register #f)
(define (setup-hb-register file)
(set! hb-register
(lambda (name proc)
(hb-register-internal file name proc))))
Whenever you call `setup-hb-register', it rebinds `hb-register' to a
new procedure which takes two args - NAME and PROC - and which has the
right FILE stored in its environment. So users calling `hb-register'
don't need to mention the FILE argument, but `hb-register-internal'
will always receive the FILE that was originally passed to
`setup-hb-register'. Cunning, huh?
That just leaves you with two problems:
1. You need to wrap HB's file structure somehow as a SCM value. But I
believe you've already done this.
2. You need to call `setup-hb-register' from C. I believe the proper
way to do this is:
scm_call_1 (SCM_VARIABLE_REF (scm_c_lookup ("setup-hb-register")),
file);
where file is the current file structure wrapped as a SCM value.
Am I any closer this time?
Neil
- Re: Benchmarks of guile-www against HB's Guile module., (continued)
- Re: Benchmarks of guile-www against HB's Guile module., Alejandro Forero Cuervo, 2002/02/12
- Re: Benchmarks of guile-www against HB's Guile module., Thien-Thi Nguyen, 2002/02/12
- Re: Benchmarks of guile-www against HB's Guile module., Alejandro Forero Cuervo, 2002/02/13
- Re: Benchmarks of guile-www against HB's Guile module., Thien-Thi Nguyen, 2002/02/13
- Re: Benchmarks of guile-www against HB's Guile module., Alejandro Forero Cuervo, 2002/02/13
- Re: Benchmarks of guile-www against HB's Guile module., Thien-Thi Nguyen, 2002/02/14
- Re: Benchmarks of guile-www against HB's Guile module., Neil Jerram, 2002/02/12
- Re: Benchmarks of guile-www against HB's Guile module., Alejandro Forero Cuervo, 2002/02/13
- Re: Benchmarks of guile-www against HB's Guile module., Neil Jerram, 2002/02/13
- Re: Benchmarks of guile-www against HB's Guile module., Alejandro Forero Cuervo, 2002/02/13
- Re: Benchmarks of guile-www against HB's Guile module.,
Neil Jerram <=