I'm stuck in the middle of my project. I have a list of lists like:
'((a for apple) (b is book) (c in cat) (ronn live in NY))
Now I want to make a query in the form of a list and have it display the correct entry in my list of lists. For example, if I input '(a for what)
or '(what in cat)
it will display (a for apple)
or (c in cat)
. If I input '(ronn live in where)
it will show (ronn live in NY)
.
Can anyone help me solve this problem?
How about running a
filter
routine across the list, and using a lambda object initialized with your query information that will then be applied to the list until it finds a match.So for instance, you would have a lamda that would look something like
Now with the
filter-object
initialized, run a filter across your listThis should return a one-element list of the matches (providing you aren't placing more than one copy in your list set.
Hope this helps,
Jason
Structure and Interpretation of Computer Programs, Video Lectures by Hal Abelson and Gerald Jay Sussman
Lecture 4a, Pattern Matching and Rule-based Substitution