diff --git a/parse.scm b/parse.scm index f36e89b..3f964c0 100644 --- a/parse.scm +++ b/parse.scm @@ -42,6 +42,33 @@ search-name)])))) (define contains-ingredient? - (lambda (recipe ingredient) + (lambda (recipe search-ingredient) (let ((ingredients (ingredients recipe))) - (ingredient-by-name ingredients ingredient)))) + (ingredient-by-name ingredients search-ingredient)))) + +(define contains-ingredients? + (lambda (recipe search-ingredients) + (let ((ingredients (ingredients recipe))) + (cond [(null? search-ingredients) #t] + [(ingredient-by-name ingredients + (car search-ingredients)) + (contains-ingredients? recipe + (cdr search-ingredients))] + [else #f]) + ))) + +(define recipes-by-ingredients + (lambda (recipes search-ingredients list) + (if (null? recipes) + list + (let* ((recipe (car recipes)) + (ingredients (ingredients recipe)) + (contains? (contains-ingredients? recipe + search-ingredients))) + (if contains? + (recipes-by-ingredients (cdr recipes) + search-ingredients + (cons recipe list)) + (recipes-by-ingredients (cdr recipes) + search-ingredients + list))))))