Subleq: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 246:
Hello, world!
</pre>
 
=={{header|AWK}}==
<lang AWK>
Line 301 ⟶ 302:
</pre>
 
=={{Headerheader|BBC BASIC}}==
The BBC BASIC implementation reads the machine code program as a string from standard input and stores it in an array of signed 32-bit integers. The default size of the array is 256, but other values could easily be substituted. No attempt is made to handle errors arising from invalid Subleq programs.
<lang bbcbasic>REM >subleq
Line 421 ⟶ 422:
Hello, world!
</pre>
 
=={{header|C sharp|C#}}==
{{trans|Java}}
<lang csharp>using System;
 
namespace Subleq {
class Program {
static void Main(string[] args) {
int[] mem = {
15, 17, -1, 17, -1, -1, 16, 1, -1, 16,
3, -1, 15, 15, 0, 0, -1, 72, 101, 108,
108, 111, 44, 32, 119, 111, 114, 108, 100, 33,
10, 0,
};
 
int instructionPointer = 0;
 
do {
int a = mem[instructionPointer];
int b = mem[instructionPointer + 1];
 
if (a == -1) {
mem[b] = Console.Read();
}
else if (b == -1) {
Console.Write((char)mem[a]);
}
else {
mem[b] -= mem[a];
if (mem[b] < 1) {
instructionPointer = mem[instructionPointer + 2];
continue;
}
}
 
instructionPointer += 3;
} while (instructionPointer >= 0);
}
}
}</lang>
{{out}}
<pre>Hello, world!</pre>
 
=={{header|C++}}==
Line 477 ⟶ 520:
Hello, world!
</pre>
 
=={{header|C#|C sharp}}==
{{trans|Java}}
<lang csharp>using System;
 
namespace Subleq {
class Program {
static void Main(string[] args) {
int[] mem = {
15, 17, -1, 17, -1, -1, 16, 1, -1, 16,
3, -1, 15, 15, 0, 0, -1, 72, 101, 108,
108, 111, 44, 32, 119, 111, 114, 108, 100, 33,
10, 0,
};
 
int instructionPointer = 0;
 
do {
int a = mem[instructionPointer];
int b = mem[instructionPointer + 1];
 
if (a == -1) {
mem[b] = Console.Read();
}
else if (b == -1) {
Console.Write((char)mem[a]);
}
else {
mem[b] -= mem[a];
if (mem[b] < 1) {
instructionPointer = mem[instructionPointer + 2];
continue;
}
}
 
instructionPointer += 3;
} while (instructionPointer >= 0);
}
}
}</lang>
{{out}}
<pre>Hello, world!</pre>
 
=={{header|COBOL}}==
Line 1,239 ⟶ 1,240:
Hello, world!
</pre>
 
 
=={{header|Oforth}}==
Line 1,445:
}</lang>
{{Output}}<pre>Hello, world!</pre>
 
=={{header|Perl 6}}==
{{trans|Perl}}
<lang perl6>my @hello-world = <15 17 -1 17 -1 -1 16 1 -1 16 3 -1 15 15 0 0 -1 72 101 108 108 111 44 32 119 111 114 108 100 33 10 0>;
 
my @memory = @hello-world;
my $ip = 0;
while $ip >= 0 && $ip < @memory {
my ($a, $b, $c) = @memory[$ip, $ip+1, $ip+2];
$ip += 3;
if $a < 0 {
@memory[$b] = getc.ord;
} elsif $b < 0 {
print @memory[$a].chr;
} else {
if (@memory[$b] -= @memory[$a]) <= 0 {
$ip = $c;
}
}
}</lang>
 
{{out}}
<pre>Hello, world!</pre>
 
=={{header|Phix}}==
Line 1,652 ⟶ 1,629:
 
(subleq Hello)</lang>
{{out}}
<pre>Hello, world!</pre>
 
=={{header|Raku}}==
(formerly Perl 6)
{{trans|Perl}}
<lang perl6>my @hello-world = <15 17 -1 17 -1 -1 16 1 -1 16 3 -1 15 15 0 0 -1 72 101 108 108 111 44 32 119 111 114 108 100 33 10 0>;
 
my @memory = @hello-world;
my $ip = 0;
while $ip >= 0 && $ip < @memory {
my ($a, $b, $c) = @memory[$ip, $ip+1, $ip+2];
$ip += 3;
if $a < 0 {
@memory[$b] = getc.ord;
} elsif $b < 0 {
print @memory[$a].chr;
} else {
if (@memory[$b] -= @memory[$a]) <= 0 {
$ip = $c;
}
}
}</lang>
 
{{out}}
<pre>Hello, world!</pre>
Line 1,760 ⟶ 1,761:
}</lang>
{{Out}}See it running in your browser by [https://scastie.scala-lang.org/f4MszRqZR5qtxI6YwarJhw Scastie (JVM)].
 
=={{header|Sidef}}==
{{trans|Perl 6}}
10,339

edits