# Get correct value

Posted 8 years ago
6396 Views
|
|
0 Total Likes
|
 Hello, I am trying to handle Associations.  c = <|w -> 1, t -> <|r -> 2, m -> 3|>|> I am using a function in order to print out the values calculate2[a_Association] := (Print[a];) calculate2[else_] := else this commando: calculate2 //@ c // InputForm; results in:  <|r->2,m->3|> <|w->1,t->Null|> I am confused about the 'Null', what I need is  <|w->1,t-> <|r->2,m->3|>|> I think the problem is that the value for t is also an association(?). Is there a workaround? The list c is just a small example, I have to work with larger lists (more than 3 hierarchy-levels). Later on I have to work with the input a (not only Print statements).Thanks! Gordon
 You see the result of Print, which is Null. In:= Print["Mary had a little lamb."] During evaluation of In:= Mary had a little lamb. In:= %37 === Null Out= True To see something, one has to give it after printing In:= Clear[calculate3] calculate3[a_] := (Print[a]; a) /; AssociationQ[a] calculate3[a_] := a /; ! AssociationQ[a] In:= calculate3 //@ c During evaluation of In:= <|r->2,m->3|> During evaluation of In:= <|w->1,t-><|r->2,m->3|>|> Out= <|w -> 1, t -> <|r -> 2, m -> 3|>|> Now you see that your function calculate is highly questionable. One gets the keys of an association with Keys and the values with Values, usually. Printing as well as InputForm are very bad data handling ideas, because they are wrappers: with other words, you can not continue working on their results.