Thursday, 12 September 2013

Mapping together symbols to values then returning a procedure to look up a value ( racket )

Mapping together symbols to values then returning a procedure to look up a
value ( racket )

I have been stumped with this for a few days now. Here is what I'm trying
to do:
Let's say I have some list of symbols. Eg. '(A B C D). I want to map those
symbols to values. Let's say my values are '(1 2 3 4).
Alright now here's the goal. I want to write a procedure that will return
a procedure I can call again later. This is what I mean:
(define get-mapped-value (map-together symbols values))
(get-mapped-value 'A)
should return '1.
So far I have written a procedure to take two lists and "zip" them
together, basically mapping values. So given '(A B C D) and '(1 2 3 4) it
will return ((A 1)(B 2)(C 3) and so on.
And I also wrote a procedure that given a symbol will return its mapped
value. But I am having trouble tying this all up and being able to make
that definition. My most recent attempt was:
(define map-together
(case-lambda
[(symbols vals) (lambda (cons lst (zip-together keys vals))]
[(symbol) (find-mapped-value symbol)]
)
)
)
but that just returns the zipped list.

No comments:

Post a Comment