Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
It's been mentioned a couple times that it would be nice if strings acted like arrays of characters.

I agree that would be great for many things, but worry about the ramifications in the details.

So, if we decide not to present a string as list magically or in a consistant manner across all the builtins, here is a light-duty idea.

Right now, we split on empty to break into a list of chars. First we need split to specify u0,u1,u2, etc. Second, if split simply produced a lazy list rather than doing it all up front, that would satisfy the people who hate using split but wish it was more direct. Third, some syntactic sugar could be used, such as a special symbol or even a named sub that takes one argument. E.g. map { whatever } unravel($x).

So, does the existance of lazy lists / generators take care of 90% of the issues that made people wish for strings-as-arrays? We can make a (lazy) array out of a string to suit the job, whenever we need.

—John


In reply to Are strings lists of characters? by John M. Dlugosz

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 wandering the Monastery: (2)
As of 2024-04-25 20:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found