We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

Beam

From Esolang
Jump to navigation Jump to search

Beam is yet another two dimensional language thought of around mid-2010 by User:Feuermonster and implemented and published in 2012.

  • The start-up direction is right.
  • There is a beam which holds an 8bit unsigned value.
  • Also there is a store which can hold an arbitrary large positive value. If it drops below zero it's wrapped to 255.
  • Then there is an infinite amount of 8bit memory cells.
  • The implementation uses NUL (\0) if no character could be read from stdin.
  • Every character which is not an instruction is a NOP.

Instructions

 > Set the direction to right
 < Set the direction to left
 ^ Set the direction to up
 v Set the direction to down
 + Increment the beam
 - Decrement the beam
 @ Output the beam as character
 : Output the beam as number
 / Redirect the control flow like this:

       |
   ----/        /---
                |
   (90 degrees to the left)

 \ Redirect the control flow like this:

           |
 -----\    \----
      |

   (90 degrees to the right)

 ! If the beam is not 0, reverse the control flow. (It bounces off the !)
 ? If the beam is 0, reverse the control flow. (It bounces off the ?)
 | Reverse the control flow if coming from a right/left-direction
 _ Reverse the control flow if coming from a up/down-direction
 H stop the program
 S store = beam
 L beam = store
 s memory[beam] = store
 g store = memory[beam]
 P memory[store] = beam
 p beam = memory[store]
 u If beam != store change direction to up
 n if beam != store change direction to down
 ` Decrement the store
 ' Increment the store
 ) If store != 0 change direction to left
 ( If store != 0 change direction to right
 r Read character from input

It should be noted, that 'u' and 'n' perform 32bit comparison: if the store exceeds 255 the comparison beam != store is always true since beam can not exceed 255. Lines are not padded to equal length. A compliant interpreter is not allowed to do this!

Example programs

Reverse stdin


'>   rP   n
 ^!p'<vn(`<
     ^ <
      >'p!`>`p@ v
            Hnp`<
           ^ <

Painfully written by hand.

A faster version (thanks to User:Fizzie):


>'p!rP(`)n>'p!`v
^        <    H(`p@p`)H
               H

Fastest version in the west (also thanks to User:Fizzie):


v
(>``v
!  H(p`@`p)H
P   H
' 
r 
' 
P 
! 
>^

Truth-machine

rS>@)

(Expects NUL or SOH from stdin.)

Codegolfed; 5 bytes.

Hello

Prints Hello!

'''''v
     >`++++++++++++++)++@v
v++++++@-(++++++++++`<'''<
>+@@+++@>-!'''>`++++++++++)v
                       @+++<

Hello, world!

Prints Hello, world! (by User:BrainFuckGirl)

'''''>`++++++++++++++)++@'''-v
v''@+++@@+++++++@(++++++++++`<
>-!'>`++++++++++++++)++@-----v
v------------(+++`<'S@-------<
>@--------@+++@------@-------v
H____@+++(++++++`<'''''!-<+@-<

Even / Odd

Reads from stdin and tests if the value (ascii value) is even or odd. If it is even, it prints a zero, else a one.

rv`<
  :u'<
 >-- u:

Cat

>r@nH
^  <

Compare

Reads in two ascii characters and prints out the smaller one.

rP'Pr'P'P```v     <
           H @p'''u``p''<
            >p-P''p-P``pu'p@

Turing completeness

Brainfuck programs can be translated to Beam programs. This mechanism works with the 'u' instruction and marking cells to restore the store.

Brainfuck

,[>+>+<<-]++++++[>--------<-]>[>.<]>.

Beam (translation with the bf2beam perl script)

v               > v                                             > v                                       > v
>'''rP>`p+P'p(`)uv>'>'p?-P'''p+P''p+P````p-Pv>p++++++P>`p+P'p(`)uv>'>'p?-P'''p--------P``p-Pv>''>`p+P'p(`)uv>'>'p?-P'''p@``v>''p@H
                 > '>'p?-P'                  ^                   > '>'p?-P'                  ^             > '>'p?-P'       ^     
      ^                                     <         ^                                     <   ^                          <       

Beam constants

Constants to set the beam to a specific value (requires store to be zero.). This list is not complete. Help me!

Number Code Bytes Cycles Cycles / Bytes Cycles / Number
24 '''>`++++++++) 14 34 2.42 1.42
24 '''''>`+++++)- 14 42 3 1.75
25 '''''>`+++++) 13 41 3.15 1.64
25 '''>`++++++++)+ 15 35 2.33 1.39
26 '''''>`+++++)+ 14 42 3 1.61
26 '''>`+++++++++)- 16 38 2.38 1.46
27 '''>`+++++++++) 15 37 2.46 1.37
28 '''''''>`++++) 14 50 3.57 1.78
28 '''>`+++++++++)+ 16 38 2.38 1.36
28 '''''>`++++++)-- 16 48 3 1.71

Implementation

Work in progress

  • Finding Beam constants.
  • Describing some techniques to program in Beam.
  • WeBeam (to program webpages).

Help is always welcome.

External resources