reduced code duplication in recipes-by-ingredients and contains-ingredients?
This commit is contained in:
parent
ba43937232
commit
ba8dc20964
20
parse.scm
20
parse.scm
|
@ -43,8 +43,7 @@
|
||||||
|
|
||||||
(define contains-ingredient?
|
(define contains-ingredient?
|
||||||
(lambda (recipe search-ingredient)
|
(lambda (recipe search-ingredient)
|
||||||
(let ((ingredients (ingredients recipe)))
|
(contains-ingredients? recipe (cons search-ingredient '()))))
|
||||||
(ingredient-by-name ingredients search-ingredient))))
|
|
||||||
|
|
||||||
(define contains-ingredients?
|
(define contains-ingredients?
|
||||||
(lambda (recipe search-ingredients)
|
(lambda (recipe search-ingredients)
|
||||||
|
@ -58,17 +57,20 @@
|
||||||
)))
|
)))
|
||||||
|
|
||||||
(define recipes-by-ingredients
|
(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)
|
(lambda (recipes search-ingredients list)
|
||||||
(if (null? recipes)
|
(if (null? recipes)
|
||||||
list
|
list
|
||||||
(let* ((recipe (car recipes))
|
(let* ((recipe (car recipes))
|
||||||
(ingredients (ingredients recipe))
|
(ingredients (ingredients recipe))
|
||||||
(contains? (contains-ingredients? recipe
|
(contains? (contains-ingredients? recipe
|
||||||
search-ingredients)))
|
search-ingredients))
|
||||||
(if contains?
|
(new-list (if contains?
|
||||||
(recipes-by-ingredients (cdr recipes)
|
(cons recipe list)
|
||||||
|
list)))
|
||||||
|
(recipes-by-ingredients-rec (cdr recipes)
|
||||||
search-ingredients
|
search-ingredients
|
||||||
(cons recipe list))
|
new-list)))))
|
||||||
(recipes-by-ingredients (cdr recipes)
|
|
||||||
search-ingredients
|
|
||||||
list))))))
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user