site-engine-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[site-engine-dev] A possible solution to the silly mistake


From: MJ Ray
Subject: [site-engine-dev] A possible solution to the silly mistake
Date: Mon, 05 Nov 2001 14:30:35 +0000

A solution to the database connection has occurred to me.  It requires
changes in most files, so I'll just make sure that there's a second opinion
first.  It relies on closures, so here's a quick reminder what they are.

Closures are more properly called "functions with closed-over variables".
That is, variables which you can't see from outside the function.  A trivial
example is a counter like so:

(define count
  (let ((counter 0))
    (lambda ()
      (set! counter (+ 1 counter))
      counter)))

Now each time count is called, it adds 1 to the current value of counter,
sets the counter to that and then returns this new value.  You can't access
the counter variable from outside the function, as it's outside the let.

With a little bit of (perfectly standard) trickery, you can put multiple
functions inside the closure.  I intend to do this so that all functions can
access the same database connection without having to have it passed as a
parameter all the time.

The changes required will be:

  - Remove all database open/close code from all other modules but wsedb

  - Introduce a (db-open) at the start and a (db-close) at the end of each
    page's script.

Anyone see a problem with that?

-- 
MJR



reply via email to

[Prev in Thread] Current Thread [Next in Thread]