* Multiple implementations of low-level functions
@ 2003-11-01 1:33 Michael J. Barillier
2003-11-01 4:45 ` Keith Wright
2003-11-02 13:48 ` Thien-Thi Nguyen
0 siblings, 2 replies; 3+ messages in thread
From: Michael J. Barillier @ 2003-11-01 1:33 UTC (permalink / raw)
I've been hacking on a system for which I would like to have multiple
implementations of low-level functions, which would be called by
higher-level code. (e.g. A test version with static data, v. a test
version with data stored in a database, v. a production version
running against an Oracle database and communicating with other
processes.)
As I see it, I've got two options, but I'm trolling for others:
(1) Something SICP-like, with a closure that's passed around,
returning a function based on a selector, as in:
(use-module (test-implementation))
(define impl (make-test-implementation args...))
((impl 'get-records) "first key" "second key")
(2) Load functions at the start of program execution, before the
high-level stuff is loaded/called:
(load "test-implementation")
(get-records "first key" "second key")
There also might be a module-based solution, but I haven't ventured
down that route.
I've written apps using the first solution, and it worked fine, other
than some nasty nesting of functions and having to pass a parameter
around. The second option is nice for its simplicity, and from the
viewpoint of building up the Scheme (or Lisp) environment/library of
available functions, loading higher-level stuff onto lower-level code.
Anyone care to weigh in on either method, or propose a sexier
solution?
--
Michael J. Barillier mbarilli(at)midsouth.rr.com /"\ ASCII Ribbon
Reg Linux user #125310 <http://counter.li.org/> \ / Campaign against
A. Because that's not how people read. X HTML and RTF
Q. Why is top-posting email replies bad? / \ email
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Multiple implementations of low-level functions
2003-11-01 1:33 Multiple implementations of low-level functions Michael J. Barillier
@ 2003-11-01 4:45 ` Keith Wright
2003-11-02 13:48 ` Thien-Thi Nguyen
1 sibling, 0 replies; 3+ messages in thread
From: Keith Wright @ 2003-11-01 4:45 UTC (permalink / raw)
Cc: guile-user
> From: "Michael J. Barillier" <mbarilli@midsouth.rr.com>
>
> I've been hacking on a system for which I would like to have multiple
> implementations of low-level functions, which would be called by
> higher-level code. (e.g. A test version with static data, v. a test
> version with data stored in a database, v. a production version
> running against an Oracle database and communicating with other
> processes.)
> ...
> Anyone care to weigh in on either method, or propose a sexier
> solution?
Why not just have a variable and assign it the value you want?
(set! compute
(case version
((test1) (lambda(n) 42))
((test2) (lambda(n) (+ 1 n)))
(else (lambda(n) (call-oracle "select answer from air"))) ))
--
-- Keith Wright <kwright@free-comp-shop.com>
Programmer in Chief, Free Computer Shop <http://www.free-comp-shop.com>
--- Food, Shelter, Source code. ---
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Multiple implementations of low-level functions
2003-11-01 1:33 Multiple implementations of low-level functions Michael J. Barillier
2003-11-01 4:45 ` Keith Wright
@ 2003-11-02 13:48 ` Thien-Thi Nguyen
1 sibling, 0 replies; 3+ messages in thread
From: Thien-Thi Nguyen @ 2003-11-02 13:48 UTC (permalink / raw)
Cc: guile-user
From: "Michael J. Barillier" <mbarilli@midsouth.rr.com>
Date: Fri, 31 Oct 2003 19:33:23 -0600
Anyone care to weigh in on either method, or propose a sexier
solution?
closure dispatch is fine. personally, i like to use keywords instead of
symbols since emacs displays them in a different face, but ymmv.
thi
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-11-02 13:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-11-01 1:33 Multiple implementations of low-level functions Michael J. Barillier
2003-11-01 4:45 ` Keith Wright
2003-11-02 13:48 ` Thien-Thi Nguyen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).