title: Key-value lookup from a pair of lists in a makefile
body: <p>In my makefile, I need to retrieve values from a value list given keys which match a key list. The lists are correctly ordered with respect to each other.</p>
  <p>I have a recipe that works, but it uses a shell command to do the heavy lifting:</p>
  <pre><code>KEYS=key1 key2 key3 key4 key5
  VALUES=val1 val2 val3 val4 val5
  
  # keys to lookup, we want our results to be: val2 val4
  LOOKUPS=key2 key4
  
  define CMD
  LOOKUPS=($(1)); \
  KEYS=($(2)); \
  VALUES=($(3)); \
  for i in $${!LOOKUPS[@]}; do \
      for j in $${!KEYS[@]}; do \
          if [[ &quot;$${LOOKUPS[$$i]}&quot; ==  &quot;$${KEYS[$$j]}&quot; ]]; then \
              echo &quot;$${VALUES[$$j]}&quot;; \
          fi; \
      done; \
  done
  endef
  
  RESULTS=$(shell $(call CMD,$(LOOKUPS),$(KEYS),$(VALUES)))
  $(info RESULTS: $(RESULTS))
  </code></pre>
  <p>Is there a way of doing this without using the shell? Perhaps involving GMSL's pairmap function? Or a better shell based recipe?</p>