in reply to Re^2: Representing all data as Lists
in thread Representing all data as Lists (Perl7?)

It's kind of funny, because my feelings are the opposite of what blokhead describes in the last paragraph of Re^3: Representing all data as Lists; I'd actually be more inclined to support unifying the internals than changing the interface, though I don't really think either is a very good idea.

Like I said (or maybe I should have said more clearly) in my original reply, I think different things should look different. You may say the corollary is that alike things should like similar -- and I'd agree -- but in this case I dont' think a string and a list are things that are really all that alike. I can understand why someone would say they are, but I think it's a contrived likeness.

I strongly agree with Perl's current notion that a string is an individual thing (i.e. a scalar). I don't often have the need to break that thing apart and operate on its individual characters (Update: a clarification of what I meant). Perhaps that's a learned trait, but I tend to think it's more likely that instinctively seeing a string as a list is less natural.

In the case of hashes, I don't feel as strongly as I do about strings. Hashes are very list-like already, and as you pointed out, you can already coerce a list into a hash. That's a pretty natural-feeling thing, in my eyes. I still think a hash is different enough from a plain list that it deserves its own syntax and sigil, though. And Perl 6 will make it pretty easy to get a list of pairs, or a list of interwoven keys/values:

my %hash = <one 1 two 2 three 3>; say $_.join(" ") for %hash.pairs; # output: # one 1 # three 3 # two 2 say for %hash.kv; # output: # one # 1 # three # 3 # two # 2

Replies are listed 'Best First'.
Re^4: Representing all data as Lists
by Anonymous Monk on Sep 20, 2005 at 20:29 UTC
    I strongly agree with Perl's current notion that a string is an individual thing (i.e. a scalar). I don't often have the need to break that thing apart and operate on its individual characters.
    I think most Perl programmers would disagree with that notion. Especially since Perl is one of the few languages which has elevated fold/spindle/mutilate of strings into a language construct. Of course I'm talking about Perl's pattern matching facility (A.K.A. regex, but they're really not regular in the theoretical sense).

      I think you misunderstood me. I could have said what I meant more clearly. I was trying to say that Perl programmers have a lot of ways to slice and dice text, and operating on strings as a bag of characters is one of the ways I use probably least often. Your mention of regular expressions really bolsters the point I was trying to make.