I have a list of objects in Scheme. Each object in turn is a list itself. I am using the map function to iterate over all the elements of the list and apply a function to them. However, I want to apply that function only if the element of the list satisfies some criteria. In C++ that would be something like this:
for(i=0; i<=n; i++)
{
if(criteria(list[n]))
//do something
}
How do I do this in Scheme? Right now, I am using the map function like this:
(map create-evaluation-link parse)
Where create-evaluation-link is a function and parse is the list.
forloops is often an indicator of imperative-style code. There may be a way to do things more functionally depending on what you're attempting to do. That said, Racket hasforloops and list comprehensions, though that's obviously a different dialect. - Alexis Kingcriteriais(lambda (l) (even? (length l))), your input list is((3 2 1) (2 1) (4 3 2 1)), do you want to be able to pass a function likecarand get(2 4)as the result, or((3 2 1) 2 4), or pass a procedure which has some side effect and gets run on the latter two? - Brian Campbellcreate-evaluation-linkto the elements. Nothing more. In your example, I would want to apply my function only to(2 1)and(4 3 2 1). - Rohit Shinde