I was re-reading Paul Graham's web articles (
http://paulgraham.com/hundred.html) and thinking about how Perl might adapt for computers with processing power many orders of magnitude better than what we have. I wasn't thinking practically, nor particularly critically, but I was thinking about it with Paul's LISPoCentric view.
Imagine the runtime inefficiency (yet potential elegance) of treating strings as lists of characters -- or references to lists of characters -- and treating hashes as lists of list-pairs. You know how, in Perl, you declare a hash as a flat array, and Perl sorts it out for you? What if, in the future, Perl actually stores all data internally as lists?
Something strange I've just realized is how completely I've forgotten that strings really
are "arrays" in C. "Modern" languages have taught me to forget the internal representation of strings and treat them as atomic.
One odd thing about strings being represented internally as lists is that the quote characters become an alias for list declaration.
Another odd thing is that sigils might converge.
Imagine my blurry view of Perl7. Pardon my lack of semicolons, I'm seeing what it would feel like to not use them all the time in Perl.
It turns out there are lots of things that might cause problems (maybe because I'm too used to thinking of scalars as strings) that might be remedied by throwing out the $ sigil and using the @, or, alternately, trying to remember that everything's a reference to a list. Or something.
It occurs to me that this behavior might be implemented today with a module. I'll have to think about this a bit. I've never written a module that fundamentally changes the look (or behavior) of the language.
It would feel strange calling split() on a list.
use strict
my @baz = 'hello there' # this is a list
print @baz[0] # => h
print @baz[6] # => t
my @foo = [ 'hello', 'there' ] # this is a list of 2 lists
@foo = split ' ', @baz # so is this?
print @foo # => "hellothere"
print len @foo # => 2
print @foo[0][1,3,4] # => "elo"
print @foo[1][3..5] # => "ere"
push @foo, 'how', 'are', 'you?'
@foo[0,3] = [ 'goodbye', 'were' ]
#
# Why would you "emulate" a hashmap using lists?
# Would a list of pairs work?
# Sorting a hash automagically sorts by keys?
#
my @bar =
{
'a' => 1,
'b' => 2,
'c' => 3
}
#
# is perhaps translated to the access-inefficient:
#
# my @bar = [ [ 'a', 1 ], [ 'b', 2 ], [ 'c', 3 ] ]
#
# do we assume hash access looks the same?
print @bar{a} # => 1
@foo = @bar{a,b,c} # => [ 1, 2, 3 ]
print @foo # => 123
print join ',', @foo # => 1,2,3
print join ',', @bar # => ???
Edit by castaway - swapped pre tags for code tags
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.