gavinhoward Well, that makes it easier to implement. In fact, it will make it easier for me to provide a way for people to get the current behavior back, if they wish.

Nice idea!

5 days later

Here an easter-egg for gh-dc. The only comment explains its existence. Run it with -x to allow long variable names. Read first, guess what it'll spit out, and then try...

#
# this is not very "stacky" code at the function's level.  most stuff is done
# via named variables.
#
# it is a translation from a commented example program using only single letter
# variable names to using long names while stripping the original comments.
#
# this just should test how much long variable names alone benefit readability.
#

 _2.1 s xmin
  0.7 s xmax

 _1.2 s ymin
  1.2 s ymax

   32 s maxiter

   80 s chars
   25 s lines

    8 k

[ q ] s break

[
  l iterations l maxiter = break
  l rsquared l isquared + 4 < break
  2 l r * l i * l imag + s i
  l rsquared l isquared - l real + s r
  l iterations 1 + s iterations
  l r 2 ^ s rsquared
  l i 2 ^ s isquared
  l iteratepoint x
] s iteratepoint 

[
  l char l chars = break
  l xmax l xmin - l chars 1 - / l char * l xmin + s real
  l ymax l ymin - l lines 1 - / l line * l ymin + s imag
  0 s r
  0 s i
  0 s rsquared
  0 s isquared
  0 s iterations 
  l iteratepoint x
  l iterations 32 + P
  l char 1 + s char
  l dochars x
] s dochars 

[
  l line l lines = break
  0 s char l dochars x
  A P
  l line 1 + s line
  l dolines x
] s dolines 

0 s line l dolines x

Maybe we should pester ask tio.run to add gh-dc too?

    yeti That is a beautiful piece of code, and while I forgot what the formulas used were, when I ran it and saw what popped out, it was a glorious thing to see.

    As for release, sorry, but it may be late. I had to deal with some loss of motivation. But I've started the fuzzing, which I expect will take about a week. Then the release should happen.

    As for getting my dc into tio.run, I think that would be fun. Maybe we can get my bc in too?

    • yeti replied to this.

      The "minimally commented" GNU-/OpenBSD-DC version. The macros are defined where they get used. That fits the structure of the comments better.

      gavinhoward As for getting my dc into tio.run, I think that would be fun. Maybe we can get my bc in too?

      Sure that would make sense too.

      I found this hidden under TIO's logo at https://tio.run and have no idea how to get a direct link to that page:

      Contact
      If you want to share your opinion, request a feature, report a bug, or ask a question, please visit gitter.im/tryitonline or send an email to feedback@tryitonline.net. In addition, Stack Exchange users with at least 20 reputation can chat on talk.tryitonline.net.

      I expect it will have more weight if you contact them.

      a year later

      GNU DC on Debian11:

      $ dc --version
      dc (GNU bc 1.07.1) 1.4.1
      
      Copyright 1994, 1997, 1998, 2000, 2001, 2003-2006, 2008, 2010, 2012-2017 Free Software Foundation, Inc.
      This is free software; see the source for copying conditions.  There is NO
      warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
      to the extent permitted by law.
      $ dc -e '1 r'
      $ echo $?
      0

      GH-DC on Debian11:

      $ dc --version
      dc 6.6.0
      Copyright (c) 2018-2023 Gavin D. Howard and contributors
      Report bugs at: https://git.gavinhoward.com/gavin/bc
      
      This is free software with ABSOLUTELY NO WARRANTY.
      $ dc -e '1 r'
      
      Runtime error: stack has too few elements
          0: (main)
      
      $ echo $?
      3

      That's FreeBSD's default DC. NetBSD's and OpenBSD's DC yield similar results with a slightly different error text.

      I think GNU DC should error too as there is nothing to swap if r is given only a one element deep stack. Or is there a good reason to tolerate this?

      • rvp replied to this.

        yeti I think GNU DC should error too as there is nothing to swap if r is given only a one element deep stack. Or is there a good reason to tolerate this?

        In dc_stack_rotate(), in the file bc-1.07.1/dc/stack.c, it is written:

        439     /* if stack has only one element, treat rotation as no-op */                
        440     if (!r)

        Thus has the implementer deemed it and thus it will remain!1

        1 Unless ye files a PR.

        • yeti replied to this.

          rvp

          Their man page states an alternative implementation via classic DC commands, that is not compatible with this behaviour: "r   Reverses the order of (swaps) the top two values on the stack. (This can also be accomplished with the sequence SaSbLaLb.)"

          $ dc -e '1 SaSbLaLb f'
          dc: stack empty
          dc: stack register 'b' (0142) is empty
          1

          So I think this make-it-nop decision is nonsense and contradicting info in the doc, which clearly speaks of the top two elements of the stack, but I'm just too lazy to fight with the GNUs over that.

          My problem was that I had a leftover r in some GNU-DC code and wanted to translate it to *BSD and their DCs (IMO) correctly complained.

          Let's just call it documented (HERE!) from now on. ;-)