{"id":448,"date":"2007-06-22T11:40:32","date_gmt":"2007-06-22T11:40:32","guid":{"rendered":"http:\/\/scientopia.org\/blogs\/goodmath\/2007\/06\/22\/simple-pathology-betterave\/"},"modified":"2007-06-22T11:40:32","modified_gmt":"2007-06-22T11:40:32","slug":"simple-pathology-betterave","status":"publish","type":"post","link":"http:\/\/www.goodmath.org\/blog\/2007\/06\/22\/simple-pathology-betterave\/","title":{"rendered":"Simple Pathology: Betterave"},"content":{"rendered":"<p>Sorry for the missed weeks of friday pathological programming language columns. To be honest, I&#8217;m running out of languages. I&#8217;m sure there must be more, but my usual sources (dealers?) are running out &#8211; so send links!<br \/>\nAnyway, today I&#8217;m going to look at a really simple one, which I find fun. It&#8217;s<br \/>\nnot an overly exciting language, but it is a language which is has semantics almost as<br \/>\ntrivially simple as [BrainFuck][bf], but which ends up looking almost as much like line-noise as [TECO][teco]. It&#8217;s called [Betterave][betterave].<br \/>\n[betterave]: http:\/\/www.esolangs.org\/wiki\/Betterave<br \/>\n[teco]: http:\/\/scienceblogs.com\/goodmath\/2006\/09\/worlds_greatest_pathological_l_1.php<br \/>\n[bf]: http:\/\/scienceblogs.com\/goodmath\/2006\/07\/gmbm_friday_pathological_progr.php<\/p>\n<p><!--more--><br \/>\nBetterave is a very simple language which is based on prefix operators. (The authors calls them functions, but they&#8217;re not.) It uses a storage system with 26 variables (one for each letter of the alphabet), and a dictionary of strings indexed by number.<br \/>\nThere are 8 kinds of operations in Betterave, and 2 kinds of control flow operators.<br \/>\nHere&#8217;s the basic list of operators:<br \/>\n1. **Literals**:<br \/>\n* `0-9` &#8211; a single digit in Betterave is a zero-parameter operator that returns<br \/>\nthe value of the digit. This is the only way to do numeric literals in betterave;<br \/>\nto create a literal like 42, you&#8217;d need to use multiple literals and<br \/>\narithmetic operators: `*76`.<br \/>\n* A literal string written in quotes adds a new string to the dictionary, and<br \/>\nreturns the index of the string.<br \/>\n2. **Arithmetic**: `+`,`-`,`*`,`\/`,`%` &#8211; binary operators that add\/subtract\/multiply\/divide\/modulo<br \/>\nthe values of the next two expressions.<br \/>\n3. **Comparisons**: `=`, &#8220; &#8211; compare the value of the next two expressions,<br \/>\nreturning 1 if the first is equal\/less than\/greater than the other.<br \/>\n4. **Input**: &#8220;`:`&#8221; reads a number from the command-line, and returns it; &#8220;`;`&#8221; inputs<br \/>\na string, adds it to the end of the string dictionary, and then returns its index.<br \/>\n5. **Output**: &#8220;`.`&#8221; prints the value of the following expression as a number; &#8220;`,`&#8221; prints it as<br \/>\nan ASCII character.<br \/>\n6. **String Operations**:<br \/>\n* *String Append*: The string append commands are &#8220;`&amp;`&#8221; and &#8220;`#`&#8221;.<br \/>\nThey&#8217;re both binary operators. Their first parameter is the index of a string<br \/>\nto modify, and the second is a number. &#8220;`#`&#8221; interprets the second parameter<br \/>\nas a number, and the string representation of that number is appended to the<br \/>\nspecified string; &#8220;`&amp;`&#8221; interprets the second character as the ASCII code of<br \/>\na character, and appends the character to the specified string.<br \/>\n* _Delete character_: &#8220;&#8221; takes one parameter, which is the index of a string<br \/>\nto modify. It removes the first character from the string, and then returns<br \/>\nthe value of that character.<br \/>\n* _Delete string_: &#8220;`_`&#8221; takes one parameter which is a string index,<br \/>\ndeletes that string from the dictionary, and returns the index of the deleted<br \/>\nstring.  The index of strings after it are modified by this.<br \/>\n* *Print string*: &#8220;`$`&#8221; takes one parameter which is the index of a string in<br \/>\nthe dictionary, and prints that string.<br \/>\n7. **Variable Operations**: there are 26 variables, a through z. A variable name<br \/>\nin uppercase assigns the value of the next expression to the variable; a variable<br \/>\nname in lowercase returns the value of the variable.<br \/>\nThere are two control flow operators in Betterave: loop, and conditional.<br \/>\n* __Loop__: &#8220;`[expr1 | expr2]`&#8221;: this evaluates expr1; then expr2. If expr2 returns<br \/>\na non-zero value, then it repeats. Loops nest like you&#8217;d expect.<br \/>\n* __Conditional__: &#8220;`? expr1 expr2 !`&#8221;. Evaluates expr1. If expr1 evaluates to<br \/>\nnon-zero, then it evaluates expr2; otherwise, it skips to the expression following<br \/>\nthe next &#8220;!&#8221;. Conditions do <em>not<\/em> nest: on false, it will just skip to the<br \/>\nnext &#8220;!&#8221;, not to a <em>matching<\/em> &#8220;!&#8221;. So, for example, &#8220;`?0 ?=10!.5!.6`&#8221; will<br \/>\noutput 56: 0 evaluates to zero (false), so it skips to the next &#8220;!&#8221;, after which<br \/>\nit &#8220;.5&#8221; and then &#8220;.6&#8221;.<br \/>\nSo. First example, as usual, is &#8220;Hello World&#8221;.<br \/>\n$&#8221;Hello, World!&#8221;<br \/>\nPretty simple. A more interesting version:<br \/>\n&#8220;Hello, World!&#8221;A+95[,_0A-a1|a]<br \/>\nThis stores the string &#8220;Hello, World!&#8221; in the string dictionary at index 0, and<br \/>\nstores 13 (the number of characters in the string), into variable A. Then it starts a loop. Inside the loop, it removes and outputs the first character of string 0, then subtracts one from A, and repeats the loop if A&gt;0. So it outputs the characters in sequence.<br \/>\nHow about a beautifully line-noisy fibonacci series?<br \/>\nAB1[.b,*48TbB+abAt|<b>a0].b,*25<br \/>\n* Read a number from the keyboard, and store it in A.<br \/>\n* Set B (which will store the result) to 1.<br \/>\n* Start a loop:<br \/>\n* Multiply B by the current value of A<br \/>\n* Subtract one from A<br \/>\n* Repeat as long as a is greater than 0.<br \/>\n* Output B, followed by a carriage return.<br \/>\n*(Note: a couple of typos were corrected in this post.)*<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sorry for the missed weeks of friday pathological programming language columns. To be honest, I&#8217;m running out of languages. I&#8217;m sure there must be more, but my usual sources (dealers?) are running out &#8211; so send links! Anyway, today I&#8217;m going to look at a really simple one, which I find fun. It&#8217;s not an [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[92],"tags":[],"class_list":["post-448","post","type-post","status-publish","format-standard","hentry","category-pathological-programming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4lzZS-7e","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/448","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/comments?post=448"}],"version-history":[{"count":0,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/448\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/media?parent=448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/categories?post=448"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/tags?post=448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}