# Mapping between lists and Mapping Formats

I've been writing a conversion 'script' between two robot description formats and thought I would try out Mathematica as I thought it sounded pretty awesome. Although by this point I should have done it manually!

I'm sure there's a much better way to do the entire mapping process. I had trouble trying to apply the mappings from the elements between the joints and the links. I had tried using variations on Rule @@ ConnectionsOrder, with various operators /., //, @@, @@@ /@

1. Is there a more idiomatic implementation of the below?

Since Mathematica is symbolically based, I thought something may exists where you can define a format, and then specifying another and some rules to convert and having everything work nicely. Does such a thing exist? - I have been text wrangling to basically manually convert the files.

jointsOrder = {"HAA", "HFE", "KFE", "WHEEL"};
linksOrder = {"BASE", "HIP", "THIGH", "shank_fixed", "WHEEL_L"};
connections =
BlockMap[Apply[Rule], Flatten[Subsequences[connectionsOrder, {2}]],
2]

• Thread[LinksOrder[[1 ;; Length[JointsOrder]]] -> JointsOrder] Commented Mar 18, 2020 at 22:56

BlockMap can do more of the work than you are allowing it to:

BlockMap[Apply[Rule], connectionsOrder, 2, 1]

{"BASE" -> "HAA", "HAA" -> "HIP", "HIP" -> "HFE", "HFE" -> "THIGH",
"THIGH" -> "KFE", "KFE" -> "shank_fixed", "shank_fixed" -> "WHEEL",
"WHEEL" -> "WHEEL_L"}

• For the second part of my question do you know of / point me to a tutorial/manpage of a general method for converting between structured formats?
– ixil
Commented Mar 19, 2020 at 15:47
• @ixil There is Manipulating Lists and Expressions. Browsing top questions in list-manipulation and expression-manipulation would be useful too. Commented Mar 19, 2020 at 17:19
Partition[connectionsOrder, 2, 1, {1, -1}, {}, Rule]

{"BASE" -> "HAA", "HAA" -> "HIP", "HIP" -> "HFE", "HFE" -> "THIGH",
"THIGH" -> "KFE", "KFE" -> "shank_fixed", "shank_fixed" -> "WHEEL",
"WHEEL" -> "WHEEL_L"}


or

Rule @@@ Partition[connectionsOrder, 2, 1]

{"BASE" -> "HAA", "HAA" -> "HIP", "HIP" -> "HFE", "HFE" -> "THIGH",
"THIGH" -> "KFE", "KFE" -> "shank_fixed", "shank_fixed" -> "WHEEL",
"WHEEL" -> "WHEEL_L"}


Also

EdgeRules @ PathGraph @ connectionsOrder

{"BASE" -> "HAA", "HAA" -> "HIP", "HIP" -> "HFE", "HFE" -> "THIGH",
"THIGH" -> "KFE", "KFE" -> "shank_fixed", "shank_fixed" -> "WHEEL",
"WHEEL" -> "WHEEL_L"}

• I notice you are omitting the quote markdown in the output formatting. Now that the block style is not the "ugly yellow" I think you should consider using it, as the syntax highlighting is useful IMHO. Commented Mar 18, 2020 at 23:54
• Thank you @Mr.Wizard; very good suggestion.
– kglr
Commented Mar 19, 2020 at 0:04
• I see you figured out I meant "code markdown" -- it's the quote block that is no longer yellow. Anyway the form you have now seems like a good one and an alternative to the one I use. Do you prefer its appearance? Commented Mar 19, 2020 at 0:12
• @Mr.Wizard, yours look better. Is there a way to do the line wrapping (I had to break the code into lines manually)?
– kglr
Commented Mar 19, 2020 at 0:24
• Do you mean basic line wrapping, or breaks at specific points? This usually handles the former, but I do tend to manually edit breaks when it looks better. Commented Mar 19, 2020 at 4:34