0

I am having trouble figuring out how to access specific pair information in Racket.

Say I am given some list like this:

(define database-of-components
'((p1 200 (2 p2) (3 p3))
(p2 8 (2 p4))
(p3 60 (1 p5) (2 p6) (3 p7))
(p4 2)
(p5 2)
...
))

How am I able to access the data contained in some individual pn? Say I am trying to get just 200 from p1 or just 60 from p3... how might I do this?

Note: This is obviously for a homework assignment but this question is just to get started.

1 Answer 1

2

Look up assq and friends (assoc, assv):

> (assq 'p1 database-of-components)
'(p1 200 (2 p2) (3 p3))
> (second (assq 'p1 database-of-components))
200
> (second (assq 'p3 database-of-components))
60
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.