This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Here's a guile profiling tool/a question/a *remarkable* guile fact (was Re: Guile profiling tools?)


>  > > defines inside of defines are *not* just being evaluated at load
>  > > time!!!!!  I find this truly remarkable!  Why is this!?!?!?!?

I read somewhere that defines inside defines are not `good' scheme but
it was never explained why.

Anyhow, AFAIK the `right' thing to do with regexp stuff and other
similar things is to use the (let... (lambda... )) construct to 
generate a closure that traps the evaluated regexp inside it:

(define foo
  (let ((RGX-1 (make-regexp "^/?test/.*"))
	(RGX-2 (make-regexp "^/?eval/([^?.]+[.]scm)$")))
    (lambda (str)
	(let ((m-1 (regexp-exec RGX-1 str))
	      (m-2 (regexp-exec RGX-2 str)))
            ...more...))))

This evaluates the make-regexp procedures only once no matter
how many times (foo) is called.

> But, R4RS states that nested defines should be equivalent to letrec,
> and that each expression assigned by the letrec must evaluatable
> "without assigning or referring to the value of any <variable>".

(letrec) still evaluates every time the procedure is called,
I mean, everything evaluates every time it is evaluated doesn't it?

> I guess I'm going to have to stop using local variables for such
> things...

Global variables get an unfairly bad rap in my humble opinion
but if you really want to minimise the use of the global namespace
then use the above closures.

	- Tel