Graphical representation in Dr Scheme

I want to submit a graph to Dr. Scheme as follows:

For each node, I want to keep its value and a list of neighboring nodes, the problem that I'm having difficulties with is that I want neighboring nodes to be saved as links to other nodes.

For example: I want node ny to be saved as ("NY" (lp)), where l and p are neighboring nodes, and not like ("New York" ("London", "Paris")).

+3
source share
1 answer

The answer depends on whether you want cycles or not - communicating with them can complicate the situation. But if you want to make a presentation using only lists, then it sharedis your friend. For instance:

(shared ([NY     (list "NY"     (list London Paris))]
         [Paris  (list "Paris"  (list NY))]
         [London (list "London" (list NY))])
  (list NY Paris London))

If your goal is to actually write “real” code, then using your own structures will be much better than lists (but then sharedit won’t work).

In the case of using promises, loops become easier to do just with help letrec. Here's what it would look like in this case:

(letrec ([NY     (list "NY"     (delay (list London Paris)))]
         [Paris  (list "Paris"  (delay (list NY)))]
         [London (list "London" (delay (list NY)))])
  (list NY Paris London))

Alternatively, you can wrap delayaround each appearance of the city inside the lists.

+3
source

Source: https://habr.com/ru/post/1743894/


All Articles