turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Associative Arrays in Graph Theory Example?

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Dec 1, 2015 5:15 AM
(769 views)

Hi All,

Am I missing something? As described below, the result I get differs from what is shown in the *Scripting Guide. *(I'm new to JMP, but I already asked one experienced user and he was stumped too.)

I copied and pasted the following code from the Associative Arrays in Graph Theory example (pages 215 and 216 of the *Scripting Guide* for 12.1).

g = Associative Array();

g[1] = Associative Array( {1, 2, 4} );

g[2] = Associative Array( {1, 3} );

g[3] = Associative Array( {4, 5} );

g[4] = Associative Array( {4, 5} );

g[5] = Associative Array( {1, 2} );

dfs = Function( {ref, node, visited}, Local( {chnode, tmp},

Write( "Node: " || Char( node ) || ", " || Char( ref[node] << get contents ) || "\!N" );

visited[node] = 1;

tmp = ref[node];

chnode = tmp << first; While( !Is Missing( chnode ),

If( !visited[chnode],

visited = Recurse( ref, chnode, visited )

);

chnode = tmp << next( chnode ); );

visited; )

);

dfs( g, 2, J( N Items( g << get keys ), 1, 0 ) );

The book shows the following result:

**Node 2: {1, 3} **

**Node 1: {1, 2, 4} **

**Node 4: {4, 5} **

**Node 5: {1, 2} **

**Node 3: {4, 5} **

**[1, 1, 1, 1, 1]**

I get this result:

**Node: 2, {{1, 1}, {3, 1}}**

**Node: 1, {{1, 1}, {2, 1}, {4, 1}}**

**Node: 4, {{4, 1}, {5, 1}}**

**Node: 5, {{1, 1}, {2, 1}}**

**Node: 3, {{4, 1}, {5, 1}}**

**[1, 1, 1, 1, 1]**

Any suggestions?

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Solution

The doc is wrong. Thanks for reporting it. Replacing "get contents" with "get keys" will produce the provided output.

2 REPLIES

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Dec 1, 2015 10:28 AM
(666 views)