Abuse filter log

Abuse Filter navigation (Home | Recent filter changes | Examine past edits | Abuse log)
Jump to navigation Jump to search
Details for log entry 7,527

12:36, 22 October 2020: Blue screen of life (talk | contribs) triggered filter 9, performing the action "edit" on Befunge. Actions taken: Warn; Filter description: require new users to introduce themselves (examine)

Changes made in edit

 
====Hello, world! (without string reversion)====
 
====Hello, world! (without string reversion)====
 
<>>#;>:#,_@#:"Hello, world!"
 
<>>#;>:#,_@#:"Hello, world!"
  +
  +
====Shorter version of the previous one====
  +
<>:#,_# @#"Hello, World!"
   
 
====Yet another "Hello, world"====
 
====Yet another "Hello, world"====

Action parameters

VariableValue
Edit count of the user (user_editcount)
0
Name of the user account (user_name)
'Blue screen of life'
Age of the user account (user_age)
160
Page ID (page_id)
1005
Page namespace (page_namespace)
0
Page title (without namespace) (page_title)
'Befunge'
Full page title (page_prefixedtitle)
'Befunge'
Action (action)
'edit'
Edit summary/reason (summary)
'Adding a shorter Hello World program without string reversion to the examples section.'
Old content model (old_content_model)
'wikitext'
New content model (new_content_model)
'wikitext'
Old page wikitext, before the edit (old_wikitext)
'{{infobox proglang |name=Befunge |paradigms=imperative |author=[[Chris Pressey]] |year=[[:Category:1993|1993]] |typesys= |memsys=stack-based |dimensions=[[:Category:Two-dimensional languages|two-dimensional]] |class=[[:Category:Turing complete|Turing complete]] (Befunge-98) |refimpl=[https://github.com/catseye/Befunge-93 Befunge-93] |majorimpl= |dialects=Befunge-93, [[Funge-98]] |influence= |influenced= |files=<code>.be</code>, <code>.bf</code>, <code>.b93</code>, <code>.b98</code>, <code>.befunge</code> }}'''Befunge''' is a two-dimensional [[esoteric programming language]] invented in 1993 by [[Chris Pressey]] with the goal of being as difficult to compile as possible. Code is layed out on a two-dimensional grid of instructions, and execution can proceed in any direction of that grid. ==Language overview== A Befunge program is laid out on a two-dimensional ''playfield'' of fixed size. The playfield is a rectangular grid of ASCII characters, each generally representing an instruction. The playfield is initially loaded with the program. Execution proceeds by the means of a ''program counter'' (-93) or ''instruction pointer'' (-98). This points to a grid cell on the playfield. The instruction pointer has inertia: it can travel to any of the four cardinal directions, and keep traveling that way until an instruction changes the direction. The instruction pointer begins at a set location (the upper-left corner of the playfield) and is initially travelling in a set direction (right). As it encounters instructions, they are executed. Befunge-93 has no jumps farther than two cells, so control flow is done by altering the direction of the program counter, sending it to different literal code paths. (Befunge-98 has far jumps, but because of inertia in the community, these are rarely used.) The following, for example, is literally an [[infinite loop]]: &gt;v ^&lt; Befunge programs mostly store data on a [[stack]] in the manner of Forth, but they can also read and write the contents of any cell in the playfield, given its coordinates, thus Befunge code can be self-modifying. ==History== Befunge is believed to be the first two-dimensional, ASCII-based, general-purpose (in the sense of "you could plausibly write [[Wikipedia:Hunt the Wumpus|Hunt the Wumpus]] in it" {{catseye|view/befunge-93/eg/wumpus.bf}}) programming language. Its form was influenced in part by the multimedia scripting application AmigaVision, and in part by [[Forth]]. The original Befunge (known as "Befunge-93" to distinguish it from others) has spawned many descendants and [[#Related languages|remote cousins]]. The closest relative, and most direct extension, of Befunge-93 is Befunge-98 of the [[Funge-98]] family of languages. Each Funge extends the central concepts of Befunge to a given number of dimensions (for example, Unefunge is one-dimensional, Trefunge is three-dimensional, Nefunge is ''n''-dimensional, etc.). Today, Befunge powers fungot, an IRC bot that enjoys some popularity in the esoteric programming community. Its source code is so small that it fits on a T-shirt. ===Etymology=== The word "Befunge" started life as a typographical error for the word "before", typed by [[Curtis Coleman]] at 4AM on a BBS chat system. It was then reverse-endowed with a fictional morphology where it took on the meaning ''Be-'' (a corruption of the prefix ''bi-'', for "two") + ''funge'' (fictional root of the word [http://dictionary.reference.com/search?q=fungible fungible], i.e. "interchangeable"). That is, to interchange (program codes with data) in two (dimensions). The name is pronounced /bee-FUNJ/. ==Instructions== Befunge-93 has the following commands: {| class="wikitable" !Cmd !Description |- |<code>+</code> |Addition: Pop two values a and b, then push the result of a+b |- |<code>-</code> |Subtraction: Pop two values a and b, then push the result of b-a |- |<code>*</code> |Multiplication: Pop two values a and b, then push the result of a*b |- |<code>/</code> |Integer division: Pop two values a and b, then push the result of b/a, rounded down. According to the specifications, if a is zero, ask the user what result they want. |- |<code>%</code> |Modulo: Pop two values a and b, then push the remainder of the integer division of b/a. |- |<code>!</code> |Logical NOT: Pop a value. If the value is zero, push 1; otherwise, push zero. |- |<code>`</code> |Greater than: Pop two values a and b, then push 1 if b>a, otherwise zero. |- |<code>&gt;</code> |PC direction right |- |<code>&lt;</code> |PC direction left |- |<code>^</code> |PC direction up |- |<code>v</code> |PC direction down |- |<code>?</code> |Random PC direction |- |<code>_</code> |Horizontal IF: pop a value; set direction to right if value=0, set to left otherwise |- |<code><nowiki>|</nowiki></code> |Vertical IF: pop a value; set direction to down if value=0, set to up otherwise |- |<code>"</code> |Toggle stringmode (push each character's ASCII value all the way up to the next <code>"</code>) |- |<code>:</code> |Duplicate top stack value |- |<code>\</code> |Swap top stack values |- |<code>$</code> |Pop (remove) top stack value and discard |- |<code>.</code> |Pop top of stack and output as integer |- |<code>,</code> |Pop top of stack and output as ASCII character |- |<code>#</code> |Bridge: jump over next command in the current direction of the current PC |- |<code>g</code> |A "get" call (a way to retrieve data in storage). Pop two values y and x, then push the ASCII value of the character at that position in the program. If (x,y) is out of bounds, push 0 |- |<code>p</code> |A "put" call (a way to store a value for later use). Pop three values y, x and v, then change the character at the position (x,y) in the program to the character with ASCII value v |- |<code>&</code> |Get integer from user and push it |- |<code>~</code> |Get character from user and push it |- |<code>@</code> |End program |- |<code>0</code> – <code>9</code> |Push corresponding number onto the stack |} ==Computational class== Because Befunge-93 programs are given an explicit limit of 80x25 cells on the size of their playfield, but are also given a working stack, any Befunge-93 program should be simulatable by a [[push-down automaton]]. However, the converse is not true; there surely exist some push-down automata which cannot be simulated by any Befunge-93 program (because they contain more states than can be encoded in the 80x25 playfield). Befunge-98 removes the fixed-size restriction on the playfield, and thus should be [[Turing-complete]]. ==Compilation== As stated, the design goal for Befunge was to create a language which was difficult to compile. This was realized by two main features: * self-modifying &ndash; the <code>p</code> instruction can write new instructions into the playfield; and * multi-dimensional &ndash; the same instruction can be executed in four different contexts (in a left-to-right series of instructions, or right-to-left, or upward or downward.) Nevertheless, these obstacles have been overcome to some degree, and Befunge compilers have been written, using appropriate techniques. The bf2c compiler included with the standard Befunge-93 distribution uses ''threaded code'': each instruction is compiled to a snippet of C code, and control flows through the snippets just as it does in a Befunge interpreter (that is, conditionally on the value of some 'direction' register.) This does not result in a significant advantage over a good interpreter. Note that the bf2c compiler is not correct since it does not handle <code>p</code> correctly, but it would not be impossible to make it do so (although the C language might not be well-suited for this.) The Betty compiler, for example, treats every possible straight line of instructions as a subprogram, and if a <code>p</code> instruction alters that subprogram, that subprogram is recompiled. This is an interesting variation on just-in-time compilation, and it results in a much better advantage over an interpreter, since many instructions can be executed in native code without making intervening decisions on the 'direction' register. The Befunjit and Bejit compilers, similarly to the Betty compiler, split the original code into subprograms which are lazily compiled and executed. They, however, divide the original playfield into "static paths" - code paths which do not contain instructions that conditionally change direction (i.e. <code>|</code>, <code>_</code> or <code>?</code>). The "static paths" may span on more cells than the "straight line paths" of Betty, which results in fewer and longer subprograms. Thus, there are fewer context jumps between the compiler and the compiled code and allows more optimisations. There are also programs which combine a Befunge interpreter and a copy of a given Befunge program into a single executable which runs the Befunge program when started. For Befunge-93 this can easily be done by having a preallocated 80&times;25 cell storage space in the interpreter, and filling it in with the chosen Befunge program. This might be considered a sort of pathological version of threaded code, and while it produces a similar effect to a compiler, that is, it generates a "native executable", it is not really considered the same thing. Sometimes such a tool is called a ''pseudo-compiler'' or ''linker''. [http://quadium.net/funge/tbc/ TBC (Tim's Befunge Compiler)], and BFC (BeFunge Compiler) written by Uranium-239, are examples of such tools. ==Examples== ===Befunge-93 and Befunge-98=== ====[[Hello, World!]]==== 64+"!dlroW ,olleH">:#,_@ ====[[Cat program]]==== ~:1+!#@_, ====[[Factorial]]==== &>:1-:v v *_$.@ ^ _$>\:^ ====DNA-code==== >78*vD v$_#>vN 7>!@ A 3 :v??v 9,-"""" 4+1ACGT +,,"""" >^^<<<< ====Sieve of Eratosthenes==== 2>:3g" "-!v\ g30 < |!`"O":+1_:.:03p>03g+:"O"`| @ ^ p3\" ":< 2 234567890123456789012345678901234567890123456789012345678901234567890123456789 ====[[Quine]]==== 01->1# +# :# 0# g# ,# :# 5# 8# *# 4# +# -# _@ Another one: 0 v "<@_ #! #: #,<*2-1*92,*84,*25,+*92*4*55.0 One that includes a bit of text of a pre-decided length: :0g,:"~"`#@_1+0"Quines are Fun">_ Arbitrary text can be inserted in between the second set of quotes, though the text is limited to 58 characters. A pseudo-quine: 060p070 p'O80v pb2*90p4$4> $4$>v> v4$>4$>4$>4$># ARGH>! <{[BEFUNGE_97]}> FUNGE! ##:-:## #####* 4$*>4$ >060p> 60g80g -!#v_ 60g1+ 60p60v #vOOGAH **>4$>^!!eg nufeB^ $4$4$4 $4<v#<<v-*2a:: v7-1g< #>70g>90g-! #@_^Befunge!! 123456 123456 VvVv!#!>Weird! >0ggv* ^$4$4p07+1g07 ,a<$4< <$4$4< <$4$4< <$4$4< <<#<*-=-=-=-=-* -=-=v* ::48*-#v_>,4$> 4$4$4 $4$4$ 4$4$4$ 4$4$4$ 4$^*!* XXXXXX XXX> BOINK>$60g1-7 0g+d2* %'A+,1 $1$1$1 $1$1$1 $>^<$ HAR!!! 8888 Befunge_is such_a pretty langua ge,_is n't_i t?_It_ 8888 looks_so much_l ike_li ne_noi se_and it's_ STILL_ ‘88’ Turing- Complet e!_Cam ouflag e_your code!! Confu se_the hell_out of_every one_re ading_ your_co de._Oh, AND_y ou.:-) ,o88o. Once_this_thing_i s_code d,_rea ding_it_back_ver ges_on the_imp 888888 ossible._Obfusc ate_the_obfus cated!_Befunge_ debuggers_are__ 888888 your_friends! By:_Alexios Chouchou las... X-X-X-X-X-X-X! 888888 -=*##*=- \*****/ 9797* -=97=- !@-*= ***** ‘"88P’ *!@-* =*!@- -=*!@ @-=*! And it prints out: GHIJKLM UVWXYZ FGHIJKLMNOP VWXYZA EFGHIJKLMNOPQR WXYZAB EFGHIJKLMNOPQRST XYZABC FGHIJKL PQRSTU EFGHIJ QRSTUV ABCDEF HIJKL OPQRS YZABCD GHIJKLM CDEFGHIJKLM RSTUVW BCDEFG IJKLMNOPQRSTUV ZABCDE HIJKLMNOPQR CDEFGHIJKLMNO STUVWX CDEFGH JKLMNOPQRSTUVW ABCDEF JKLMNOPQRSTUV CDEFGH LMNOPQ TUVWXY DEFGHI KLMNOPQRSTUVWXY BCDEFG LMNOPQRSTUVWXY DEFGH NOPQR UVWXYZ EFGHIJ LMNOPQ UVWXYZ DEFG OPQRSTUVWXYZA DEFGHI OPQRST VWXYZA FGHIJK MNOPQ WXYZAB EFGH STUVWXYZAB EFGHIJ PQRSTU WXYZAB GHIJKL NOPQR XYZABC FGHI WXYZABCD FGHIJK QRSTUV XYZABC HIJKLM OPQRS YZABCD GHIJ MNOPQRS YZABCDE GHIJKL RSTUVW YZABCD IJKLMN PQRST ZABCDE NOPQRSTU YZABCDEF HIJKLM STUVWX ZABCDEF IJKLMNO QRSTU ABCDEF HIJKLM PQRSTUVWXYZABCDEF JKLMNO STUVWX ABCDEFGHIJKLMNOP RSTUVW ABCDEFG IJKLMN RSTUVWXYZABCDEF LMNOPQRSTUVWX CDEFGHIJKLMNOPQ STUVWXYZABCDEFG JKLMNO TUVWXYZABCDEF NOPQRSTUVWX DEFGHIJK MNOPQR TUVWXYZABCDEFG KLMNOP XYZABCDE QRSTUVW GHIJK NOPQRS UVWXY BCDEF LMNOPQ VWXYZ WXYZA XYZAB YZABC ====Simple game ("Less or More")==== vv < < 2 ^ v< v1<?>3v4 ^ ^ > >?> ?>5^ v v v9<?>7v6 v v< 8 > > ^ vv < < 2 ^ v< v1<?>3v4 ^ ^ > >?> ?>5^ v v v ,*25 << v9<?>7v6 ,, v v< "" 8 >< > > ^ ""v >*: >0"!rebmun tupnI">:#,_$25*,:&:99p`|^< _0"!niw uoY">:#,_$25*,@ ^ < >:99g01-*+^ Another one (inspired by the one above): v>>> > v>>> > v 012 3 012 3 ^?^ ^?^ >>?#v?4>>?#v?4v v?v v?v 98765 98765 >>>>> ^>>>>> v v 0 + * + : 5 < >"!sseuG">:#,_v 0v_v#:-&:,+:5$< , v>0"!niw uoY" +0>:#,_$5:+,@ :>`0\"!"\v v"small"_"gib" ^>" ooT">:#,_$5 ===Befunge-98=== :''Main article: [[Funge-98]]'' ====Hello, world! (without string reversion)==== <>>#;>:#,_@#:"Hello, world!" ====Yet another "Hello, world"==== ;Hello, world!; >00ga6*1-->#@_1>:#<>#<0#<g#<:#<a#<6#<*#<1#<-#<-#<>#+>#1>#,_$$@ This basically prints the characters between the semicolons. ====1D Factorial==== 5 :>>#;1-:48*+01p*01g48*-#;1#+-#1:#<_$.@ (the 5 is the input number) ====Convert binary number to decimal==== v ;11101010; >>>>>>>>>>>>>>>a0g68*-90g68*-2*+80g68*-4*+70g68*-8*+v @.+***288-*86g03+**88-*86g04+**84-*86g05+**44-*86g06< Just insert an 8-bit number between the semicolons in the first line. ==Interpreters== === befunge93.js === [https://github.com/amicloud/befunge93 befunge93.js] is a Befunge-93 interpreter written in Javascript available as an [https://www.npmjs.com/package/befunge93 npm] package to use in your own applications or make your own IDE or interactive interpreter. [https://amicloud.github.io/fungide/ Fungide] is an interactive interpreter powered by befunge93.js. Features: * Decent UI * Visual program execution * Crawl or Step through your code * Can run your program without UI updating for fast execution === BefunExec === [http://www.mikescher.de/programs/view/BefunUtils BefunExec] is a befunge-93 interpreter written in C#. ([https://github.com/Mikescher/BefunExec On Github]) It only understands the befunge-93 instruction set but can work with program sizes greater than 80x25. It has advanced features like * breakpoints * stepping the instruction pointer backwards * showing a graph of the possible program flow paths * context-aware syntax highlighting * supporting programs with extended size (tested with an 2000x12039 program) ==Related languages== Befunge was preceded in 1991 by a similar but less featureful language [[Biota]], which was designed for experiments in self-reproduction. It was followed soon after, in 1994, by another similar language, [[Orthagonal]], the design of which was spurred by a discussion on alt.folklore.computers. Each of these three languages originated (as far as anyone can tell) completely independently of the other two. Befunge has also provided inspiration to the design of subsequent languages, the most similar of these are known as [[fungeoid]]s. Most of the languages are not similar enough to be called direct descendants, but often the author mentions the influence of Befunge in the accompanying commentary. Fungeoid languages include * [[Wierd]], a two-dimensional [[Turing tarpit]] * [[Befreak]], a reversible language * [[PATH]], which adds elements of [[Brainfuck]] * [[Flobnar]], a "functional-programming" fungeoid ==External resources== ===Befunge-93=== * {{catseye|projects/befunge93/doc/befunge93.html|Befunge-93 documentation.}} * [http://www.tutorialspoint.com/compile_befunge_online.php Befunge-93 Online Compilation.] * [http://www.quirkster.com/iano/js/befunge.html JavaScript Befunge-93 interpreter.] * [https://github.com/programble/befungee befungee], a Befunge-93 interpreter written in python, with a debugger and a concurrent mode. * [http://bephunge.sadowl.com/ Bephunge], an implementation of Befunge-93 in PHP (command-line) ([https://github.com/graue/esofiles/blob/master/befunge/impl/bephunge.phps mirror] in [[the Esoteric File Archive]]). * [https://github.com/graue/esofiles/tree/master/befunge/src/ Befunge programs] in [[the Esoteric File Archive]]. * [https://sourceforge.net/projects/yabi93/ YaBI93] - multiplatform Befunge93 interpreter (with IDE) for Java 1.5. * [https://github.com/serprex/Befunge Marsh/Bejit/funge.py/bf.vim] Fast interpreters/quasi JITs & a vim debug mode. [https://serprex.github.io/Befunge now with a WASM JIT online] * [http://befunge.aurlien.net Another interpreter in JavaScript] - ([https://github.com/arnemart/befungius On GitHub]) * [https://adrianton3.github.io/befunjit/demos/visualizer-lazy/visualizer.html Befunjit] - A just-in-time compiler for Befunge-93 * [https://github.com/nilp0inter/awkfunge awkfunge] Befunge-93 interpreter written in AWK. * [https://github.com/CzechsMix/FungePP FungePP] Interpreter for Funge++, a Procedural Befunge-93 Extension, written in C++ * [https://github.com/Mikescher/BefunCompile BefunCompile] a restricted Befunge-93 to C (and C#, and Python) compiler * [https://github.com/fbastos1/beefunge Beefunge] A Befunge-93 graphical IDE written in C++. Features a field as large as Funge-98. Currently under testing and development. * [https://github.com/DarkKitsune/NemFunge93 NemFunge93] Command line Befunge-93 interpreter written in imperative Nemerle for .NET and Mono. * [https://github.com/FreedomSka/befunge FreedomSka/befunge] - More befunge code examples * [https://befunje.ivan.sh/ Befunje] - Befunge-93 interpreter with visualization * [https://github.com/amicloud/befunge93 befunge93.js] is a Befunge-93 interpreter written in Javascript available as an [https://www.npmjs.com/package/befunge93 npm] package * [https://amicloud.github.io/fungide/ Fungide] is a visual interactive interpreter powered by befunge93.js. ===Befunge-98 and beyond=== * {{catseye|node/Funge-98.html|Funge-98 documentation.}} * [https://github.com/catseye/Funge-98/blob/master/doc/funge98.markdown Funge-98 specification] * [http://quadium.net/funge/ vsync's Funge stuff.] * [https://github.com/tngreene/BefungeSharp BefungeSharp] A Funge-98 IDE written in C#. Features a command-line editor and a compliant interpreter. * {{wayback|20070322234225|http://www.teepop.net/fungus/|Fungus}} - a nice Befunge-98 IDE for Win32. Warning: its interperter is not fully standards compliant. * {{wayback|20060925154455|http://kotisivu.mtv3.fi/quux/befunge.html|mooz' Befunge page}} - contains a Javascript interpreter and several interesting Befunge programs. * [http://www.purplehatstands.com/bequnge BeQunge] A cross-platform Funge-98 interpreter, code editor, and debugger. Works in any number of dimensions. * [http://www.quote-egnufeb-quote-greaterthan-colon-hash-comma-underscore-at.info/befunge/ J^4: Befunge] Jeffrey Lee's Befunge site, features plenty of interesting programs. * [http://www.iki.fi/deewiant/ Mycology and CCBI] A complete Befunge-98 test suite based on the specification, and an interpreter which passes all the tests. * [https://github.com/VorpalBlade/cfunge cfunge] - Small fast Befunge-98 interpreter in C, standard compliant. * [http://rcfunge98.com/ Rc/Funge-98] - Compliant Funge-98 implementation in C; diagnostics, tutorials and documentation, fingerprints include the TRDS time traveler. * [http://cubonegro.orgfree.com/sponge/sponge.html Sponge] - a compiler (in Common Lisp) from a tiny subset of Scheme to Befunge 98. * [http://mearie.org/projects/pyfunge/ PyFunge] - A Befunge-93/Funge-98 interpreter in Python. Its goal is a fully functional, compliant and optimizing implementation of Funge-98. * [http://hackage.haskell.org/package/Fungi Fungi] - A standards compliant Funge-98 interpreter and debugger written in Haskell. * [http://www.lshift.net/blog/2012/08/25/tdd-for-esoteric-programming-languages-using-clojure-and-befunge Closidrium] - Author retrospective of creating a Befunge-98 Interpreter in Clojure. * [https://github.com/TieSoul/Multilang Multilang] - A shell supporting multiple languages, including Befunge-98. * [http://www.mikescher.de/programs/view/BefunGen BefunGen] - A Befunge compiler / code generator, compiles to Befunge code from a c-like language * [https://github.com/electrodude/fungewars Fungewars] - A programming game in Funge-98. [[Category:Languages]] [[Category:Stack-based]] [[Category:Push-down automata]] [[Category:Turing complete]] [[Category:Two-dimensional languages]] [[Category:Implemented]] [[Category:Low-level]] [[Category:Self-modifying]] [[Category:1993]]'
New page wikitext, after the edit (new_wikitext)
'{{infobox proglang |name=Befunge |paradigms=imperative |author=[[Chris Pressey]] |year=[[:Category:1993|1993]] |typesys= |memsys=stack-based |dimensions=[[:Category:Two-dimensional languages|two-dimensional]] |class=[[:Category:Turing complete|Turing complete]] (Befunge-98) |refimpl=[https://github.com/catseye/Befunge-93 Befunge-93] |majorimpl= |dialects=Befunge-93, [[Funge-98]] |influence= |influenced= |files=<code>.be</code>, <code>.bf</code>, <code>.b93</code>, <code>.b98</code>, <code>.befunge</code> }}'''Befunge''' is a two-dimensional [[esoteric programming language]] invented in 1993 by [[Chris Pressey]] with the goal of being as difficult to compile as possible. Code is layed out on a two-dimensional grid of instructions, and execution can proceed in any direction of that grid. ==Language overview== A Befunge program is laid out on a two-dimensional ''playfield'' of fixed size. The playfield is a rectangular grid of ASCII characters, each generally representing an instruction. The playfield is initially loaded with the program. Execution proceeds by the means of a ''program counter'' (-93) or ''instruction pointer'' (-98). This points to a grid cell on the playfield. The instruction pointer has inertia: it can travel to any of the four cardinal directions, and keep traveling that way until an instruction changes the direction. The instruction pointer begins at a set location (the upper-left corner of the playfield) and is initially travelling in a set direction (right). As it encounters instructions, they are executed. Befunge-93 has no jumps farther than two cells, so control flow is done by altering the direction of the program counter, sending it to different literal code paths. (Befunge-98 has far jumps, but because of inertia in the community, these are rarely used.) The following, for example, is literally an [[infinite loop]]: &gt;v ^&lt; Befunge programs mostly store data on a [[stack]] in the manner of Forth, but they can also read and write the contents of any cell in the playfield, given its coordinates, thus Befunge code can be self-modifying. ==History== Befunge is believed to be the first two-dimensional, ASCII-based, general-purpose (in the sense of "you could plausibly write [[Wikipedia:Hunt the Wumpus|Hunt the Wumpus]] in it" {{catseye|view/befunge-93/eg/wumpus.bf}}) programming language. Its form was influenced in part by the multimedia scripting application AmigaVision, and in part by [[Forth]]. The original Befunge (known as "Befunge-93" to distinguish it from others) has spawned many descendants and [[#Related languages|remote cousins]]. The closest relative, and most direct extension, of Befunge-93 is Befunge-98 of the [[Funge-98]] family of languages. Each Funge extends the central concepts of Befunge to a given number of dimensions (for example, Unefunge is one-dimensional, Trefunge is three-dimensional, Nefunge is ''n''-dimensional, etc.). Today, Befunge powers fungot, an IRC bot that enjoys some popularity in the esoteric programming community. Its source code is so small that it fits on a T-shirt. ===Etymology=== The word "Befunge" started life as a typographical error for the word "before", typed by [[Curtis Coleman]] at 4AM on a BBS chat system. It was then reverse-endowed with a fictional morphology where it took on the meaning ''Be-'' (a corruption of the prefix ''bi-'', for "two") + ''funge'' (fictional root of the word [http://dictionary.reference.com/search?q=fungible fungible], i.e. "interchangeable"). That is, to interchange (program codes with data) in two (dimensions). The name is pronounced /bee-FUNJ/. ==Instructions== Befunge-93 has the following commands: {| class="wikitable" !Cmd !Description |- |<code>+</code> |Addition: Pop two values a and b, then push the result of a+b |- |<code>-</code> |Subtraction: Pop two values a and b, then push the result of b-a |- |<code>*</code> |Multiplication: Pop two values a and b, then push the result of a*b |- |<code>/</code> |Integer division: Pop two values a and b, then push the result of b/a, rounded down. According to the specifications, if a is zero, ask the user what result they want. |- |<code>%</code> |Modulo: Pop two values a and b, then push the remainder of the integer division of b/a. |- |<code>!</code> |Logical NOT: Pop a value. If the value is zero, push 1; otherwise, push zero. |- |<code>`</code> |Greater than: Pop two values a and b, then push 1 if b>a, otherwise zero. |- |<code>&gt;</code> |PC direction right |- |<code>&lt;</code> |PC direction left |- |<code>^</code> |PC direction up |- |<code>v</code> |PC direction down |- |<code>?</code> |Random PC direction |- |<code>_</code> |Horizontal IF: pop a value; set direction to right if value=0, set to left otherwise |- |<code><nowiki>|</nowiki></code> |Vertical IF: pop a value; set direction to down if value=0, set to up otherwise |- |<code>"</code> |Toggle stringmode (push each character's ASCII value all the way up to the next <code>"</code>) |- |<code>:</code> |Duplicate top stack value |- |<code>\</code> |Swap top stack values |- |<code>$</code> |Pop (remove) top stack value and discard |- |<code>.</code> |Pop top of stack and output as integer |- |<code>,</code> |Pop top of stack and output as ASCII character |- |<code>#</code> |Bridge: jump over next command in the current direction of the current PC |- |<code>g</code> |A "get" call (a way to retrieve data in storage). Pop two values y and x, then push the ASCII value of the character at that position in the program. If (x,y) is out of bounds, push 0 |- |<code>p</code> |A "put" call (a way to store a value for later use). Pop three values y, x and v, then change the character at the position (x,y) in the program to the character with ASCII value v |- |<code>&</code> |Get integer from user and push it |- |<code>~</code> |Get character from user and push it |- |<code>@</code> |End program |- |<code>0</code> – <code>9</code> |Push corresponding number onto the stack |} ==Computational class== Because Befunge-93 programs are given an explicit limit of 80x25 cells on the size of their playfield, but are also given a working stack, any Befunge-93 program should be simulatable by a [[push-down automaton]]. However, the converse is not true; there surely exist some push-down automata which cannot be simulated by any Befunge-93 program (because they contain more states than can be encoded in the 80x25 playfield). Befunge-98 removes the fixed-size restriction on the playfield, and thus should be [[Turing-complete]]. ==Compilation== As stated, the design goal for Befunge was to create a language which was difficult to compile. This was realized by two main features: * self-modifying &ndash; the <code>p</code> instruction can write new instructions into the playfield; and * multi-dimensional &ndash; the same instruction can be executed in four different contexts (in a left-to-right series of instructions, or right-to-left, or upward or downward.) Nevertheless, these obstacles have been overcome to some degree, and Befunge compilers have been written, using appropriate techniques. The bf2c compiler included with the standard Befunge-93 distribution uses ''threaded code'': each instruction is compiled to a snippet of C code, and control flows through the snippets just as it does in a Befunge interpreter (that is, conditionally on the value of some 'direction' register.) This does not result in a significant advantage over a good interpreter. Note that the bf2c compiler is not correct since it does not handle <code>p</code> correctly, but it would not be impossible to make it do so (although the C language might not be well-suited for this.) The Betty compiler, for example, treats every possible straight line of instructions as a subprogram, and if a <code>p</code> instruction alters that subprogram, that subprogram is recompiled. This is an interesting variation on just-in-time compilation, and it results in a much better advantage over an interpreter, since many instructions can be executed in native code without making intervening decisions on the 'direction' register. The Befunjit and Bejit compilers, similarly to the Betty compiler, split the original code into subprograms which are lazily compiled and executed. They, however, divide the original playfield into "static paths" - code paths which do not contain instructions that conditionally change direction (i.e. <code>|</code>, <code>_</code> or <code>?</code>). The "static paths" may span on more cells than the "straight line paths" of Betty, which results in fewer and longer subprograms. Thus, there are fewer context jumps between the compiler and the compiled code and allows more optimisations. There are also programs which combine a Befunge interpreter and a copy of a given Befunge program into a single executable which runs the Befunge program when started. For Befunge-93 this can easily be done by having a preallocated 80&times;25 cell storage space in the interpreter, and filling it in with the chosen Befunge program. This might be considered a sort of pathological version of threaded code, and while it produces a similar effect to a compiler, that is, it generates a "native executable", it is not really considered the same thing. Sometimes such a tool is called a ''pseudo-compiler'' or ''linker''. [http://quadium.net/funge/tbc/ TBC (Tim's Befunge Compiler)], and BFC (BeFunge Compiler) written by Uranium-239, are examples of such tools. ==Examples== ===Befunge-93 and Befunge-98=== ====[[Hello, World!]]==== 64+"!dlroW ,olleH">:#,_@ ====[[Cat program]]==== ~:1+!#@_, ====[[Factorial]]==== &>:1-:v v *_$.@ ^ _$>\:^ ====DNA-code==== >78*vD v$_#>vN 7>!@ A 3 :v??v 9,-"""" 4+1ACGT +,,"""" >^^<<<< ====Sieve of Eratosthenes==== 2>:3g" "-!v\ g30 < |!`"O":+1_:.:03p>03g+:"O"`| @ ^ p3\" ":< 2 234567890123456789012345678901234567890123456789012345678901234567890123456789 ====[[Quine]]==== 01->1# +# :# 0# g# ,# :# 5# 8# *# 4# +# -# _@ Another one: 0 v "<@_ #! #: #,<*2-1*92,*84,*25,+*92*4*55.0 One that includes a bit of text of a pre-decided length: :0g,:"~"`#@_1+0"Quines are Fun">_ Arbitrary text can be inserted in between the second set of quotes, though the text is limited to 58 characters. A pseudo-quine: 060p070 p'O80v pb2*90p4$4> $4$>v> v4$>4$>4$>4$># ARGH>! <{[BEFUNGE_97]}> FUNGE! ##:-:## #####* 4$*>4$ >060p> 60g80g -!#v_ 60g1+ 60p60v #vOOGAH **>4$>^!!eg nufeB^ $4$4$4 $4<v#<<v-*2a:: v7-1g< #>70g>90g-! #@_^Befunge!! 123456 123456 VvVv!#!>Weird! >0ggv* ^$4$4p07+1g07 ,a<$4< <$4$4< <$4$4< <$4$4< <<#<*-=-=-=-=-* -=-=v* ::48*-#v_>,4$> 4$4$4 $4$4$ 4$4$4$ 4$4$4$ 4$^*!* XXXXXX XXX> BOINK>$60g1-7 0g+d2* %'A+,1 $1$1$1 $1$1$1 $>^<$ HAR!!! 8888 Befunge_is such_a pretty langua ge,_is n't_i t?_It_ 8888 looks_so much_l ike_li ne_noi se_and it's_ STILL_ ‘88’ Turing- Complet e!_Cam ouflag e_your code!! Confu se_the hell_out of_every one_re ading_ your_co de._Oh, AND_y ou.:-) ,o88o. Once_this_thing_i s_code d,_rea ding_it_back_ver ges_on the_imp 888888 ossible._Obfusc ate_the_obfus cated!_Befunge_ debuggers_are__ 888888 your_friends! By:_Alexios Chouchou las... X-X-X-X-X-X-X! 888888 -=*##*=- \*****/ 9797* -=97=- !@-*= ***** ‘"88P’ *!@-* =*!@- -=*!@ @-=*! And it prints out: GHIJKLM UVWXYZ FGHIJKLMNOP VWXYZA EFGHIJKLMNOPQR WXYZAB EFGHIJKLMNOPQRST XYZABC FGHIJKL PQRSTU EFGHIJ QRSTUV ABCDEF HIJKL OPQRS YZABCD GHIJKLM CDEFGHIJKLM RSTUVW BCDEFG IJKLMNOPQRSTUV ZABCDE HIJKLMNOPQR CDEFGHIJKLMNO STUVWX CDEFGH JKLMNOPQRSTUVW ABCDEF JKLMNOPQRSTUV CDEFGH LMNOPQ TUVWXY DEFGHI KLMNOPQRSTUVWXY BCDEFG LMNOPQRSTUVWXY DEFGH NOPQR UVWXYZ EFGHIJ LMNOPQ UVWXYZ DEFG OPQRSTUVWXYZA DEFGHI OPQRST VWXYZA FGHIJK MNOPQ WXYZAB EFGH STUVWXYZAB EFGHIJ PQRSTU WXYZAB GHIJKL NOPQR XYZABC FGHI WXYZABCD FGHIJK QRSTUV XYZABC HIJKLM OPQRS YZABCD GHIJ MNOPQRS YZABCDE GHIJKL RSTUVW YZABCD IJKLMN PQRST ZABCDE NOPQRSTU YZABCDEF HIJKLM STUVWX ZABCDEF IJKLMNO QRSTU ABCDEF HIJKLM PQRSTUVWXYZABCDEF JKLMNO STUVWX ABCDEFGHIJKLMNOP RSTUVW ABCDEFG IJKLMN RSTUVWXYZABCDEF LMNOPQRSTUVWX CDEFGHIJKLMNOPQ STUVWXYZABCDEFG JKLMNO TUVWXYZABCDEF NOPQRSTUVWX DEFGHIJK MNOPQR TUVWXYZABCDEFG KLMNOP XYZABCDE QRSTUVW GHIJK NOPQRS UVWXY BCDEF LMNOPQ VWXYZ WXYZA XYZAB YZABC ====Simple game ("Less or More")==== vv < < 2 ^ v< v1<?>3v4 ^ ^ > >?> ?>5^ v v v9<?>7v6 v v< 8 > > ^ vv < < 2 ^ v< v1<?>3v4 ^ ^ > >?> ?>5^ v v v ,*25 << v9<?>7v6 ,, v v< "" 8 >< > > ^ ""v >*: >0"!rebmun tupnI">:#,_$25*,:&:99p`|^< _0"!niw uoY">:#,_$25*,@ ^ < >:99g01-*+^ Another one (inspired by the one above): v>>> > v>>> > v 012 3 012 3 ^?^ ^?^ >>?#v?4>>?#v?4v v?v v?v 98765 98765 >>>>> ^>>>>> v v 0 + * + : 5 < >"!sseuG">:#,_v 0v_v#:-&:,+:5$< , v>0"!niw uoY" +0>:#,_$5:+,@ :>`0\"!"\v v"small"_"gib" ^>" ooT">:#,_$5 ===Befunge-98=== :''Main article: [[Funge-98]]'' ====Hello, world! (without string reversion)==== <>>#;>:#,_@#:"Hello, world!" ====Shorter version of the previous one==== <>:#,_# @#"Hello, World!" ====Yet another "Hello, world"==== ;Hello, world!; >00ga6*1-->#@_1>:#<>#<0#<g#<:#<a#<6#<*#<1#<-#<-#<>#+>#1>#,_$$@ This basically prints the characters between the semicolons. ====1D Factorial==== 5 :>>#;1-:48*+01p*01g48*-#;1#+-#1:#<_$.@ (the 5 is the input number) ====Convert binary number to decimal==== v ;11101010; >>>>>>>>>>>>>>>a0g68*-90g68*-2*+80g68*-4*+70g68*-8*+v @.+***288-*86g03+**88-*86g04+**84-*86g05+**44-*86g06< Just insert an 8-bit number between the semicolons in the first line. ==Interpreters== === befunge93.js === [https://github.com/amicloud/befunge93 befunge93.js] is a Befunge-93 interpreter written in Javascript available as an [https://www.npmjs.com/package/befunge93 npm] package to use in your own applications or make your own IDE or interactive interpreter. [https://amicloud.github.io/fungide/ Fungide] is an interactive interpreter powered by befunge93.js. Features: * Decent UI * Visual program execution * Crawl or Step through your code * Can run your program without UI updating for fast execution === BefunExec === [http://www.mikescher.de/programs/view/BefunUtils BefunExec] is a befunge-93 interpreter written in C#. ([https://github.com/Mikescher/BefunExec On Github]) It only understands the befunge-93 instruction set but can work with program sizes greater than 80x25. It has advanced features like * breakpoints * stepping the instruction pointer backwards * showing a graph of the possible program flow paths * context-aware syntax highlighting * supporting programs with extended size (tested with an 2000x12039 program) ==Related languages== Befunge was preceded in 1991 by a similar but less featureful language [[Biota]], which was designed for experiments in self-reproduction. It was followed soon after, in 1994, by another similar language, [[Orthagonal]], the design of which was spurred by a discussion on alt.folklore.computers. Each of these three languages originated (as far as anyone can tell) completely independently of the other two. Befunge has also provided inspiration to the design of subsequent languages, the most similar of these are known as [[fungeoid]]s. Most of the languages are not similar enough to be called direct descendants, but often the author mentions the influence of Befunge in the accompanying commentary. Fungeoid languages include * [[Wierd]], a two-dimensional [[Turing tarpit]] * [[Befreak]], a reversible language * [[PATH]], which adds elements of [[Brainfuck]] * [[Flobnar]], a "functional-programming" fungeoid ==External resources== ===Befunge-93=== * {{catseye|projects/befunge93/doc/befunge93.html|Befunge-93 documentation.}} * [http://www.tutorialspoint.com/compile_befunge_online.php Befunge-93 Online Compilation.] * [http://www.quirkster.com/iano/js/befunge.html JavaScript Befunge-93 interpreter.] * [https://github.com/programble/befungee befungee], a Befunge-93 interpreter written in python, with a debugger and a concurrent mode. * [http://bephunge.sadowl.com/ Bephunge], an implementation of Befunge-93 in PHP (command-line) ([https://github.com/graue/esofiles/blob/master/befunge/impl/bephunge.phps mirror] in [[the Esoteric File Archive]]). * [https://github.com/graue/esofiles/tree/master/befunge/src/ Befunge programs] in [[the Esoteric File Archive]]. * [https://sourceforge.net/projects/yabi93/ YaBI93] - multiplatform Befunge93 interpreter (with IDE) for Java 1.5. * [https://github.com/serprex/Befunge Marsh/Bejit/funge.py/bf.vim] Fast interpreters/quasi JITs & a vim debug mode. [https://serprex.github.io/Befunge now with a WASM JIT online] * [http://befunge.aurlien.net Another interpreter in JavaScript] - ([https://github.com/arnemart/befungius On GitHub]) * [https://adrianton3.github.io/befunjit/demos/visualizer-lazy/visualizer.html Befunjit] - A just-in-time compiler for Befunge-93 * [https://github.com/nilp0inter/awkfunge awkfunge] Befunge-93 interpreter written in AWK. * [https://github.com/CzechsMix/FungePP FungePP] Interpreter for Funge++, a Procedural Befunge-93 Extension, written in C++ * [https://github.com/Mikescher/BefunCompile BefunCompile] a restricted Befunge-93 to C (and C#, and Python) compiler * [https://github.com/fbastos1/beefunge Beefunge] A Befunge-93 graphical IDE written in C++. Features a field as large as Funge-98. Currently under testing and development. * [https://github.com/DarkKitsune/NemFunge93 NemFunge93] Command line Befunge-93 interpreter written in imperative Nemerle for .NET and Mono. * [https://github.com/FreedomSka/befunge FreedomSka/befunge] - More befunge code examples * [https://befunje.ivan.sh/ Befunje] - Befunge-93 interpreter with visualization * [https://github.com/amicloud/befunge93 befunge93.js] is a Befunge-93 interpreter written in Javascript available as an [https://www.npmjs.com/package/befunge93 npm] package * [https://amicloud.github.io/fungide/ Fungide] is a visual interactive interpreter powered by befunge93.js. ===Befunge-98 and beyond=== * {{catseye|node/Funge-98.html|Funge-98 documentation.}} * [https://github.com/catseye/Funge-98/blob/master/doc/funge98.markdown Funge-98 specification] * [http://quadium.net/funge/ vsync's Funge stuff.] * [https://github.com/tngreene/BefungeSharp BefungeSharp] A Funge-98 IDE written in C#. Features a command-line editor and a compliant interpreter. * {{wayback|20070322234225|http://www.teepop.net/fungus/|Fungus}} - a nice Befunge-98 IDE for Win32. Warning: its interperter is not fully standards compliant. * {{wayback|20060925154455|http://kotisivu.mtv3.fi/quux/befunge.html|mooz' Befunge page}} - contains a Javascript interpreter and several interesting Befunge programs. * [http://www.purplehatstands.com/bequnge BeQunge] A cross-platform Funge-98 interpreter, code editor, and debugger. Works in any number of dimensions. * [http://www.quote-egnufeb-quote-greaterthan-colon-hash-comma-underscore-at.info/befunge/ J^4: Befunge] Jeffrey Lee's Befunge site, features plenty of interesting programs. * [http://www.iki.fi/deewiant/ Mycology and CCBI] A complete Befunge-98 test suite based on the specification, and an interpreter which passes all the tests. * [https://github.com/VorpalBlade/cfunge cfunge] - Small fast Befunge-98 interpreter in C, standard compliant. * [http://rcfunge98.com/ Rc/Funge-98] - Compliant Funge-98 implementation in C; diagnostics, tutorials and documentation, fingerprints include the TRDS time traveler. * [http://cubonegro.orgfree.com/sponge/sponge.html Sponge] - a compiler (in Common Lisp) from a tiny subset of Scheme to Befunge 98. * [http://mearie.org/projects/pyfunge/ PyFunge] - A Befunge-93/Funge-98 interpreter in Python. Its goal is a fully functional, compliant and optimizing implementation of Funge-98. * [http://hackage.haskell.org/package/Fungi Fungi] - A standards compliant Funge-98 interpreter and debugger written in Haskell. * [http://www.lshift.net/blog/2012/08/25/tdd-for-esoteric-programming-languages-using-clojure-and-befunge Closidrium] - Author retrospective of creating a Befunge-98 Interpreter in Clojure. * [https://github.com/TieSoul/Multilang Multilang] - A shell supporting multiple languages, including Befunge-98. * [http://www.mikescher.de/programs/view/BefunGen BefunGen] - A Befunge compiler / code generator, compiles to Befunge code from a c-like language * [https://github.com/electrodude/fungewars Fungewars] - A programming game in Funge-98. [[Category:Languages]] [[Category:Stack-based]] [[Category:Push-down automata]] [[Category:Turing complete]] [[Category:Two-dimensional languages]] [[Category:Implemented]] [[Category:Low-level]] [[Category:Self-modifying]] [[Category:1993]]'
Unified diff of changes made by edit (edit_diff)
'@@ -303,4 +303,7 @@ ====Hello, world! (without string reversion)==== <>>#;>:#,_@#:"Hello, world!" + +====Shorter version of the previous one==== + <>:#,_# @#"Hello, World!" ====Yet another "Hello, world"==== '
New page size (new_size)
24005
Old page size (old_size)
23933
Lines added in edit (added_lines)
[ 0 => '', 1 => '====Shorter version of the previous one====', 2 => ' <>:#,_# @#"Hello, World!"' ]
Unix timestamp of change (timestamp)
1603370164