From e5ca0bc5e1af45b6dbcfecd47787e952a7fea774 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Tue, 29 Aug 2017 09:18:39 +0100 Subject: [PATCH] [functional-tests] add indirect-lambda/set-lambda! to (utils) --- functional-tests/utils.scm | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/functional-tests/utils.scm b/functional-tests/utils.scm index 8ef55df..7778fa7 100644 --- a/functional-tests/utils.scm +++ b/functional-tests/utils.scm @@ -4,7 +4,11 @@ dec! swap! slurp-file - chomp) + chomp + hotpatch-sym + indirect-lambda + set-lambda!) + (import (chezscheme) (only (srfi s1 lists) drop-while)) @@ -40,4 +44,19 @@ (drop-while char-whitespace? (reverse (string->list line)))))) + (define hotpatch-sym (gensym)) + + (define-syntax indirect-lambda + (syntax-rules () + ((_ params b1 b2 ...) + (let ((this (lambda params b1 b2 ...))) + (lambda args + (if (and (= (length args) 2) + (eq? (car args) hotpatch-sym)) + (set! this (cadr args)) + (apply this args))))))) + + (define (set-lambda! fn new-fn) + (fn hotpatch-sym new-fn)) + )