Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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


In reply to Representing all data as Lists (Perl7?) by rje

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-26 01:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found