Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

★ /prog/ Challenge Vol. 5 ★

Name: Anonymous 2010-06-11 23:51

The challenge suggestion thread was too busy going nowhere, and I feel like writing some code, so here is a /prog/ challenge.

THE CHALLENGE:
Design a toy programming language. You may implement either a compiler or interpreter, and you may write the implementation in any language of your choosing.

Post the source code to your implementation as well as programs in your language to accomplish at least two of the following tasks, plus one ``wild card'' program not listed here.

    • Factorial calculator
    • Fibonacci sequence generator
    • Prime number sieve (e.g. Eratosthenes, Atkin, etc.)
    • fgrep (output lines of input containing a given string)
    • Caesar cipher
    • Simple interactive calculator
    • Tic-tac-toe (AI not required)
    • The game of Nim (http://en.wikipedia.org/wiki/Nim)

Entries must be submitted prior to 2010-06-21 00:00, which gives one full week and two weekends. Judgment will be in three categories: presentation and cleverness of designed language, clarity of implementation, and overall usefulness/entertainment/trolling value of the ``wild card'' program.

Winner will receive ten Susscoins, to be transferred via /prog/mail.

Name: Anonymous 2010-06-13 4:58

>>40
CREATE MY ANUS

Name: Anonymous 2010-06-13 6:30

BIG NEWS EVERYBODY

turd 0.02 released

now with fibs, fact, and prime sieve

http://www.zshare.net/download/77182774740b729e

Name: Anonymous 2010-06-13 6:50

>>40
I believe many may already exist.

Name: Anonymous 2010-06-13 7:29

>>43
you mena haskall?

Name: Anonymous 2010-06-13 9:13

Name: Anonymous 2010-06-13 9:26

>>36
Unicode is pretty! ( ^ヮ^)

Name: Anonymous 2010-06-13 9:39

>>46
PRETTY MY ANUS

Name: Anonymous 2010-06-13 10:12

>>45
winner

Name: Anonymous 2010-06-13 10:25

>>36
specifically designed to annoy people who can't figure out how to input Unicode
You stole my idea, you magnificent bastard.

Name: Anonymous 2010-06-13 10:53

Name: Anonymous 2010-06-13 21:45

>>45
isSelfEvaluting

Name: Anonymous 2010-06-14 0:10

A language implementation consisting largely of eval with trivial changes to another language's syntax is generally not very interesting or clever.[1]

I'm neither interesting nor clever.  Here is a joke entry lacking in interest and cleverness.

#!/usr/bin/perl
# invalid perl code - flips parens
while(<>){$_=~s/\)(.*?)\(/\($1\)/g;eval $_}


__________
1: >>3

Name: Anonymous 2010-06-14 0:29

>>52
$_
I don't think you know Perl as well as you think you do.

Name: Anonymous 2010-06-14 0:59

>>53
I don't think >>52 thinks he knows Perl as well as you think he thinks he does.

Name: Anonymous 2010-06-14 1:42

perl -ni -e 'tr/)(/()/;eval'

Name: >>55 2010-06-14 1:51

Er, skip that -i flag. I used to use that all the time (with -p) for unfucking user settings. I left it in by force of habit.

Name: Anonymous 2010-06-14 2:00

>>40
APL says hi.

Anyway, I'm in. Taking a good suggestion from another thread, my language shall be named Cognitive Dissonance.

Name: Anonymous 2010-06-14 13:56

>>57
Cool Language Name, Bro

Name: !!FaCtOrzEWgHo50o 2010-06-14 18:02

here's this:
#!/usr/bin/perl

# stack.pl - an interpreter for a very simple stack-based language.
#
# fibonacci sequence generator:
# echo 'swap dup . over +' | perl stack.pl 0 1
#
# factorial calculator:
# echo '1 + dup rot dup . * swap' | perl stack.pl 1 1

use strict;
use feature qw(say switch);

local $/;
my @stack = @ARGV;
my @words = split /\s+/, <STDIN>;

do
{ for(@words)
  { given($_)
    { when(/^(?:\d*\.)?\d+$/) { push @stack, $_; }
      when('.') { say pop @stack; }
      when('dup') { push @stack, $stack[-1]; }
      when('swap') { @stack[-1, -2] = @stack[-2, -1]; }
      when('drop') { pop @stack; }
      when('over') { push @stack, $stack[-2]; }
      when('rot') { @stack[-1,-2,-3] = @stack[-3, -1, -2]; }
      when('+') { push @stack, (pop @stack) + (pop @stack); }
      when('-') { my($x, $y) = ((pop @stack), pop @stack);
                  push @stack, $y - $x; }
      when('*') { push @stack, (pop @stack) * (pop @stack); }
      when('/') { my($x, $y) = ((pop @stack), pop @stack);
                  push @stack, $y / $x; }
      when('%') { my($x, $y) = ((pop @stack), pop @stack);
                  push @stack, $y % $x; }
      when('^') { my($x, $y) = ((pop @stack), pop @stack);
                  push @stack, $y ** $x; }
      default { die "unrecognized word: $_"; }}}} while(@stack)


and then the ``wild card'' program: dup rot + 2 % rot rot ^ ^

which can be used like this:
#!/usr/bin/perl

use feature qw(say switch);

my $pattern = shift;

while(1)
{ my $newpattern = '';
  say $pattern;
  $pattern = '00' . $pattern . '00';
  for(0..(length $pattern) - 3)
  { my @part = split //, substr $pattern, $_, 3;
    $newpattern .= (exec_stack('dup rot + 2 % rot rot ^ ^ .', @part))[0]; }
  $pattern = $newpattern; }

sub exec_stack($@)
{ my @words = split /\s+/, shift;
  my @stack = @_;
  my @output = ();
  do
  { for(@words)
    { given($_)
      { when(/^(?:\d*\.)?\d+$/) { push @stack, $_; }
        when('.') { push @output, pop @stack; }
        when('dup') { push @stack, $stack[-1]; }
        when('swap') { @stack[-1, -2] = @stack[-2, -1]; }
        when('drop') { pop @stack; }
        when('over') { push @stack, $stack[-2]; }
        when('rot') { @stack[-1,-2,-3] = @stack[-3, -1, -2]; }
        when('+') { push @stack, (pop @stack) + (pop @stack); }
        when('-') { my($x, $y) = ((pop @stack), pop @stack);
                    push @stack, $y - $x; }
        when('*') { push @stack, (pop @stack) * (pop @stack); }
        when('/') { my($x, $y) = ((pop @stack), pop @stack);
                    push @stack, $y / $x; }
        when('%') { my($x, $y) = ((pop @stack), pop @stack);
                    push @stack, $y % $x; }
        when('^') { my($x, $y) = ((pop @stack), pop @stack);
                    push @stack, $y ** $x; }
        default { die "unrecognized word: $_"; }}}} while(@stack);
  return @output; }

Name: Anonymous 2010-06-14 21:20

# stack.pl - an interpreter for a very simple stack-based language.
I'm bored to tears already.

Name: Anonymous 2010-06-14 22:00

>>60
it gets better when you get to the ``wild card'' program.
that program hints at the real purpose of the language... to make small programs that could be run simultaneously over a large set of data, on dirt-cheap massively parallel hardware. of course that perl script doesn't do the parallel thing, but it does a pretty good job of showing how it'd be used.

Name: Anonymous 2010-06-14 22:02

!/usr/bin/perl
I'm bored to tears already.

Name: Anonymous 2010-06-14 22:16

>>61
Can't that be said of any "very simple stack-based language"? I mean, if you chose to use them that way?

Name: Anonymous 2010-06-14 23:16

I'm working on FRNPL Recursively Named Programming Language. You read it left to right with each line going straight down, here's the Fibonacci program for example:

print                    @       @ @ while ........... exit
"How high should I go? " a       b c <     @ @ @ print
                         _getnum 0 1 c     d b c c   
                                     a     + c d
                                           b
                                           c


The interpreter's basically done, I guess I'll just add features during the next few days.

Name: Anonymous 2010-06-14 23:33

>>63
most stack-based languages don't stay very simple for long.

Name: Anonymous 2010-06-15 10:20

>>64
You should make builtins one character in length.

Name: Anonymous 2010-06-15 11:48

>>66
like turd.

>>64
pronounced FERN-NUP-ALL?

Name: Anonymous 2010-06-15 12:54

>>67
Pronounced Fair Nipple

Name: Anonymous 2010-06-15 17:37

       r-+__
        /|\ \
     n / | v \
     |/  |/  |
  R__c___+_  |
     |\  |\\ |
     | \_0 r||
      \__1__//
          \_/


Writing a parser for this would be fun.

Name: Anonymous 2010-06-15 17:37

Oops, forgot the function header:

fib n:

Name: Anonymous 2010-06-15 18:28

>>69
That looks really cool.

Name: Anonymous 2010-06-15 19:13

Is Xarn in? If he's not in, I refuse to submit an entry. If he's in, I see no point in submitting my entry.

Name: Anonymous 2010-06-15 19:14

>>69
Have you seen Tubes? The project seems to be in the hands of brain-damaged high school kids, but the code looks conceptually similar, except less ass-key.

Name: Anonymous 2010-06-15 19:15

>>72
A true Xarn fan would recognize his code from miles away.

Name: Anonymous 2010-06-15 19:18

>>72
If you see a link to cairnarvon.rotahall.org instead of an actual code listing, it's Xarn. Otherwise it isn't.

Name: Anonymous 2010-06-15 20:15

>>40
So something that would interpret declarative knowledge and create imperative knowledge from that?

Name: 36 2010-06-16 1:08

It just occurred to me that I didn't write a wild card program. Here's a fancy one.
I wish I'd remembered to include a modulo operation.

3 → Λ
0 ← 4000
381 ← 1000
«
    Α ← 0
    Β ← 382
    β ← 1
    − → α
    α ≠ 0
    380 ← 0
    379 ← 0
    Α ← 2
    Β ← 382
    β ← 2
    + → α
    Α ← 0
    382 ← 2
    383 ← 1
    Β ← 382
    × → β
    Α ← 383
    + → 1
    Α ← 380
    «
        α < 337
        Β ← 382
        β ← 2
        Α ← 380
        + → Β
        Α ← 0
        × → 382
        Α ← 379
        Β ← 1
        ÷ → 383
        Α ← 383
        × → 383
        Β ← 383
        Α ← 379
        − → 383
        Α ← 381
        × → β
        Α ← 382
        + → 379
        Α ← 379
        Β ← 1
        ÷ → 382
        383 ← 2
        Α ← 380
        Β ← 383
        + → Β
        Α ← 382
        β ← α
        α ← 1
        Β ← 380
        + → β
        Α ← 380
        Β ← 382
        β ← 2
        − → β
        383 ← 2
        Α ← 383
        + → Β
        383 ← β
        384 ← β
        Β ← 381
        ÷ → 383
        × → 383
        Α ← 384
        Β ← 383
        − → 382
        Α ← 379
        Β ← 1
        ÷ → 383
        Α ← 383
        Β ← 381
        ÷ → 383
        Β ← 382
        + → 382
        «
            Α ← 380
            α > 2
            Β ← 0
            β = 1
            Α ← 382
            Β ← 383
            β ← 100
            ÷ → Λ
            384 ← α
            ÷ → α
            × → α
            Α ← 384
            Β ← 382
            − → 382
            Β ← 383
            Α ← 382
            β ← 10
            ÷ → Λ
            384 ← α
            ÷ → α
            × → α
            Α ← 384
            Β ← 382
            − → Λ
            1 = 0
        »
        Α ← 380
    »
»

Name: Applesauce !!XGrol9omL3xbWra 2010-06-16 1:24

I'll do it.

Name: Anonymous 2010-06-16 2:36

>>73
Have you seen Tubes?
I'm going to need a link to that, good Sir.

Name: Anonymous 2010-06-16 3:08

I finally thought up a concept:
n+t0=t
=i-nt{
_t1 =*
c+n.cn
=ci=c0
0i=1t=


It goes around the code in a spiral until it hits white space. Any size spiral will work. That code computes fibs for an input.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List