0
|
3121 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
GROUPS:

# Why is AppendTo "Squaring My Strings" Making the Result Power?

Posted 10 years ago
 Does anyone know why this is happening? When I append to a list using the function below Mathematica is "squaring" each of the elements in the list. When I change to using Append I get the following alternate output "Thread::tdlen: Objects of unequal length in {emptyList,{,,Subframe,-18.47,,5,D}} {emptyList} cannot be combined. >>" See code below. thanks (* Test Function*) myFunction[aLine_, sf_] := Module[{theList, theSF}, theList = {"emptyList"}; theSF = StringJoin[{"*"}, sf, {","}, {"D"}]; If[StringMatchQ[aLine, theSF], AppendTo[theList, {aLine}]] (* if aLine contains the sub-string append to the list *) theList ]; (* Test Case *) testString = ",,Subframe,-18.47,,5,D"; theResult = myFunction[testString, "5"] Head[theResult] theResult[[1]] Head[theResult[[1]]] (* Unexpected Output *) {("emptyList")^2, {(",,Subframe,-18.47,,5,D")^2}} List (emptyList)^2 Power (* Expected Ouput *) {("emptyList"), {(",,Subframe,-18.47,,5,D")}} 
2 Replies
Sort By:
Posted 10 years ago
 Excellent - that's it!! It would be nice if there were some sort of a notebook profiling tool that would allow the user to "single step" through lines in a cell to help detect this sort of an issue.thanks for the quick (and accurate) response.
Posted 10 years ago
 The space between If[ ] and theList (where the comment is) gets interpreted as multiplication. Try adding a semicolon after the If[ ].