chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] Functions with lots of parameters


From: John Cowan
Subject: Re: [Chicken-users] Functions with lots of parameters
Date: Fri, 29 Sep 2006 17:05:44 -0400
User-agent: Mutt/1.3.28i

Alejandro Forero Cuervo scripsit:

> [Lots of procedure arguments makes for a hard problem, especially when
> passed around from a procedure to its callees.  Records are a possibility,
> but they aren't very extensible, and preplanning everything we might
> want is hard.  Dynamically scoped variables would solve the problem,
> but that's not the Scheme way.]

Fortunately, SRFI-39, Parameter objects, gets you what you want.
The general idea is that you use:

        (define foo (make-parameter 10))

to create a dynamic variable named foo with initial value 10.  You can get
the value of foo by saying "(foo)" and change its value to 15 by saying
"(foo 15)".

More usefully, the special form "parameterize" is a dynamic-extent
equivalent of "let":

        (parameterize ((foo 15)) <body>)

will cause "(foo)" to evaluate to 15 in the *dynamic* extent of "<body>".
Parameters actually have more flexibility than this: the full details
are available at http://srfi.schemers.org/srfi-39/srfi-39.html .

Even more fortunately, SRFI-39 is built into Chicken.  You can get
portability by saying "(require-extension (srfi 39))", although Chicken
does not require this.

-- 
XQuery Blueberry DOM                            John Cowan
Entity parser dot-com                           address@hidden
    Abstract schemata                           http://www.ccil.org/~cowan
    XPointer errata
Infoset Unicode BOM                                 --Richard Tobin




reply via email to

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