reverse #succ ?

Discussion in 'Ruby' started by trans. (T. Onoma), Oct 27, 2004.

  1. Is there a reverse #succ for String? If not, could there be?

    T.
    trans. (T. Onoma), Oct 27, 2004
    #1
    1. Advertising

  2. trans.  (T. Onoma)

    Hal Fulton Guest

    trans. (T. Onoma) wrote:
    > Is there a reverse #succ for String? If not, could there be?


    It's one of those things that looks easy until you try it.

    There are too many "edge cases" that require judgment about how
    to generate the next value.

    Search the archives, it's been discussed off and on for five years.


    Hal



    PS - Are the archives up again yet??
    Hal Fulton, Oct 27, 2004
    #2
    1. Advertising

  3. the blade list archive (Re: reverse #succ ?)

    Hi,

    In message "Re: reverse #succ ?"
    on Wed, 27 Oct 2004 14:17:13 +0900, Hal Fulton <> writes:

    |PS - Are the archives up again yet??

    It's up now.

    The list archive hosted in the Nagaoka University of Technology, which
    is recently hit by severe earthquake in Niigata prefecture, Japan.
    The archive maintainer, Shin-ichiro Hara, told us that he and his
    family were safe. So were the machines at his office.

    matz.
    Yukihiro Matsumoto, Oct 27, 2004
    #3
  4. On Wednesday 27 October 2004 01:17 am, Hal Fulton wrote:
    | trans. (T. Onoma) wrote:
    | > Is there a reverse #succ for String? If not, could there be?
    |
    | It's one of those things that looks easy until you try it.
    |
    | There are too many "edge cases" that require judgment about how
    | to generate the next value.
    |
    | Search the archives, it's been discussed off and on for five years.

    Thanks and yes the archives are back up. I found a few hits. I see the
    problem. Though, I don't really care if it's a one-to-one match to #succ. I
    would just prefer that my Range#reverse_each method doesn't blow up ;)
    Certainly there must a basic #pred method that makes sense.

    Then again how much use does String#succ actually get? And what for? Can
    anyone really give a use case truly dependent on the specific current
    behavior? Would it make more sense if it were simply an ascii "dial", within
    a particular range of characters? And perhaps too that particular range could
    have a redefinable specal global.

    T.
    trans. (T. Onoma), Oct 27, 2004
    #4
  5. Re: the blade list archive (Re: reverse #succ ?)

    On Wednesday 27 October 2004 01:41 am, Yukihiro Matsumoto wrote:
    | Hi,
    |
    | In message "Re: reverse #succ ?"
    |
    | on Wed, 27 Oct 2004 14:17:13 +0900, Hal Fulton
    <> writes:
    | |PS - Are the archives up again yet??
    |
    | It's up now.
    |
    | The list archive hosted in the Nagaoka University of Technology, which
    | is recently hit by severe earthquake in Niigata prefecture, Japan.
    | The archive maintainer, Shin-ichiro Hara, told us that he and his
    | family were safe. So were the machines at his office.

    Give him our best then. I know what it can be like. We recently had a couple
    of bad tsunamis in the neck of the woods (Florida).

    T.
    trans. (T. Onoma), Oct 27, 2004
    #5
  6. Re: the blade list archive (Re: reverse #succ ?)

    > |
    > | It's up now.
    > |
    > | The list archive hosted in the Nagaoka University of Technology, which
    > | is recently hit by severe earthquake in Niigata prefecture, Japan.
    > | The archive maintainer, Shin-ichiro Hara, told us that he and his
    > | family were safe. So were the machines at his office.



    here's to the safety of us all. we've been hit by earthquakes recently also.
    --
    edwin eyan moragas

    ha... a... k... tu!
    Edwin Eyan Moragas, Oct 27, 2004
    #6
  7. "trans. (T. Onoma)" <> wrote in message news:<>...
    > On Wednesday 27 October 2004 01:17 am, Hal Fulton wrote:
    > | trans. (T. Onoma) wrote:
    > | > Is there a reverse #succ for String? If not, could there be?
    > |
    > | It's one of those things that looks easy until you try it.
    > |
    > | There are too many "edge cases" that require judgment about how
    > | to generate the next value.
    > |
    > | Search the archives, it's been discussed off and on for five years.
    >
    > Thanks and yes the archives are back up. I found a few hits. I see the
    > problem. Though, I don't really care if it's a one-to-one match to #succ. I
    > would just prefer that my Range#reverse_each method doesn't blow up ;)
    > Certainly there must a basic #pred method that makes sense.
    >
    > Then again how much use does String#succ actually get? And what for? Can
    > anyone really give a use case truly dependent on the specific current
    > behavior? Would it make more sense if it were simply an ascii "dial", within
    > a particular range of characters? And perhaps too that particular range could
    > have a redefinable specal global.
    >
    > T.


    #pred leads to the gates of madness.
    Mr. Fulton is right in that it doesnt sound too hard to
    implement until you try it.

    I have used String#succ to ummm, 'test', the strength of passwords.
    The current implementation doesnt allow that if a password uses more
    printable chars than letters or numbers.

    An ascii 'dial' with a definable, or redefinable, range would be just
    perfect.
    ascci_succ ?
    'z9'.succ => 'aa0'
    'z9'.a_succ => 'z:'

    I just wonder if it should be a 'wheel' or 'dial', or if it should just have
    borders. 'a'.. 'the_end_of_the_line' of printable char range.
    illocutionist, Nov 10, 2004
    #7
  8. (Thanks to all who have taken some time with this and String Range thread.)

    On Tuesday 09 November 2004 10:28 pm, illocutionist wrote:
    | > On Wednesday 27 October 2004 01:17 am, Hal Fulton wrote:
    | > | trans. (T. Onoma) wrote:
    | > | > Is there a reverse #succ for String? If not, could there be?
    | > |
    | > | It's one of those things that looks easy until you try it.
    | > |
    | > | There are too many "edge cases" that require judgment about how
    | > | to generate the next value.
    | > |
    | > | Search the archives, it's been discussed off and on for five years.
    | >
    | > Thanks and yes the archives are back up. I found a few hits. I see the
    | > problem. Though, I don't really care if it's a one-to-one match to #succ.
    | > I would just prefer that my Range#reverse_each method doesn't blow up ;)
    | > Certainly there must a basic #pred method that makes sense.
    | >
    | > Then again how much use does String#succ actually get? And what for? Can
    | > anyone really give a use case truly dependent on the specific current
    | > behavior? Would it make more sense if it were simply an ascii "dial",
    | > within a particular range of characters? And perhaps too that particular
    | > range could have a redefinable specal global.
    | >
    | > T.
    |
    | #pred leads to the gates of madness.
    | Mr. Fulton is right in that it doesnt sound too hard to
    | implement until you try it.

    Almost. I managed to dig up a working #pred method in ruby-talk archives. I
    think robert wrote it (have to check to be sure), but it works well enough,
    given that it would probably never be used ;)

    | I have used String#succ to ummm, 'test', the strength of passwords.
    | The current implementation doesnt allow that if a password uses more
    | printable chars than letters or numbers.
    |
    | An ascii 'dial' with a definable, or redefinable, range would be just
    | perfect.
    | ascci_succ ?
    | 'z9'.succ => 'aa0'
    | 'z9'.a_succ => 'z:'
    |
    | I just wonder if it should be a 'wheel' or 'dial', or if it should just
    | have borders. 'a'.. 'the_end_of_the_line' of printable char range.

    It has become increasing apparent to me that string ranges are of very limited
    use --primarily they seemed to be used just to get a list of letters a-z.
    While I'm sure there are at least a couple cases out there somewhere in which
    the current behavior is quite useful, a number of of alternates have been
    suggested to make it even more so; the general "dial" being one of them.
    Another interesting idea is dictionary-order given a "depth" parameter. For
    instance:

    'a'.succ(1) #=> 'b'
    'z'.succ(1) #=> nil (nothing after z of depth 1)
    'a'.succ(2) #=> 'aa'
    'aa'.succ(2) #=> 'ab'
    'az'.succ(2) #=> 'b'
    'b'.succ(2) #=> 'ba'

    and so forth. Of course other methods would require adjustment to handle the
    parameter, but that is fairly easy to do. No doubt there are other variations
    of a more useful #succ as well.

    Clearly what would be better is some sort of Iterator / Enumerator /
    Generator, perhaps provided by a String class method to which parameters can
    be passed to determine behavior --or perhaps a few such methods. For example,
    one method might be as above:

    sg = String.dict_enum('A-B', 2)
    sg.to_a
    #=> [ 'A', 'AA', 'AB', 'B', 'BA', 'BB' ]

    Speaking of which, if any one has a general purpose string generator, I would
    really love to get a hold of it.

    My overall conclusion is that string ranges have held back the Range class. On
    suby-ruby we have been able to get Range to behave uniformally even with
    string ranges. This required using an alternative comparesion method (#cmp
    instead of #<=>). But given the limited usefulness of the current String#succ
    in contrast to the other useful possibilities for generating a list of
    ordered strings, plus the "headache" it causes Range to support it, it seems
    to me that it might be better just to let it go. Besides, it is easy enough
    to do:

    ?a..?z

    If one needs simple character enumeration.

    Opinions on this are greatly welcome.

    T.

    P.S. Of course, if anyone can figure out a way to create a one-to-one
    correspondence between strings and floats, then we'd have whole new ball game
    on our hands!
    trans. (T. Onoma), Nov 10, 2004
    #8
  9. "trans. (T. Onoma)" <> wrote in message news:<>...
    > (Thanks to all who have taken some time with this and String Range thread.)
    >
    > On Tuesday 09 November 2004 10:28 pm, illocutionist wrote:
    > | > On Wednesday 27 October 2004 01:17 am, Hal Fulton wrote:
    > | > | trans. (T. Onoma) wrote:
    > | > | > Is there a reverse #succ for String? If not, could there be?
    > | > |
    > | > | It's one of those things that looks easy until you try it.
    > | > |
    > | > | There are too many "edge cases" that require judgment about how
    > | > | to generate the next value.
    > | > |
    > | > | Search the archives, it's been discussed off and on for five years.
    > | >
    > | > Thanks and yes the archives are back up. I found a few hits. I see the
    > | > problem. Though, I don't really care if it's a one-to-one match to #succ.
    > | > I would just prefer that my Range#reverse_each method doesn't blow up ;)
    > | > Certainly there must a basic #pred method that makes sense.
    > | >
    > | > Then again how much use does String#succ actually get? And what for? Can
    > | > anyone really give a use case truly dependent on the specific current
    > | > behavior? Would it make more sense if it were simply an ascii "dial",
    > | > within a particular range of characters? And perhaps too that particular
    > | > range could have a redefinable specal global.
    > | >
    > | > T.
    > |
    > | #pred leads to the gates of madness.
    > | Mr. Fulton is right in that it doesnt sound too hard to
    > | implement until you try it.
    >
    > Almost. I managed to dig up a working #pred method in ruby-talk archives. I
    > think robert wrote it (have to check to be sure), but it works well enough,
    > given that it would probably never be used ;)
    >


    Take a gander at Mr Fernandez's stab at it under:
    The Opposite of .succ!
    (Young and foolish I was)
    *Now I'm old and foolish, but thats another thread*

    > | I have used String#succ to ummm, 'test', the strength of passwords.
    > | The current implementation doesnt allow that if a password uses more
    > | printable chars than letters or numbers.
    > |
    > | An ascii 'dial' with a definable, or redefinable, range would be just
    > | perfect.
    > | ascci_succ ?
    > | 'z9'.succ => 'aa0'
    > | 'z9'.a_succ => 'z:'
    > |
    > | I just wonder if it should be a 'wheel' or 'dial', or if it should just
    > | have borders. 'a'.. 'the_end_of_the_line' of printable char range.
    >
    > It has become increasing apparent to me that string ranges are of very limited
    > use --primarily they seemed to be used just to get a list of letters a-z.


    consider this little bit o' perl:
    $hexdigit = (0 .. 9, 'a' .. 'f')[$num & 15];
    ^ the ability to do this would be nice.


    > While I'm sure there are at least a couple cases out there somewhere in which
    > the current behavior is quite useful, a number of of alternates have been
    > suggested to make it even more so; the general "dial" being one of them.
    > Another interesting idea is dictionary-order given a "depth" parameter. For
    > instance:
    >
    > 'a'.succ(1) #=> 'b'
    > 'z'.succ(1) #=> nil (nothing after z of depth 1)
    > 'a'.succ(2) #=> 'aa'
    > 'aa'.succ(2) #=> 'ab'
    > 'az'.succ(2) #=> 'b'
    > 'b'.succ(2) #=> 'ba'
    >


    Yikes.
    No, that would breed much confusion for the average user.
    It could be usefull, but IMO, would be a huge mistake if
    added to the standard.
    Too easy to trip oneself up.

    I would vote for the wheel first.

    > and so forth. Of course other methods would require adjustment to handle the
    > parameter, but that is fairly easy to do. No doubt there are other variations
    > of a more useful #succ as well.
    >
    > Clearly what would be better is some sort of Iterator / Enumerator /
    > Generator, perhaps provided by a String class method to which parameters can
    > be passed to determine behavior --or perhaps a few such methods. For example,
    > one method might be as above:
    >
    > sg = String.dict_enum('A-B', 2)
    > sg.to_a
    > #=> [ 'A', 'AA', 'AB', 'B', 'BA', 'BB' ]
    >
    > Speaking of which, if any one has a general purpose string generator, I would
    > really love to get a hold of it.
    >
    > My overall conclusion is that string ranges have held back the Range class. On
    > suby-ruby we have been able to get Range to behave uniformally even with
    > string ranges. This required using an alternative comparesion method (#cmp
    > instead of #<=>). But given the limited usefulness of the current String#succ
    > in contrast to the other useful possibilities for generating a list of
    > ordered strings, plus the "headache" it causes Range to support it, it seems
    > to me that it might be better just to let it go. Besides, it is easy enough
    > to do:
    >
    > ?a..?z
    >
    > If one needs simple character enumeration.
    >
    > Opinions on this are greatly welcome.
    >
    > T.
    >
    > P.S. Of course, if anyone can figure out a way to create a one-to-one
    > correspondence between strings and floats, then we'd have whole new ball game
    > on our hands!
    illocutionist, Nov 10, 2004
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Neha
    Replies:
    37
    Views:
    1,395
  2. Hal Fulton

    Time#succ ?

    Hal Fulton, Nov 23, 2003, in forum: Ruby
    Replies:
    7
    Views:
    129
    Niklas Frykholm
    Nov 28, 2003
  3. illocutionist
    Replies:
    3
    Views:
    134
    Mauricio Fernández
    Mar 6, 2004
  4. Jeff Mitchell

    Propose Range.new(..., &succ)

    Jeff Mitchell, Apr 24, 2004, in forum: Ruby
    Replies:
    2
    Views:
    104
    Tim Sutherland
    Apr 26, 2004
  5. paul
    Replies:
    10
    Views:
    201
    Tom Werner
    Nov 10, 2006
Loading...

Share This Page