From 10f2225bdd2817558164ae7686256695da8756d7 Mon Sep 17 00:00:00 2001 From: Victor Fors Date: Tue, 19 Apr 2022 18:12:48 +0200 Subject: [PATCH] refactoring --- parking.scm | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/parking.scm b/parking.scm index 9902d9e..1d65e2a 100644 --- a/parking.scm +++ b/parking.scm @@ -9,9 +9,18 @@ (lambda (b) (fn a b))) +(define (curry2 fn a b) + (lambda (c) + (fn a b c))) + (define (perhaps fn a) (if a (fn a) a)) +(define (upon pred? fn a) + (if (pred? a) + (fn a) + a)) + (define (member? a ln) (if (member a ln) #t #f)) @@ -43,10 +52,7 @@ (define (format-assoc statement ln) (apply string-append - (map (lambda (directive) - (if (symbol? directive) - (->string (value directive ln)) - directive)) statement))) + (map (curry2 upon symbol? (compose ->string (curry (flip value) ln))) statement))) (define (simple-json-request uri) (with-input-from-request uri #f read-json))