[plt-scheme] Newbie Schemer question
> Still, there are situations in which something like dynamic scope can be
> useful. I assume your example is just a simplified version of what you
> really want to do. If you can explain what it is you're trying to do, I'm
> sure an appropriate Scheme solution can be suggested.
>
Yes, I have simplified a bit what I need... ;-)
I'm going to try to explain in a simplest way my requirement's context.
I'm developing server applications to manage a Call Center platform, and
especially inbound calls.
- telephony server: connects to different telephony systems that
supports a CTI (Computer Telephony Integration) link , such as PBX,
voice boarding, and so on. The telephony server provides a common API to
control and monitor telephony devices.
- telephony router server: monitors routing points on a telephony system
(a kind of telephony entry point in a telephony system), and deflects
any inbound calls (customers calls) on those routing points to telephony
devices of the platform (agents phones). The telephony router server
executes a strategy script on the script server to get the
identification of the telephony device where the inbound call should be
deflected on.
- script server: provides a common API to run script command on a script
engine plugged in the script server. The script server is not specific
to telephony purpose.
Each routing point is associated to:
- the identifier of the routing point's telephony device.
- a complete script source code that could correspond to a list of
procedures, functions, whatever you want (library functions).
- a simple script command that will be executed when an inbound call is
alerting the routing point's telephony device. This script command may
use some functions the "complete script source code" provides.
Okay, here my problems begin! It should be obvious that the script
command needs to get information about the inbound call context (callers
and callee's phone numbers, data attached to the call, and so on) to
choose the telephony device of the platform where the inbound call must
be deflected to.
So my initial though was to encapsulate the <script command> like this
(for MzScheme script engine):
((let ([*callingDeviceId* 0556437921]
[*calledDeviceId* 3000] ...))
(lambda ()
(<script command>)))
I think I can't define functions, some getters, for each telephony
parameters such as (define (get-calling-device-id) (0556437921)),
because the script server just creates on MzSchem script engine
instance, and thus such function will be overrided by a newest
declaration in multithreading context.
A friend tells me I can force strategy script developer to declare a
specific parameter .context in the function of his script such as:
(define (f a b c .context)
(...))
Then the script command (f 1 2 3) will be extended by the script engine
wrapper by (f 1 2 3 '(<telephony parameters)). But I feel that is not
the good way to proceed, because one, I force the developer to respect a
kind of function interface, and two, I can't assume that the script
command corresponds to a classic function call (actually, the script
command could be just a simple evaluation such as (+ 1 2), I don't
know).
You talk about fluid-let, a special feature that could solve my problem.
How does it work?
Regards,
--
Daniel
"Cang ngay cang thay minh do"
Le mer 06/11/2002 à 07:48, Anton van Straaten a écrit :
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> > I would like to execute a function that has one of its variable defined
> > outside this function, in an upper context. Suppose that I define a simple
> > function such as:
> >
> > (define (f n)
> > (+ *p* n))
> >
> > I would like to write something like that (the following syntax is
> > incorrect):
> >
> > ((let ((*p* 1))
> > (lambda ()
> > (f 2)))
> >
> > How should I formulate this in Scheme?
>
> The feature you're describing is usually called "dynamic scope" or "dynamic
> variables" (not to be confused with similar terms sometimes used in the
> context of fluid-let). Scheme does not support dynamic scope directly.
> Since Scheme uses lexical scoping, as Paul pointed out, this doesn't work
> because the body of the function f, where *p* is referenced, is not within
> the same lexical scope as the definition of *p*.
>
> Dynamic scope is generally considered a bad idea because it can make
> programs hard to understand, and introduce bugs. In any given lexical
> scope, e.g. within a function, it's hard for a human reader of the code to
> tell what variables may or may not be available in that scope, and the
> available variables can change from one invocation of the function to the
> next.
>
> Still, there are situations in which something like dynamic scope can be
> useful. I assume your example is just a simplified version of what you
> really want to do. If you can explain what it is you're trying to do, I'm
> sure an appropriate Scheme solution can be suggested.
>
> Anton
>