Search code examples
wolfram-mathematicamathematica-8

Confusion in String Manipulation


InputForm[{a, b, c, d, e, f}] gives {a, b, c, d, e, f}

InputForm[Characters["SOMETHING"]] gives {"S", "O", "M", "E", "T", "H", "I", "N", "G"}

But why does not Drop[InputForm[Characters["SOMETHING"]],1] give {"O", "M", "E", "T", "H", "I", "N", "G"}

but gives a InputForm[] and nothing else?

How can I achieve this?

Thank You


Solution

  • When you evaluate

    InputForm[Characters["SOMETHING"]]
    

    Mathematica internally produces the result

    InputForm[List["S","O","M","E","T","H","I","N","G"]]
    

    i.e. it's an expression with InputForm as a head, which contains ListList["S","O","M","E","T","H","I","N","G"] as its first subexpression. You don't see the InputForm head when Mathematica displays the expression, because the front end only uses it as a hint as to how the expression should be shown, but it's still there behind the scenes.

    Then when you use Drop[..., 1], it looks at the expression it's given, picks out the first subexpression, which is List["S","O","M","E","T","H","I","N","G"], and discards it. That leaves just InputForm[].

    To make an analogy: if you evaluated

    Drop[List[List["S","O","M","E","T","H","I","N","G"]], 1]
    

    you would understand why you'd get an empty list back, right? It's the same thing going on.