1

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

  • I'm not familiar with the language so can't answer but as a general rule, you should mention what you're getting as well as what you want to get (be that different output or an error) – Basic Nov 24 '12 at 21:20
  • You are starting at index 1 instead of 0? (index 0 is the 'S') – ffffff01 Nov 24 '12 at 21:54
  • 1
    @f01 Mathematica uses 1-based indexing. – David Z Nov 25 '12 at 03:34

1 Answers1

4

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.

David Z
  • 128,184
  • 27
  • 255
  • 279
  • 1
    @user1709828 the simplest solution is to avoid using `InputForm` except for wrapping something for display. If you want all your output, or something in particular, to always show in `InputForm` there are several ways to handle that – Rojo Nov 24 '12 at 22:03
  • @ Rojo, I want to use the output of each remaining elements of Drop[InputForm[Characters["SOMETHING"]],1] and use in ToCharacterCode, which requires input in " " form. and I am trying to achieve it through InputForm. –  Nov 24 '12 at 22:31
  • @user1709828 still, not a good reason to use `InputForm`. To convert back to a string you want `StringJoin`, or for this particular case you could just apply `ToCharacterCode` directly to the string and then use `Drop` on the result of that (because `ToCharacterCode` gives a list). – David Z Nov 25 '12 at 03:34