From cc3cd7c19f9593e0633396062340cf586b62952f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoffer=20M=C3=BCller=20Madsen?= Date: Wed, 5 Apr 2017 15:08:16 +0200 Subject: [PATCH] reduce code size of recipes-by-ingredients by using 'filter' --- parse.scm | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/parse.scm b/parse.scm index 55922ad..54cea99 100644 --- a/parse.scm +++ b/parse.scm @@ -63,19 +63,5 @@ (define recipes-by-ingredients (lambda (recipes search-ingredients) - (recipes-by-ingredients-rec recipes search-ingredients '()))) - -(define recipes-by-ingredients-rec - (lambda (recipes search-ingredients list) - (if (null? recipes) - list - (let* ((recipe (car recipes)) - (ingredients (ingredients recipe)) - (contains? (contains-ingredients? recipe - search-ingredients)) - (new-list (if contains? - (cons recipe list) - list))) - (recipes-by-ingredients-rec (cdr recipes) - search-ingredients - new-list))))) + (filter (lambda (x) (contains-ingredients? x search-ingredients)) + recipes)))