Deadfish
From Esolang
Deadfish is a very odd interpreted programming language created by Jonathan Todd Skinner. It was released under public domain and was originally programmed in C, but now it has been since ported to many other programming languages(see below). Deadfish has a way to output things but it has no way to input them! It has only a few commands, only four in total. It is also case-sensitive, and can deal only with integer values when adding or subtracting, however once squared this number increases greatly! You can have several commands per line, at least in the C implementation. Errors are not acknowledged the shell simply adds a newline character! Anything that is not a command is not accepted by the interpreter. As you've probably assumed deadfish was created in less then a hour, and can be very useful in creating highly interactive programs[sic].
Contents |
[edit] Commands
Commands: i for increment, d for decrement, s for square, o for output.
For the XKCD variation, use
Commands: x for increment, d for decrement, k for square, c for output.
[edit] Why deadfish
Deadfish started out as a subset of HQ9+, as in all it would do would be to print out hello world and give an iou depending on how many times the command 9 was entered to how many 99 bottles of beer programs it owed the programmer. Deadfish was originally going to be called fishheads as programming in this language is like eating raw fish heads. However, after the limiting features of the language, programming in this language became like eating (and having to smell) dead, rotting fish heads.
[edit] Example Program
Note: the standard shell adds >> characters for readability >> i >> >> o 1 >> d
[edit] Implementations
[edit] Bash
#!/bin/bash no=0 while true; do ((no==256||no<0)) && no=0 echo -n '>> ' # prompt if read; then case $REPLY in d) ((no--)) ;; i) ((no++)) ;; o) echo $no ;; s) no=$((no*no)) ;; *) : ;; esac else echo # on EOF fi done
[edit] Befunge-93
v Deadfish in Befunge 0 >0" >>">:vv < ,# _$:vv-*5+7*44 + v < _:*v : $ v^,_v^.< > 5> ~ >#$>:375**-v ^ < $ #v-*:*25:_$1+ ^#-*65-*99:_$1- #v ^ _$0~^ >:1+v -^> #1-#_1+:48:**
[edit] C
/* <-- Deadfish Interpreted Computer Language --> */
/* <-- Programmed by Jonathan Todd Skinner --> */
/* <-- Include Header File --> */
/* Updated the Code to Remove Uneeded Header Includes - JTS */
#include <stdio.h>
/* <-- Declare some variables --> */
unsigned int x; /* make a positive integer and call it x */
char usrinput; /* string to hold user input */
/* <-- Declare a function --> */
void entercommand(void);
/* <-- Start Main Function --> */
int main(void)
{
/* At beginning of x is always 0 */
x = 0;
entercommand();
}
/* <-- Enter Command --> */
void entercommand(void)
{
/* Accept User Input */
printf(">> "); /* output shell symbol */
scanf("%c",&usrinput); /* scan for user input that is char */
/* Check for commands and do action */
/* Make sure x is not greater then 256 */
if(x == 256) x = 0;
if(x == -1) x = 0;
if(usrinput == 'i')
{
x++;
entercommand();
}
else if(usrinput == 'd')
{
x--;
entercommand();
}
else if(usrinput == 'o')
{
printf("%d\n",x);
entercommand();
}
else if(usrinput == 's')
{
x=x*x;
entercommand();
}
else
{
printf("\n");
entercommand();
}
}
[edit] Commodore 64 BASIC
Type "H" to quit. ((Fixed to comply with the Deadfish 0-255 rule (again))) You can download a "better" version of in the "External Links" section.
10 INPUT A$ 20 IF A$="I" THEN B = B+1 21 IF A$="D" THEN B = B-1 22 IF A$="S" THEN B = B*B 23 IF A$="O" THEN PRINT B 24 IF A$="H" THEN END 31 IF B = 256 THEN B = 0 32 IF B < 0 THEN B = 255 33 GOTO 10
[edit] FALSE
[0~][" >> "^ \$\$256=\1_=&[%0]?\ $'i=[\1+\]? $'d=[\1-\]? $'s=[\$*\]? 'o=[$,]? ]#
[edit] Forth
\ Type 'h' to halt
: MAIN
0 BEGIN
DUP 256 = OVER -1 = OR IF DROP 0 THEN
KEY CASE
'i' OF 1+ ENDOF
'd' OF 1- ENDOF
's' OF DUP * ENDOF
'o' OF DUP . ENDOF
'h' OF DROP EXIT ENDOF
ENDCASE
AGAIN
;
MAIN BYE
[edit] Glass
{M[moO!iI!aA!sS!n<0>=c<1>=/cc<1>ie.?as.?=ec*=/e">> "oo.?fil.?=gf
*sl.?=hg*=l<-1>n*ae.?<256>n*ae.?aa.?=/ln<0>=l<0>=\/hjf*g*h*as.?s
i.?=kj*"i"se.?=/knn*<1>aa.?=k<0>=\kj*"d"se.?=/knn*<1>as.?=k<0>=\
kj*"s"se.?=/knn*n*am.?=k<0>=\kj*"o"se.?=/kn*o(on).?<10>s(ns).?oo
.?k<0>=\hh*<1>as.?=\e<0>=\\<10>s(ns).?oo.?]}
[edit] Haskell
main = loop (0, "")
loop :: (Int, String) -> IO ()
loop (x', s) = do
putStr $ s ++ ">> "
c <- getChar
let x = case x' of -1 -> 0; 256 -> 0; _ -> x'
loop $ case c of
'i' -> (x+1, "")
'd' -> (x-1, "")
'o' -> (x, show x ++ "\n")
's' -> (x*x, "")
_ -> (x, "\n")
[edit] HTML / Javascript
This interpreter is online here.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><TITLE>Deadfish in HTML</TITLE>
<SCRIPT type="text/javascript">
var i=0;
function deadfish()
{
var c=document.getElementById("cmd").value;
document.getElementById("cmd").value="";
document.getElementById('op').innerHTML+=
">> &#"+c.charCodeAt(0)+";<BR/>";
if(c=='i') i++;
else if(c=='d') i--;
else if(c=='s') i*=i;
else if(c=='o') document.getElementById('op').innerHTML+=i+"<BR/>";
else document.getElementById('op').innerHTML+="<BR/>";
if(i==256||i==-1) i=0;
return false;
}
</SCRIPT>
</HEAD><BODY>
<H1>Deadfish in HTML</H1>
<DIV id="op"></DIV>
<FORM onsubmit="return deadfish()">
>> <INPUT type="text" maxlength="1" size="1" id="cmd" /><BR/>
<INPUT type="submit" value="Submit" />
</FORM>
</BODY></HTML>
[edit] Java
// Deadfish in Java -- JTS
// Compiled with JDK 6 and tested with JRE 6 on Ubuntu 9.0.4
// And yes, I do hate Java like most people and I hate how I have to do it for comp sci!
import java.util.Scanner;
public class Deadfish
{
public static void main(String args[])
{
Scanner comm = new Scanner(System.in);
boolean isSquared = false;
int x = 0;
String usrinput;
while(true)
{
System.out.print(">> ");
usrinput = comm.next();
if(usrinput.contentEquals("i"))
{
if(x >= 256 && isSquared == false)
x = 0;
x++;
}
else if(usrinput.contentEquals("d"))
{
if(x <= -1 && isSquared == false)
x = 0;
x--;
}
else if(usrinput.contentEquals("o"))
System.out.println(x);
else if(usrinput.contentEquals("s"))
{
if(x >= 256)
isSquared = true;
x = x * x;
}
else
System.out.println();
}
}
}
//FIN
[edit] Lua
#!/usr/bin/env lua
accumulator = 0
while true do
io.write(">>> ")
local input = io.stdin:read'*l'
if accumulator == 256 or accumulator < 0 then accumulator = 0 end
if input == "i" then
accumulator = accumulator + 1
elseif input == "d" then
accumulator = accumulator - 1
elseif input == "s" then
accumulator = accumulator ^ 2
elseif input == "o" then
print(accumulator)
end
end
[edit] Perl
#!/usr/bin/perl -w
my $acc=0;
while (1) {
print ">> ";
$_ = <>;
if ($acc==-1 or $acc==256) { $acc=0; }
if (/^i$/) { $acc++; }
elsif (/^d$/) { $acc--; }
elsif (/^o$/) { print $acc, "\n"; }
elsif (/^s$/) { $acc*=$acc; }
else { print "\n"; }
}
[edit] Python
"""
Deadfish Programming Language Interpreter
Programmed by Jonathan Todd Skinner
This code is hereby released into the public domain
Harry eased the mess
"""
# Initialization
accumlator = 0
# Processing/Main program loop
while True:
# Get user input
userInput = raw_input(">> ")
if accumlator == 256 or accumlator == -1:
accumlator = 0
# Process input
if userInput == "i":
accumlator += 1
elif userInput == "d":
accumlator += -1
elif userInput == "o":
print accumlator
elif userInput == "s":
accumlator *= accumlator
else:
print ">>"
[edit] Ruby
#!/usr/bin/env ruby
#deadfish interpreter for public domain.
no=0
loop do
the_cmd = gets.chomp
case the_cmd
when "d" then no=no-1
when "i" then no=no+1
when "o" then puts "#{no}"
when "s" then no=no*no
end
end
[edit] TeX
% Deadfish interpreter in TeX
\catcode32=9\endlinechar=-1
\newcount\accumulator
\def\checkwrapping{
\ifnum\accumulator=256\accumulator=0\fi
\relax
\ifnum\accumulator=-1\accumulator=0\fi
}
\def\I{
\advance\accumulator by 1
\checkwrapping
}
\def\D{
\advance\accumulator by -1
\checkwrapping
}
\def\S{
\multiply\accumulator by \accumulator
\checkwrapping
}
\def\O{
\message{\the\accumulator}
}
\tracingonline=-1
\scrollmode
\def\Activate{
\catcode105=13
\catcode100=13
\catcode115=13
\catcode111=13
}
\catcode62=11
\def\Start{
\escapechar=-1
\loop
\read16 to \>>
\>>
\iftrue\repeat
}
\Activate
\leti=\I
\letd=\D
\lets=\S
\leto=\O
\Start
[edit] Thutu
This stores data in unary, which explains its inefficiency and the length of one of the lines.
/=>=> =x/z=x/ * /=>=> =x/> /=1/=n=>=> =xse/ /^i=xs(a*)e/=>=> =xs$1ae/ /^d=xsa?(a*?)e/=>=> =xs$1e/ /^s=xs(a*)a(b*)e/s=xs$1b$2e$1$2b/ /^s=xs(b*)e(a*)b/s=xs$1e$2a/ /^s=xs(b*)e(a*)$/=>=> =xs$2e/ /^o=xs(a*)e$/o=xs$1v/ /(=x.*[sbc])v/$1w0/ /(=x.*[sbc])av/$1cw1/ /(=x.*[sbc])aav/$1ccw2/ /(=x.*[sbc])aaav/$1cccw3/ /(=x.*[sbc])aaaav/$1ccccw4/ /(=x.*[sbc])aaaaav/$1cccccw5/ /(=x.*[sbc])aaaaaav/$1ccccccw6/ /(=x.*[sbc])aaaaaaav/$1cccccccw7/ /(=x.*[sbc])aaaaaaaav/$1ccccccccw8/ /(=x.*[sbc])aaaaaaaaav/$1cccccccccw9/ /(=x.*[sbc])aaaaaaaaaa(a*)v/$1bbbbbbbbbb$2v/ /(=xsc*)bbbbbbbbbb(.*)w/$1ccccccccca$2w/ /(=x.*)ab(.*w)/$1ba$2/ /(=x.*)ac(.*w)/$1ca$2/ /(=x.*)bc(.*w)/$1cb$2/ /=xs([ca]*)aw/=xs$1av/ /=xs(c*)w/=xs$1x/ /=xs(c*)c(a*)x/=xs$1a$2x/ /^o=xs(a*)x(.*)$/$2=n=>=> =xs$1e/ /^.*=x/=n=>=> =x/ . * /=xsaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaae/se/ .
[edit] Unlambda
This implementation uses Church numerals, which are essentially unary. Use large ones at your own risk.
````sii
``s``s`ks ``s``s`kskk
`k ``s``s `d`k `````.>.>. @ic
`k ``s``s``s``s`k?i`kii`k ``s``s`ks ``s`k`s`ks ``s`k`s`kk i `ki
``s``s``s``s`k?d`kii`k
``s``s``si
`k ``s``s`ks ``s`k`si
``s`kk ``s``s`ks ``s`k`s`ks ``s`k`s`kk ``si`kk `ki
``s`kk ``si`kk
`k`k`ki `k`ki
``s``s``s``s`k?o`kii`k
``sk ``s`kr ``s`k
```sii ``s `k `s``s``si
`k ``s``s``si`kk
``s`k`s``si`k
`k``si`k `k``si`k `k``si`k `k``si`k `k``si`k
`k``si`k `k``si`k `k``si`k `k``si`k k
``s`kk ``s``s`ks``s`k`s`ks ``s`k`s`kk ``si`k`ki `ki
``s`k`s``s`ks``s`k`sik ``s`kk``s`kk``si`k`ki
`ki ``s`kk
``s``s`ks ``s`k`s`ks ``s`k`s`kk
`k ``s``si`k.9 `k ``s``si`k.8 `k ``s``si`k.7 `k ``s``si`k.6 `k
``s``si`k.5 `k ``s``si`k.4 `k ``s``si`k.3 `k ``s``si`k.2 `k
``s``si`k.1 `k `k.0
``s`kk
``s``s`ks``s``s`ks
`k ``s`kc ``s`k`s`k`k`ki ``s``s`ks``s``s`ksk `k`k``si`ki `kk
``s``s`kskk `ki
``s `k`s``s`ks k i
``s``s``s``s`k?s`kii`k ``s``s`ks k i
``si`kr
``s``s`kc
``s`k`s`k`ki
``s``s`ks ``s``s`ks ``s``s`ks k `k``s`k`sik
`k `k ``````s``s`ks k ``s``s`ks k i
``s``s`ks k i ``s``s`ks k i
k ``si`ki
`k ``s`kd ``si `k`k`ki
i
`ki
[edit] WTFZOMFG
'>> "
_2 +
(
_0 %4 _4 ~-256 | { _0 =0 } _3
> +
> > ^
& > @i | { _0 + _3 } <
& > @d | { _0 - _3 } <
& > @s | { _0 & m _3 } <
& > @o | { _0 \ '\n" _3 } <
& > ~-10 | { '>> " } <
+
)
[edit] ZiziQue
[Start]
!i^inc"Increment
!d^dec"Decrement
!s^sqr"Square
!o^out"Output
.
[out]
"{number}
^Start
[inc]
+number
^Start
[dec]
-number
^Start
[sqr]
=number,{{number}*{number}}
^Start
[edit] External resources
- Creator's Webpage (Note: The creator's webpage was added for more information about the creator of the language.)
- Deadfish at Planet Source Code
- "DEADFISH 64" This is an implementation of Deadfish for the Commodore 64

