0
$\begingroup$

In the Virtual Book of Mathematica, there is a simple example to show how to create lists of strings by List:

List[{"a", "b", "c"}, {"you", "are", "good"}]

here " " indicates these strings, which is easy to understand.

However, if we use

List[{a, b, c}, {you, are, good}]

instead, we can find that both codes give the same result:

{{a, b, c}, {you, are, good}}

So my questions:

  1. Whether or not the two codes are different with respect to the output of their results. If yes, what is(are) the difference(s)?

  2. Whether or not the two codes are exactly the same in the context of a program?

Thank you in advance.

$\endgroup$
6
  • 2
    $\begingroup$ Move your cursor into the output cell and type something to reveal the quotes. Mathematica hides quotes in outputs by default (I don't know why) $\endgroup$
    – Szabolcs
    Dec 10, 2018 at 11:48
  • 2
    $\begingroup$ Your first List creates a list of strings, the second a list of actual undefined variables $\endgroup$ Dec 10, 2018 at 11:49
  • 3
    $\begingroup$ Output cells, you see the results in, have ShowStringCharacters->False so no, they are not the same. Take a loot at FullForm. p.s. List[1] vs {1} is only a syntactic sugar, again compare with FullForm. $\endgroup$
    – Kuba
    Dec 10, 2018 at 11:50
  • 2
    $\begingroup$ With respect to question 2, if you're ever wondering if two things are precisely identical in Mathematica, SameQ (===) works for that. $\endgroup$
    – eyorble
    Dec 10, 2018 at 12:06
  • $\begingroup$ @Kuba Thanks a lot. Could you suggest how do I see that output cells have the property of ShowStringCharacters->False? $\endgroup$
    – lxy
    Dec 10, 2018 at 13:59

1 Answer 1

2
$\begingroup$

With

l1 = List[{"a", "b", "c"}, {"you", "are", "good"}];
l2 = List[{a, b, c}, {you, are, good}];

1. Whether or not the two codes are different with respect to the output of their results. If yes, what is(are) the difference(s)?

One way to see that they are different is the following:

l1 // FullForm
l2 // FullForm

l1

l2

Addressing the comment: Could you suggest how do I see that output cells have the property of ShowStringCharacters->False

From the docs we read:

ShowStringCharacters is an option for Cell that specifies whether to display " when a string is entered.

So, you can set it to True for both lists and check for which one you will get the "" like so:

ExpressionCell[l1, "Output", ShowStringCharacters -> True]
ExpressionCell[l2, "Output", ShowStringCharacters -> True]

out1

out2

2.Whether or not the two codes are exactly the same in the context of a program?

When you run

l1 === l2

you get

false

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.