#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    383
    Rep Power
    0

    St*ck - brainf*ck with stack


    Being a big fan of esoterical languages, I recently ran into a precious piece of insanity called Stacked Brain****. I even started writing an interpreter for it in D. There are more bf-inspired languages with stack (Brainstack and Stackf*ck), but the first rather misses the idea of minimalism by having both cells and a stack (inc. commands for both), and the latter still has a memory cell and simply pushed/pops this cell.
    Suddenly, the thought the this idea could be taken further emerged... a single stack - no (accessable) other memory - and only 8 commands of vanishingly small power to operate on it.
    St*ck was fathered, and now I'd appreciate some comments on what I figured out so far, so the child may be born without malformations.
    One note on turing completeness: I don't have any idea, but as the semantics are rather close to bf, just with a stack instead of a tape, it may be turing-complete.
    ----------

    St*ck has a single Stack. If this stack is limited, what the limit is, and what size each item has, is up to the implementation. As with traditional brain****, formatting and non-command characters are ignored. So far, the commands are as following:
    Code:
    Command | Meaning
        ^   | push previously popped value, or 0
        v   | pop (remember for subsequent push)
        +   | increment top item
        -   | decrement top item
        .   | output top item as ASCII char (peek, i.e. do not pop)
        ,   | push input
        [   | jump past matching ] if top item == 0 (peek)
        ]   | jump back to matching [ if top item != 0 (peek)
    As said, any feedback is welcome.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    San Francisco Bay
    Posts
    1,939
    Rep Power
    1313
    Originally Posted by delnan
    As said, any feedback is welcome.
    You might get a better response if you show some example programs. (And of course, you'll get a better feel for the language in the process of creating them.)
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    383
    Rep Power
    0
    Well then, I'll stick to the traditional hello, World. As st*ck's "tape" is unlimited only on one side, but limited to one on the other, the clever "approximate all character values in one big loop" doesn't work. But loops are still useful.
    Code:
    // approximate "!" (dec 33 = 3x10 plus 3) by loop
    +++ // set top item (loop counter) to 3
    [
      v
      ++++++++++ // add 10 to top item
      ^ - // push loop counter and dec it
    ]
    v +++ ^ // finish counting to !: 30 plus 3 = 33 = !
    // now loop counter is 0 and ! is on the stack
    ^ // push new loop counter (old loop counter becomes next char)
    // same principle for remaining chars: dlroW *space* *comma* olleH
    
    // d = 100 = 10x10
    ++++++++++
    [
      v
      ++++++++++
      ^
    ]
    ^
    
    // l = 108 = 10x11 minus 2
    ++++++++++
    [
      v
      +++++++++++
      ^
    ]
    v -- ^^
    
    // r = 114 = 11x10 plus 4
    +++++++++++
    [
      v
      ++++++++++
      ^
    ]
    v +++ ^^
    
    // o = 111 = 11x10 plus 1
    +++++++++++
    [
      v
      ++++++++++
      ^
    ]
    v + ^^
    
    // W = 87 = 9x10 minus 3
    +++++++++
    [
      v
      ++++++++++
      ^
    ]
    v --- ^^
    
    // space = 32 = 5x6 plus 2
    +++++
    [
      v
      ++++++
      ^
    ]
    v ++ ^^
    
    // comma = 44 = 4x11
    ++++
    [
      v
      +++++++++++
      ^
    ]
    ^
    
    // o again
    +++++++++++
    [
      v
      ++++++++++
      ^
    ]
    v + ^^
    
    // l = 108 = 11x10 minus 2
    +++++++++++
    [
      v
      ++++++++
      ^
    ]
    v -- ^^
    
    // l again
    // as only the last item popped is preserved
    / /we cannot alter more than two items
    // (character and loop counter) within one loop
    // however, we can output the same item twice
    // since the dot does not pop but peek
    
    // e = 101 = 10x10 plus 1
    ++++++++++
    [
      v
      ++++++++++
      ^
    ]
    v + ^^
    
    // H = 72 = 7x10 plus 2
    +++++++
    [
      v
      ++++++++++
      ^
    ]
    v ++ ^^
    
    // now, the stack contains "Hello *comma* *space* World!" (in reverse order)
    . // output latest char: "H"
    v // pop manually, as dot does only peek
    // etc cetera:
    .v // "e"
    .  // "l" no pop because "Hello" has to l
    .v // second "l"
    .v // "o"
    .v // comma
    .v // space
    .v // "W"
    .v // "o"
    .v // "r"
    .v // "l"
    .v // "!"
    Untested, of course, since there is no implementation.
    And I wouldn't be to surprised if there is a more efficient way...

IMN logo majestic logo threadwatch logo seochat tools logo