# [plt-scheme] dynamically varying the definitions used by a procedure

 From: David J. Neu (djneu at att.net) Date: Wed Sep 29 19:31:14 EDT 2004 Previous message: [plt-scheme] Non-blocking single character read in DrScheme? Next message: [plt-scheme] dynamically varying the definitions used by a procedure Messages sorted by: [date] [thread] [subject] [author]

```Hello all,

I have an application in which I'd like to be able to run a procedure,
(in the example below, the execute procedure) and to have the
variables, procedures, etc. that are used by the procedure vary - with
different definitions of the variables, procedures, etc. being loaded
from disk.

I was wondering if someone could let me know if there is a better way
to handle the following situation, than the way I'm doing it in the
following toy example?

The example contains three files: test.ss, euclidean.ss and hamming.ss.

Many thanks!
--David

;; *** start: test.ss ****
(define dbms
'((euclidean . "euclidean.ss")
(hamming . "hamming.ss")))

(define execute
(lambda (arequest)
(let ((lfilename (assq arequest dbms)))
(if lfilename
(begin
(load (cdr lfilename))
(printf "~a~n" (f x y)))
(error (format "request ~a not found~n" arequest))))))

(execute 'euclidean)
(execute 'hamming)
;; *** end: test.ss ****

;; *** start: euclidean.ss ****
(define x '(2 5 7))

(define y '(1 0 2))

(define square
(lambda (ax)
(* ax ax)))

(define f
(lambda (ax ay)
(sqrt
(+ (square (- (car ax)  (car ay)))
(square (- (cadr ax)  (cadr ay)))
(square (- (caddr ax)  (caddr ay)))))))
;; *** end: euclidean.ss ****

;; *** start: hamming.ss ****
(define x '(1 0 0))

(define y '(1 0 1))

(define hamming
(lambda (ax ay)
(+  (- (car ax)  (car ay)))
(- (cadr ax)  (cadr ay))
(- (caddr ax)  (caddr ay))))
;; *** end: hamming.ss ****

```

 Posted on the users mailing list. Previous message: [plt-scheme] Non-blocking single character read in DrScheme? Next message: [plt-scheme] dynamically varying the definitions used by a procedure Messages sorted by: [date] [thread] [subject] [author]
{"ft_lang_label":"__label__en","ft_lang_prob":0.7600626,"math_prob":0.63905823,"size":1468,"snap":"2021-21-2021-25","text_gpt3_token_len":420,"char_repetition_ratio":0.14002733,"word_repetition_ratio":0.008298756,"special_character_ratio":0.34673023,"punctuation_ratio":0.16725978,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99037904,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-06-24T06:19:46Z\",\"WARC-Record-ID\":\"<urn:uuid:8b2ddda4-530b-4848-b16a-49f7f010cb7d>\",\"Content-Length\":\"7726\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:0d36991d-86a9-41cf-b97c-04f77e190ef5>\",\"WARC-Concurrent-To\":\"<urn:uuid:e505860b-82e1-490c-a012-b13bd2279f9d>\",\"WARC-IP-Address\":\"104.21.48.235\",\"WARC-Target-URI\":\"https://lists.racket-lang.org/users/archive/2004-September/006747.html\",\"WARC-Payload-Digest\":\"sha1:HJHEHHWGIZYIA7G35ZNFRREWVKF7V4MK\",\"WARC-Block-Digest\":\"sha1:6R4R52TMNAXYVIC5WFQ36K4UG4VTECC5\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-25/CC-MAIN-2021-25_segments_1623488551052.94_warc_CC-MAIN-20210624045834-20210624075834-00397.warc.gz\"}"}