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

Pages: 1-4041-8081-120121-160161-

★ /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-12 0:12

This interpreter/compiler can be written in any language? Jesus LISP fags have this easy...

Name: Anonymous 2010-06-12 0:16

>>2
I'm not so sure about that. A language implementation consisting largely of eval with trivial changes to another language's syntax is generally not very interesting or clever.

Name: Anonymous 2010-06-12 1:44

I'd like to participate.

However, I have never written a compiler or interpreter before so I am a complete and utter noob at this.

What is /prog/'s recommended reading on this subject?  I have Basics of Compiler Design1 and Engineering A Compiler2, and have only read the beginning of the latter so far (man is it wordy).

_________________________________________________
1. http://www.diku.dk/hjemmesider/ansatte/torbenm/Basics/ - Get it for free here
2. I donno, check The Pirate Bay.

Name: Anonymous 2010-06-12 2:01

>>4
Jesus christ, here's a hing: it's /prog/'s favorite book.

Name: Anonymous 2010-06-12 2:03

>>5
Ok, besides SICP.  I don't want to complete all of SICP to write a toy compiler.

Name: Anonymous 2010-06-12 2:40

>>6
Implementing a Lisp interpreter or compiler is usually easier than in most languages, since you don't have to write your own read (lexer/parser) if you're writing it in Lisp, and since the code is effectively an AST (S-Exp external representation) stored as normal lisp lists (chained cons cell trees) which the language usually provides extensive functions to work with (or if it doesn't, you can easily implement them anyway), you can get right to the task at hand: eval (interpretation) or compile(compilation). Not only that, but such languages are very nice for extending themselves from within via macros due to the language's homoiconic property.

Sadly, I've already written toy interpreters and compilers, so this isn't as interesting of a task, altough it's still fun, but I suppose I lack enough imagination for designing a truly awesome language (I'm sadly content with what I'm currently using, and only have small gripes with the language, which I can fix by writing a few functions/macros). Both interpreters and compilers being rather simple to do in Lisp, altough, real-world compilers are not trivial things, because one has many issues to consider when it comes to optimizations and code transformations one perform, not to mention things like gc's, the runtime, libraries, and so on.

Name: Anonymous 2010-06-12 2:51

>>7
Yeah, Lisp is cool and I'd like to learn it.  Just not right now.

Name: Anonymous 2010-06-12 3:24

I am already working on my own language, does that count if i finish and submit it?

Name: Anonymous 2010-06-12 4:31

>>1
pass, I've written enough toy interpreters to last a lifetime

Name: Anonymous 2010-06-12 4:42

Entries must be submitted prior to 2010-06-21 00:00, which gives one full week and two weekends.
I'm going to take this opportunity to remind everyone that the ICFP programming contest starts on Friday. So if you are going to compete in that, you really need to finish this by Thursday.

Name: Anonymous 2010-06-12 4:50

>>10
submit an old one

Name: Anonymous 2010-06-12 5:01

how long till Xarn posts a solution made using C and Allegro?

Name: Anonymous 2010-06-12 5:05

Ok. Count me in. I'm gonna to implement something like http://www.golfscript.com/golfscript/ just for sake of it.


Will report back later.

Name: Anonymous 2010-06-12 5:15

10 4 dispatch we're rolling.

Name: Anonymous 2010-06-12 5:17

Maybe I'll finally write Trollgol this time

Name: Anonymous 2010-06-12 5:37

>>12
I wrote an ANSI C compiler when I was 12

Name: Anonymous 2010-06-12 6:23

I predict exactly zero working entries.

Name: Anonymous 2010-06-12 7:08

I have written an interpreter in Haskell for AbcSM, an assembler-like extension to the abc programming language. Does that qualify?

Name: Anonymous 2010-06-12 7:15

>>14 is done. It even fit in comments. Though I gave up on implementing langauge with lists, zips because tasks do not require it.

What did I win?

#!/usr/bin/python3

# ANonymous
# Artifical Language

import sys


# Syntax:
# something - instruction / guranteed stack delta

# INTEGER x(2 x, 3 x, 555 x) - pops top element and push it INTEGER times. /INTEGER-2
# INTEGER m- moves top element INTEGER times into the stack:
#    stack:{a b c d e} cmd:2 m -> {a b e c d}
#
# << read integer
# >> output integer/string
# [code block/array] - pushes  code block on stack/1
# integer - pushes integer on stack /1
# [code block] ! - executes code block, /-2
# [code block] N ! - executes code block N times /-3
# + addition

def readInt():
    return int(sys.stdin.readline())

def parseAnal(source):
    commands0 = source.split()
   
    commands = []

    # pack blocks
    blocks = []
    blocks.append(commands)

    i = 0
    while i < len(commands0):
        if commands0[i] not in "[]":
            blocks[-1] += [commands0[i]]
            i += 1
            continue
        if commands0[i] == '[':
            newBlock = []
            blocks[-1] += [newBlock]
            blocks += [newBlock]
            i += 1
            continue
        if commands0[i] == ']':
            del blocks[-1]
            i += 1
            continue
   
    assert len(blocks) == 1
    return blocks[0]

# return true if types of top of stack matches the given pattern
# examples: stack: ["hello",3], pattern: "SI" (string, integer) return true
# (note, we don't have strings yet)
#
def stackMatches(stack, pattern):
    if len(stack) < len(pattern):
        return False
    matches = {str : 'S', int: 'I', list: 'B'}
    pattern = pattern[::-1] # reverse to match stack order
    for i in range(len(pattern)):
        if matches[type(stack[-1-i])] != pattern[i]:
            return False
    return True

stack = []
def evalAnal(blocks):
    global stack
    while True:
        [block, i] = blocks[-1]
        if i >= len(block):
            break

        if type(block[i]) == list:
            stack.append(block[i])
            blocks[-1][1] += 1
            continue

        if type(block[i]) == str:
            #push int
            if block[i][0] in "0123456789":
                stack.append(int(block[i]))
                blocks[-1][1] += 1
                continue
            # dup
            if block[i] == "x":
                n = stack[-1]
                del stack[-1]
                top = stack[-1]
                del stack[-1]
                stack += [top] * n
                blocks[-1][1] += 1
                continue
            # debug: print stack
            if block[i] == "p":
                print(stack)
                blocks[-1][1] += 1
                continue
            # pop
            if block[i] == ">>>":
                del stack[-1]
                blocks[-1][1] += 1
                continue
            # move
            if block[i] == "m":
                delta = -stack[-1]
                del stack[-1]
                stack.insert(delta-1, stack[-1])
                del stack[-1]
                blocks[-1][1] += 1
                continue
            # mult
            if block[i] == "*":
                stack.append(stack[-1] * stack[-2])
                del stack[-2]
                del stack[-2]
                blocks[-1][1] += 1
                continue
            # add
            if block[i] == "+":
                stack.append(stack[-1] + stack[-2])
                del stack[-2]
                del stack[-2]
                blocks[-1][1] += 1
                continue
            # read
            if block[i] == "<<":
                stack.append(readInt())
                blocks[-1][1] += 1
                continue
            # write
            if block[i] == ">>":
                print(stack[-1])
                del stack[-1]
                blocks[-1][1] += 1
                continue
            # exec
            if block[i] == "!":
                if stackMatches(stack, "BI"):
                    n = stack[-1]
                    b = stack[-2]
                    del stack[-2:]
                    blocks[-1][1] += 1
                    while n > 0:
                        n-=1
                        evalAnal([[b,0]])
                    continue
                   
        print(block[i])
        assert not "implemented"


def execAnal(source):
    commands = parseAnal(source)
    blocks = [[commands,0]]
    evalAnal(blocks)

def fibo():
    execAnal("0 1 [ 3 x >> 2 m + ] << !")

def fact():
    execAnal("1 0 [  1 + 2 x 2 m * 1 m ] << ! >>> >> ")

def additor():
    execAnal("<< << + >>")

if len(sys.argv) > 1:
    execAnal(sys.argv[1])
    exit(1)

fibo()

Name: Anonymous 2010-06-12 7:25

What did I win?
We won't know till it's over

Name: Anonymous 2010-06-12 8:38

EXPERT C SOLUTION. Work in progress. Currently solutions for problem 1 and 2.


/*   turd.c
 *
 *   turd language interpreter v0.01
 *
 *   Released under the GPL v3
 *
 *   Copyright (C)  (name withheld)
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define TYPE_UNKNOWN    0
#define TYPE_VAR        1
#define TYPE_BUILTIN    2
#define TYPE_FUNC        3

#define VAR_UNKNOWN        0
#define VAR_INT            1
#define VAR_STR            2

typedef struct {
    int type;
    int subtype;
    int iv;
    char *sv;
    int (*builtin)(int,char*);
} obj_t;

obj_t OBJ[128];
char *BUF[1024]; // 1024 lines max
int LINE;
char GOTO = 0;
int DEBUG = 0;

int *RI(char *s) {
    if(DEBUG) printf("RI: %s\n",s);
    static int I;
    I=0;
    if(isalpha(*s)) {
        if(OBJ[*s].type==TYPE_VAR) {
            switch(OBJ[*s].subtype) {
                case VAR_INT: I = OBJ[*s].iv; break;
                case VAR_STR: I = atoi(OBJ[*s].sv); break;
            }
        }
    } else {
        I = atoi(s);
    }
    return &I;
}

#define BUILTIN(n)    int builtin_ ## n (int v, char *s)
#define SET_BUILTIN(o,b) OBJ[o].type = TYPE_BUILTIN; OBJ[o].builtin = builtin_ ## b

BUILTIN(assign_int) {
    OBJ[v].iv = *RI(s);
    OBJ[v].type = TYPE_VAR;
    OBJ[v].subtype = VAR_INT;
    //printf("assign int: %c = %d\n",v,OBJ[v].iv);
    return 0;
}

BUILTIN(assign_str) {
    OBJ[v].type = TYPE_VAR;
    OBJ[v].subtype = VAR_STR;
    free(OBJ[v].sv);
    OBJ[v].sv = strdup(s);
    if(DEBUG) printf("assign str: %c = \"%s\"\n",v,OBJ[v].sv);
    return 0;
}

int *arithmetic_prepare(int v, char *s, int *c) {
    char *p,*f;
    int i;
    static int a[32];
    f = s = strdup(s);
    if(*s=='=') {
        // TODO verify current type
        if(DEBUG) printf("arithmetic: reflexive\n");
        s++;
    } else {
        if(DEBUG) printf("arithmetic: non-reflexive\n");
        OBJ[v].iv;
    }
    for(i=0;i<31;i++) {
        if((p = strchr(s,',')))
            *p++ = 0;
        a[i]=*RI(s);
        if(DEBUG) printf("list %02d: %d\n",i,a[i]);
        if(!p)
            break;
        s = p;
    }
END:
    OBJ[v].type = TYPE_VAR;
    OBJ[v].subtype = VAR_INT;
    if(*f=='=') {
        // reflexive
        *c = i+1;
        if(DEBUG) printf("list: return count %d\n",*c);
        free(f);
        return a;
    }
    free(f);
    *c = i;
    if(DEBUG) printf("list: return count %d\n",*c);
    OBJ[v].iv = a[0];
    return a+1;
}

BUILTIN(add) {
    int c,*a = arithmetic_prepare(v,s,&c);
    while(c--) { OBJ[v].iv += *a++; }
    if(DEBUG) printf("plus: result %c = %d\n",v,OBJ[v].iv);
    return 0;
}
BUILTIN(subtract) {
    int c, *a = arithmetic_prepare(v,s,&c);
    while(c--) { OBJ[v].iv -= *a++; }
    if(DEBUG) printf("subtract: result %c = %d\n",v,OBJ[v].iv);
    return 0;
}
BUILTIN(multiply) {
    int c, *a = arithmetic_prepare(v,s,&c);
    while(c--) { OBJ[v].iv *= *a++; }
    if(DEBUG) printf("multiply: result %c = %d\n",v,OBJ[v].iv);
    return 0;
}
BUILTIN(divide) {
    int n=0, c, *a = arithmetic_prepare(v,s,&c);
    while(*a) { n += *a; a++; }
    OBJ[v].iv = n;
    //printf("plus: result %c = %d\n",v,OBJ[v].iv);
    return 0;
}

BUILTIN(goto) {
    int l;
    char *p;
    if(v=='X') {
        exit(atoi(s));
    }
    for(l=0;l<1024;l++) {
        p = BUF[l];
        if(!p)
            break;
        if(*p++!='@')
            continue;
        if(v!=*p)
            continue;
        LINE = l;
        return 0;
    }
    printf("error: label not found: @%C\n",v);
    return -1;
}

BUILTIN(print) {
    /* TODO: parse \n etc and do not force newline */
    switch(OBJ[v].type) {
        case TYPE_VAR:
            switch(OBJ[v].subtype) {
                case VAR_INT: printf("%d\n",OBJ[v].iv); break;
                case VAR_STR: printf("%s\n",OBJ[v].sv); break;
            }
            break;
    }
    return 0;
}

BUILTIN(if) {
    static char a[256];
    strcpy(a,s);
    char *p = strrchr(a,'@');
    if(!p) {
        printf("error: expecting @ for ?\n");
        return -1;
    }
    *p++ = 0;
    GOTO = *p;
    switch(OBJ[v].type) {
        case TYPE_VAR:
            switch(OBJ[v].subtype) {
                case VAR_INT:
                    switch(*a) {
                        case '=':
                            return (OBJ[v].iv == *RI(a+1));
                        case '<':
                        case '>':
                            // TODO
                            break;
                    }
                case VAR_STR:
                    return (strcmp(OBJ[v].sv,s)==0);
            }
            break;
    }
    return -1;
}


int main(int argc, char **argv) {
    char *s,*p,op;
    int i,r=0;
    FILE *f = stdin;
    memset(OBJ,0,sizeof(OBJ));
    memset(BUF,0,sizeof(BUF));

    SET_BUILTIN('#',assign_int);
    SET_BUILTIN(':',assign_str);
    SET_BUILTIN('+',add);
    SET_BUILTIN('-',subtract);
    SET_BUILTIN('*',multiply);
    SET_BUILTIN('/',divide);
    SET_BUILTIN('>',print);
    SET_BUILTIN('@',goto);
    SET_BUILTIN('?',if);

    builtin_assign_str('Z',argv[0]);
    for(i=1;i<argc;i++) {
        printf("argv[%d]: %s\n",i,argv[i]);
        if(i==1 && strcmp(argv[1],"-f")==0) {
            f = NULL;
            if(argv[2]) {
                f = fopen(argv[2],"r");
            }
            if(!f) {
                printf("error: failed to open file\n");
                return 1;
            }
            printf("opened file %s\n",argv[2]);
            i++;
            r = 2;
            continue;
        }
        builtin_assign_str('@'+(i-r),argv[i]);
    }

    for(LINE=0;LINE<1024;LINE++) {
        s = malloc(256);
        if(!fgets(s,256,f))
            break;
        if((p = strchr(s,'\n')))
            *p = 0;
        while(isspace(*s))
            s++;
        BUF[LINE] = s;
    }

    for(LINE=0;LINE<1024;LINE++) {
        s = BUF[LINE];
        if(!s)
            break;
        if(DEBUG) printf("===========================\n");
        if(DEBUG) printf("line: %s\n",s);
        switch(*s) {
            case 0:        continue; //blank line
            case '#':    continue; //comment line
            case '@':    continue;  //goto label
            default:    break;
        }
        if(!isalpha(*s)) {
            printf("error: unexpected (%C)\n",*s);
            break;
        }
        op = s[1];
        if(OBJ[op].type!=TYPE_BUILTIN) {
            printf("error: invalid instruction (%C)\n",op);
            break;
        }
        r = OBJ[op].builtin(*s,s+2);
        if(r<0) {
            if(DEBUG) printf("exiting due to error\n");
            return 1;
        }
        if(r>0) {
            if(GOTO) {
                builtin_goto(GOTO,"");
                GOTO = 0;
            }
        }
    }
    return 0;
}


---------------

#!/change/to/your/path/turd -f

# factorial.turd
#

# Create integer n with value of command line argument 1 (A)
n#A

# Create integer a with value of n
a#n

# Label L
@L

# Decrement n
n-=1

# If n = 1 goto @E
n?=1@E

# Derp
a*=n

# Goto @L
L@

# Label @E
@E

# Print a to stdout
a>

------------

#!/path/turd -f
#
# Fibonacci sequence generator. Pass number of terms as
# command line argument

a#0
b#1
a>
b>

@L
n+=1
n?=A@X
c+a,b
c>
a#b
b#c
L@

Name: Anonymous 2010-06-12 9:07

>>22
Copyright (C)  (name withheld)
I don't think you know how copyright works.

Name: Anonymous 2010-06-12 9:12

>>22
Expert Orphan Work Creator

Name: Anonymous 2010-06-12 9:30

>>22
MUST... REMAIN... ANONYMOUS

Name: Anonymous 2010-06-12 11:00

>>21
Ten Susscoins.

Name: Anonymous 2010-06-12 11:46

>>23
The author has asserted that the work belongs to someone and not the public domain. It's not very enforceable but the thought counts for something -- if the author can prove that he is the originator then his rights to the work would hold.

Name: Anonymous 2010-06-12 12:13

Who was the genius that designed Turd? Such mystery will confound historians 400 years from now.

Name: Anonymous 2010-06-12 12:30

>>28
Turd
This article is about the programming language. For other uses, see Turd (disambiguation).

Turd is a programming language named after the stuff that comes out of anii. It is famous for being both the only major programming language for which the original designer is completely unknown[1]. Read more...

Name: Anonymous 2010-06-12 12:31

>>29
s/both//

Name: Anonymous 2010-06-12 12:41

Name: Anonymous 2010-06-12 12:47

Feces
From Wikipedia, the free encyclopedia
  (Redirected from Turd)

Name: Anonymous 2010-06-12 12:51

Name: Anonymous 2010-06-12 12:53

>>33
That's a better place

Name: Anonymous 2010-06-12 17:21

>>34
PLACE MY ANUS

Name: Anonymous 2010-06-12 23:31

I've devised an esolang specifically designed to annoy people who can't figure out how to input Unicode. It's my first esolang, so nothing terribly adventurous. I've named it Codan.

It's pretty straightforward: there's an unspecified number of memory cells, each containing a (signed) integer (initialised to 0). Furthermore, there are three registers: Α, Β, and Λ. (Note that Α and Β are uppercase alpha and beta, not the Latin A and B.)
Α and Β just refer to memory cells (the contents of which can be easily accessed through special variables α and β, respectively), but Λ is a special I/O register: trying to fetch its contents will prompt the user for input (in the form of a number), trying to store a number in it will output that number to the screen.

Assigning to cells works like this:

Α ← 0
Β ← 1
10 → α
β ← α
β → Λ

(All whitespace is optional.)
This has Α refer to memory[0], Β to memory[1], then sets the value at memory[0] to 10, the value at memory[1] to the value at memory[0], and finally outputs the value at memory[1], being 10. x → y is completely equivalent to y ← x.
You can also just go 10 ← 1 (which assigns 1 directly to memory location 10) or 2 → Λ (which outputs 2 directly), if you like.

Next there are expressions, which are of the form function → target (or the other way around, of course). The functions are +, −, ×, ÷, and ↑, for addition, subtraction, multiplication, division, and exponentiation, respectively.
The functions operate on the values pointed to by Α and Β.

Α ← 0
Β ← 1
2 → 0
3 → 1
× → Λ

This would output 6.

Finally, there's the loop, which uses « to open and » to close.
By itself it just runs forever, so you can put assertions inside, which are of the form left-operand comparison-operator right-operand.
The operands can be anything you'd expect. The operator is one of =, ≠, <, ≤, >, ≥, ≮, ≯, ≰, or ≱, which should be self-explanatory. When the assertion is false, the innermost loop execution is currently in will be escaped from.

Α ← 0
Β ← Α
α ← 1
«
α < 10
+ → α
»
α → Λ

This will output 16.

Here's the factorial calculator:

1 ← Λ
1 → 2
1 → 3
Α ← 1
Β ← 2
«
α ≰ 0
× → 2
Β ← 3
− → α
Β ← 2
»
β → Λ


And the Fibonacci sequence generator (as far as signed ints will go):

Α ← 1
Β ← 2
α ← 0
β ← 1
«
α ≮ 0
α → Λ
+ → 3
α ← β
Α ← 3
β ← α
Α ← 1
»


And finally, the prime number sieve (up to 1000, but in principle it's only limited by the size of the memory):

Α ← 2
Β ← 2
«
    Α ≤ 1000
    «
        α = 0
        Α → Λ
        α ← Α
        Β ← Α
        «
            0 ← Β
            0 → Β
            + → Β
            Β ≤ 1000
            1 → β
        »
        0 = 1
    »
    α ← Α
    0 → Β
    1 → 0
    + → Α
»


The ``compiler'' I wrote for Codan is a Python script that outputs C and then calls gcc. Because this post is long enough as it is, I've put it on Sprunge:

http://sprunge.us/eOhB?py

Name: Anonymous 2010-06-12 23:43

>>36
GOOD.

Name: Anonymous 2010-06-12 23:59

>>36
excuse me sir but your operators appear to be backwards

Name: Anonymous 2010-06-13 0:03

>>38
They aren't.

Name: Anonymous 2010-06-13 3:03

I would like to create a programming language that is based only on formulas in mathematical notation.

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.

Name: Anonymous 2010-06-16 4:12

>>77
I don't know how it works, but it works. That must have been a pain in the ass to write.

>>79
http://esolangs.org/wiki/Tubes

Name: Anonymous 2010-06-16 13:06

I'm not >>1, but...

ENTRIES SO FAR

Finished
>>20    Artificial Language, interpreted: fibs, fact, wild card
>>36,77 Codan, compiled: fibs, fact, Eratosthenes, wild card
>>59    Stack.pl interpreted fibs, fact, wild card

Work in progress
>>22,42 Turd, interpreted: fibs, fact, Eratosthenes Needs: wild card program
>>45    Jeme (nameless), interpreted: none Needs: programs
>>64    FRNPL, ?
>>80    Uzumaki (nameless), ?

(I hope I didn't miss anyone; I erred on the side of taking joke entries seriously.)

Name: Anonymous 2010-06-16 13:16

Hi, Turd author here. Been busy with actual work coding - A rather exciting windows Credential Provider that sucks you off and anaylzes your semen to authenticate you. Actually I made that bit up. But some exciting new features are being added to turd and I plan to implement some more programs from the list and a wild card

Name: Anonymous 2010-06-16 14:03

>>82
You forgot to note that Codan was designed by Xarn.

Name: Anonymous 2010-06-16 15:14

>>84
Obvious but irrelevant.

Name: Anonymous 2010-06-16 16:25

>>83
Port this to PAM, please.

Name: Anonymous 2010-06-16 18:17

I write it in Æ: http://dis.4chan.org/read/prog/1198205066

Factorial calculator:

!fact = %return $1 * !fact ($1-1)
%while ($line = !fgets)
    %print !fact $line

Fibs:

!fibs = (1,1) ++ (!zipWith f_+, !fibs, !tail !fibs)

fgrep:

%while ($line = !fgets)
    %if (!match $line, $1) %print $line


Wildcard program and interpreter: (Hey, it said I could write it in any language I wanted to!)

%eval !getContents

Name: Anonymous 2010-06-16 21:13

>>87
Great, now provide an actual implementation of your language.

Name: Anonymous 2010-06-16 21:59

>>88
He did, can't you read?

Name: Anonymous 2010-06-17 1:51

>>80
Whilst thinking about it further, I'm changing it slightly, so you can write it in any direction you want(as long as it fits the down right up left(and is surrounded by whitespace).

So you can write it like this:

n   
=                     .
_                     n
c                     }
=                     1
0i=1t=0n*{t           -
          =           n
          0t+it+ci=cc=t

Or in any darn order really, trying to work in a way. Also adding in so you can reuse operators and variables by crossing over paths. There's only five operators, = + - _ ., or equals, add, subtract, get input, output variable. Only support for integers, no strings or arrays. I have exams next week, I'll try to finish it, but at the moment, all there is is a simple interpreter for the base language.

Name: Anonymous 2010-06-17 1:55

>>90
Oh, and there's also the control operator *, which works like brainfuck's [ symbol with the preceding variable, on the next set of curly brackets.

Sage because I've already bumped it.

Name: Anonymous 2010-06-17 10:17

Bump. We need more languages. ah fuck, I'm going to create new one.

Name: Anonymous 2010-06-17 12:00

I'll get to creating my language tomorrow, after my exams.
Though I'm worried that it'll end up as a shitty clone of Haskell :\

Name: Anonymous 2010-06-17 12:25

>>93
put shit in, get shit out

Name: Anonymous 2010-06-17 12:56

A+ work

Name: Anonymous 2010-06-17 13:11

>>93
Yeah, I too need to finish some projects for university. If only I had more time.

Name: Anonymous 2010-06-17 13:26

I thought a little about a language that doesn't have branches, but allows you to copy around and modify code instead . . .

Name: Anonymous 2010-06-17 14:41

Name: Anonymous 2010-06-17 14:56

>>96
I said exams. Not studying in a university yet.

Name: Anonymous 2010-06-17 15:14

100 GET

Name: Anonymous 2010-06-17 15:25

>>98
Too bad it's not Touring complete.

Name: Anonymous 2010-06-17 15:26

>>101
Anal ram 3500

Name: Anonymous 2010-06-17 15:28

>>102
ANAL RAM MY ANUS

Name: Anonymous 2010-06-17 20:30

>>99
Get of my lawn kid

Name: Anonymous 2010-06-18 1:43

>>59 here, with a new implementation of the same language (with a few more words added)...
from __future__ import print_function
import re

def eval_stack(code, stack):
    words = code.split()
    int_re = re.compile('^\d+$')
    float_re = re.compile('^\d*\.\d+$')
    while len(stack) > 0:
        output = []
        for word in words:
            if int_re.match(word):
                stack = stack + [int(word)]
            elif float_re.match(word):
                stack = stack + [float(word)]
            else:
                output, stack = { '%': lambda s: (output, s[:-2] + [s[-2] % s[-1]]),
                                  '*': lambda s: (output, s[:-2] + [s[-2] * s[-1]]),
                                  '+': lambda s: (output, s[:-2] + [s[-2] + s[-1]]),
                                  '-': lambda s: (output, s[:-2] + [s[-2] - s[-1]]),
                                  '/': lambda s: (output, s[:-2] + [s[-2] / s[-1]]),
                                  '^': lambda s: (output, s[:-2] + [s[-2] ** s[-1]]),
                                  '.': lambda s: (output + [s[-1]], s[:-1]),
                                  'ndrop': lambda s: (output, s[:-(s[-1]+1)]),
                                  # drop = 1 ndrop
                                  'drop': lambda s: (output, s[:-1]),
                                  'ndup': lambda s: (output, s[:-1] + s[-(s[-1]+1):-1]),
                                  # dup = 1 ndup
                                  'dup': lambda s: (output, s + [s[-1]]),
                                  'npick': lambda s: (output, s[:-1] + [s[-(s[-1]+1)]]),
                                  # over = 2 npick
                                  'over': lambda s: (output, s + [s[-2]]),
                                  'nrot': lambda s: (output, s[:-(s[-1]+2)] + s[-(s[-1]+1):-1] + [s[-(s[-1]+2)]]),
                                  # swap = 1 nrot
                                  'swap': lambda s: (output, s[:-2] + s[:-3:-1]),
                                  # rot = 2 nrot
                                  'rot':  lambda s: (output, s[:-3] + s[-2:] + [s[-3]]) }[word](stack)
        yield output

def print_stack(code, stack):
    [[print(j) for j in i] for i in eval_stack(code, stack)]

Name: Anonymous 2010-06-18 16:14

Bampu let's not lose this thread.

Deadline in 56 hours and 46 minutes.

Name: Anonymous 2010-06-18 16:14

>>106
Right, because threads expire on dis. IHBT

Name: Anonymous 2010-06-18 16:15

>>106
Dammit, off by an hour. Time zones are hard.

Name: Anonymous 2010-06-18 16:16

>>107
You're a moron, kid.

Name: Anonymous 2010-06-18 16:16

>>107
They dont expire. They just get forgotten.

Name: Anonymous 2010-06-18 17:16

>>106
Deadline in 56 hours and 46 minutes.
I think that I won't be able to finish in time D:

Name: Anonymous 2010-06-18 17:22

I'm writing a programming language called Anuslandia.

Name: Anonymous 2010-06-18 18:42

>>112

Sounds like fun

Name: Anonymous 2010-06-18 21:14

>>111
Sure you can! I just started today, and I have a nice chunk of code working already. I might be able to get JIT compilation working before the deadline.

Though I'm working backwards, so I don't have the parser written yet.

Name: Anonymous 2010-06-18 22:00

>>114
Implement a prototype parser/compiler in another language, re-implement the parser/compiler in the language itself, then enjoy the pleasure of being boostrapped inside.

Name: Anonymous 2010-06-19 3:40

>>115
Or implement a hacky "throw-away" interpreter in one language, then write the actual compiler (and maybe a new interpreter) in the language you were designing. Less time spent.

Name: Anonymous 2010-06-19 10:28

>>116
isn't that bastically what >>115 said?

Name: Anonymous 2010-06-19 18:25

Deadline in 29 hours and 35 minutes.

Name: Anonymous 2010-06-19 18:32

>>118
Dead
U MENA HASKAL

Name: Anonymous 2010-06-19 18:54

>>116
Or just write a compiler/interpreter in whatever language, then write the compiler/interpreter for your designed language in your designed language and do it that way. Less time spent.

Name: Anonymous 2010-06-19 20:32

>>118
Haven't started yet, fuck.

Name: Anonymous 2010-06-20 0:05

Hm. I don't foresee being able to finish in the next 24 hours.
I'll try to get something functioning anyway, but I might be a day late with it :(

Name: Anonymous 2010-06-20 6:04

BUMP

Name: Anonymous 2010-06-20 8:12

>>123
Why?

Name: Anonymous 2010-06-20 8:14

I have a language, but no interpreter. I don't know if I can be bothered to write one, either.

Name: Anonymous 2010-06-20 10:54

>>125
Cool story, bro.

Name: Anonymous 2010-06-20 15:05

>>126
Fuck off

Name: Anonymous 2010-06-20 17:06

>>36
damn that just makes my brain hurt from trying to read the source code

Name: Anonymous 2010-06-20 18:15

>>128
Really? It's structured EnglishPython.
Oh yeah, you're from /pr/.

Name: Anonymous 2010-06-20 20:31

Deadline in three and a half hours. Hurry hurry hurry!

Name: Anonymous 2010-06-21 0:35

I'm a tad late, but:

http://sprunge.us/HUCP soda.c
http://sprunge.us/JSeQ sasm

http://sprunge.us/RRNM caesar
http://sprunge.us/hPOZ fibs
http://sprunge.us/eCMJ wildcard

libao needed; you could hack it out but the wildcard program won't have much of a point without it.

Name: Anonymous 2010-06-21 1:13

>>131
Relatively boring language rendered highly enjoyable by the addition of sound. Well done!

Name: Anonymous 2010-06-21 2:55

I vote for Xarn. Xarn wins.

Name: Anonymous 2010-06-21 3:26

>>133
Xarn's is atually one of the least interesting languages.

Name: Anonymous 2010-06-21 3:35

>>134
None of the languages are very interesting, really. Codan has the Unicode gimmick, >>131 has the sound gimmick, and that's about it.
>>131 probably has the fanciest implementation, and Codan probably has the fanciest wild card program, but neither of those are strictly categories.

Name: Anonymous 2010-06-21 5:38

>>135
lol 0/10 bud

Name: Anonymous 2010-06-21 6:19

Name: Anonymous 2010-06-21 6:23

>>137
ps: not late if using baker island time as you didn't specifiy tz

Name: Anonymous 2010-06-21 6:36

God damnit i didnt even finsh my “lisp like„ interpreter.

Name: Anonymous 2010-06-21 9:45

WHERE'S MY PRIZEs AT

Name: Anonymous 2010-06-21 10:27

I'd submit my entry if the deadline was extended by a week :<

Name: 1 2010-06-21 11:52

RESULTS TIME

Presentation and cleverness - Codan, for its detailed introductory explanation. To be honest, none of the languages here struck me as being particularly clever; I have seen esolangs and stack languages resembling pieces of all of them. >>64 could potentially have won in that respect, as I don't recall having seen a language written horizontally like that. Alas, it can't really be awarded anything without an implementation or samples.

Clarity of implementation - tied between Codan and the latest version of Turd. Codan benefits from being much more straightforward, since it simply generates code and leaves the task of actually making it do something to the C compiler. Turd is necessarily a bit more complex, but it contains a full interpreter, handles both numbers and text, and still manages to be fairly easy to understand at a glance.

Wild card program - I suppose calculating π to 1000 decimal places could surely be considered "useful" for some definition of the term, and it was fairly entertaining to see it after spending several minutes looking at the code and not having a clue what it did. Turd's SUSSMAN printer definitely wins in terms of trolling value, though.

Overall, it's a close choice between Codan and Turd. Since Turd is overall a more usable language (having implemented the largest set of implemented programs of all those submitted), owing to its long and open development cycle, and thanks to its text processing capabilities that seem to be absent from Codan, I would be inclined to award the winning prize in favor of it. Unfortunately, its author appears not to have a /prog/mail address, so I suppose I will have to award the ten Susscoins to Codan.

I should note that I am intentionally not including Soda in the voting: first because it was submitted late, but more importantly to avoid a conflict of interest (since I wrote it).

On a side note, I'm somewhat disappointed in the absence of LISP here. Maybe the lengthy development process of Arc and similar such projects are an indication that this is because implementing a language in Lisp is an inherently difficult and time-consuming process which couldn't be accomplished in such a short time frame. Although the prize has been awarded for this challenge already, perhaps we will still see more implementations here in the coming months.

Name: Anonymous 2010-06-21 11:56

I'll be trying to finish my language, too. I'll post it here in the future for /Prague/riders to evaluate.

Name: Anonymous 2010-06-21 11:59

>>142
There's no lisp because making lisp interpreters in lisp is easy if not cheating (no need for writing one's own parser, free AST representation, homoiconicity of the language giving you cheap low-level macros and making eval easy to describe in itself). The tricky part is making something new, which is what the challenge is. Reimplementing someone else's lisp is easy. Inventing some new unique semantics or ideas that nobody else had is something much harder and rarer in the Lisp world, because just about anything was already tried.
Trivial interpreters can be expressed in a single page of code.

Of course, some simple esolangs shouldn't be hard to make in it, but it's more fun to try to create something which you could find useful yourself.

Name: Anonymous 2010-06-21 12:07

>>144
YHBT.

Name: Anonymous 2010-06-21 12:09

>>142
>>64 could potentially have won in that respect, as I don't recall having seen a language written horizontally like that.
Are you serious? I got bored, figured I wouldn't win anyway, and quit writing it. God damn it.

Anyways, congratulations, Xarn.

Name: Anonymous 2010-06-21 13:45

Xarn wins. Life goes on as always.

Name: Anonymous 2010-06-21 14:02

I considered adding a %d/%c output toggle to Codan (like the # of the Optimising Brainfuck via-C Compiler which inspired it; though the function of # varies wildly from Brainfuck implementation to implementation) so I could implement a bunch of ciphers and CGOL in it, but decided an entirely numerical language would be purer and more annoying to work with.
I'm actually surprised how many working entries we ended up with, even if they weren't terribly adventurous. Way to go, /prog/.

Name: Anonymous 2010-06-21 14:05

>>148
Yeah, at least three. All were imperative, leading me to assume that the anusdolytes with the most free time also have the least originality.

Name: Anonymous 2010-06-21 14:41

>>149
Or perhaps because a non-imperative language is generally more difficult to implement.

Name: Anonymous 2010-06-21 18:16

TURD AUTHOR HERE: Why do the winner need a /prog/mail to get the susscoins :-(

Name: Anonymous 2010-06-21 18:19

Or perhaps because Xarn.

Name: Anonymous 2010-06-21 18:47

Turd was fucking impressive. Why didnt it win?

Name: Anonymous 2010-06-21 18:53

>>153
What was so impressive about it? It's a nice little language, but it's hardly revolutionary.

Name: Anonymous 2010-06-21 18:55

>>153
Turd won, but the Sußcoins were awarded to Codan due to a lack of /prog/mail.

Name: Anonymous 2010-06-21 18:57

Turd and Codan tied. In fairness, both deserved to lose.

Name: Anonymous 2010-06-21 19:31

>>156
LOSE MY ANUS

Name: Anonymous 2010-06-21 19:53

I've just added a switch statement to turd

Name: Anonymous 2010-06-21 20:06

>>158
Too much. KISS

Name: Anonymous 2010-06-21 20:47

>>154
Nothing here was revolutionary.

Name: Anonymous 2010-06-22 1:16

>>149
at least one was not imperative.

Name: Anonymous 2010-06-22 10:36

>>161
How so?

Name: Anonymous 2010-06-22 18:21

>>161
that stack one is a concatenative language.

Name: Anonymous 2010-06-22 18:26

Codan actually has a proof of Touring completeness. That's nice.

http://esolangs.org/wiki/Codan#Turing_completeness

Name: Anonymous 2010-06-22 18:46

>>164
Turd solves NP complete problems in linear time

Name: Anonymous 2010-06-22 20:27

>>163
Every one of the languages here was implemented in C, Python, or Perl.

Name: Anonymous 2010-06-22 20:28

Name: Anonymous 2010-06-23 0:28

>>166
ghc is written in c, but that doesn't make haskell imperative.

Name: Anonymous 2010-06-23 1:32

>>167
To be fair, Xarn wrote the Codan article himself, and Turd is a work in progress.

Name: Anonymous 2010-07-16 16:22

I don't understand codan...

It seems to me to be just a way to put unicode into variables.

Name: Anonymous 2010-09-18 10:54

Not enough Xarn on /xarn/ these days.

    /´. _, -―-、ヽ、
  ./  l´[☆ィTfヘマ、 ヽ
 |  | |ィケリノ |ト}!l|
 | _| レァ予  伝yリ|    ,..、
  | fr| 《{_丿   Ljハ∥  _,ノ/`il  /
  | ゞ||'''  r‐ァ`,ツイイ´  ハ il      PROGGLES
 |  | 「`}T 云'I「|{ {::::{ V リ   \
 || N {`ヾー弋イノ`衣√`ヾノ
  从 | l! Y   Qヘ\イ乍}
    `ヽハ l〉    Y´ア´
      レ´       「´

Name: Anonymous 2010-09-18 11:54

>>171
BUMP MY NECROFETIC ANUS

Name: Anonymous 2010-09-18 14:14

>>171
Sadly, I have to agree with you.

Name: Anonymous 2010-09-19 9:38

>>158
New Turd release, now.

Name: Anonymous 2010-09-19 10:01

>>174
sorry, turd is untouched since then. the one letter variable system was not right for the perfect language that i will one day write. also i wasn't happy with \n terminated lines as it hindered the writing of ugly terse one-liners. and also it was a massive hack designed at the keyboard.

Name: Anonymous 2010-09-19 12:26

A beautiful, inspiring thread.

Name: Anonymous 2010-11-15 0:25

Name: Anonymous 2011-03-03 5:13

prog was good once

Name: Anonymous 2011-03-03 5:41

>>178
Sup, XARN

Name: Anonymous 2011-03-03 5:44

It's not complete and I'm still working on the syntax.

(require parser-tools/yacc
         parser-tools/lex
         (prefix-in : parser-tools/lex-sre))


(define-empty-tokens infix-operators (cons append + * - ^ / // > < >= <= = :=))

(define-empty-tokens separators (comma open-paren close-paren
                                       open-bracket close-bracket
                                       open-brace close-brace
                                       => assign eof))

(define-empty-tokens keywords (ellipsis eq? eqv? equal? quote lambda let let* letrec in nil if then else cond))

(define-tokens values (lisp number identifier string))

(define-lex-abbrevs
  (%digit (:/ #\0 #\9))
  (%idchr (:or alphabetic "?" "!" "_"))
  (%string (:: #\" (complement (:: any-string #\" any-string)) #\"))
  (%number (:or (:+ %digit)
                (:: (:+ %digit) #\. (:+ %digit))))
  (%identifier (:: %idchr (:* (:or %digit %idchr)))))

(define lexit
  (lexer
   ((eof) 'eof)
   ((:: "--" (complement (:: any-string #\newline any-string)) #\newline) (lexit input-port))
   ((:: "{-" (complement (:: any-string "-}" any-string)) "-}") (lexit input-port))
   ((:or #\tab #\space #\newline) (lexit input-port))
   ((:or "=" ">=" "<=" ">" "<" "^" ":="
         "+" "*" "-" "/" "//") (string->symbol lexeme))
   ((:or "let" "let*" "letrec" "in" "if" "cond" "=>" "eq?" "eqv?" "equal?"
         "then" "else" "nil") (string->symbol lexeme))
   ((:or "λ" "lambda") (token-lambda))
   ((:or "'" "quote") (token-quote))
   ("..." (token-ellipsis))
   (":" (token-cons))
   ("++" (token-append))
   ("," (token-comma))
   ("{" (token-open-brace))
   ("}" (token-close-brace))
   ("[" (token-open-bracket))
   ("]" (token-close-bracket))
   ((:: "#(" any-string ")#") (token-lisp (substring lexeme 2 (- (string-length lexeme) 2))))
   ("(" (token-open-paren))
   (")" (token-close-paren))
   (%number (token-number (string->number lexeme)))
   (%string (token-string lexeme))
   (%identifier (token-identifier (string->symbol (regexp-replace* #rx"_" lexeme "-"))))))

(define parseit
  (parser
   (start top)
   (end eof)
   (tokens infix-operators separators keywords values)
   (error (λ x (displayln x)))
  
   (precs (right quote)
          (left + *)
          (left - / //)
          (right ^)
          (right cons append)
          (nonassoc >= > < <=)
          (right =)
          (right :=)
          (right comma))
  
   (grammar
    (top (() #f)
         ((stmt) $1)
         ((stmts) `(begin ,@$1))
         )
   
    (stmts
     ((stmt) `(,$1))
     ((stmt stmts) `(,$1 ,@$2)))
   
    (value
     ((number) $1)
     ((string) $1)
     ((fun) $1)
     ((nil) ''())
     ((list) `(quote ,$1))
     ((quote expr) `(quote ,$2)))
   
    (values
     ((value) `(,$1))
     ((value comma values) `(,$1 ,@$3)))
   
    (list
     ((open-bracket close-bracket) ''())
     ((open-bracket values close-bracket) `(,@$2)))
   
    (stmt
     ((expr) $1)
     ((identifier := expr) `(define ,$1 ,$3))
     ((identifier = expr) `(set! ,$1 ,$3)))
   
    (expr
     ((value) $1)
     ((fun) $1)
     ((lisp) $1)
     ((let bindings in expr) `(let ,$2 ,$4))
     ((let* bindings in expr) `(let* ,$2 ,$4))
     ((letrec bindings in expr) `(letrec ,$2 ,$4))
     ((cond condcases) `(cond ,@$2))
     ((if expr then expr) `(if ,$2 ,$4 #f))
     ((if expr then expr else expr) `(if ,$2 ,$4 ,$6))
     ((open-paren expr close-paren list-of-exprs) `(,$2 ,@$4))
     ((fun list-of-exprs) `(,$1 ,@$2))
     ((- expr) `(- ,$2))
     ((expr + expr) `(+ ,$1 ,$3))
     ((expr * expr) `(* ,$1 ,$3))
     ((expr / expr) `(/ ,$1 ,$3))
     ((expr // expr) `(quotient ,$1 ,$3))
     ((expr ^ expr) `(expt ,$1 ,$3))
     ((expr - expr) `(- ,$1 ,$3))
     ((expr > expr) `(> ,$1 ,$3))
     ((expr < expr) `(< ,$1 ,$3))
     ((expr >= expr) `(>= ,$1 ,$3))
     ((expr <= expr) `(<= ,$1 ,$3))
     ((expr = expr) `(= ,$1 ,$3))
     ((expr eq? expr) `(eq? ,$1 ,$3))
     ((expr eqv? expr) `(eqv? ,$1 ,$3))
     ((expr equal? expr) `(equal? ,$1 ,$3))
     ((expr cons expr) `(cons ,$1 ,$3))
     ((expr append expr) `(append ,$1 ,$3))
     ((open-paren expr close-paren) $2)
     ((open-brace exprs close-brace) `(begin ,@$2))
     ((lambdaexpr) $1)
     )
   
    (exprs
     ((expr) `(,$1))
     ((expr exprs) `(,$1 ,@$2)))
   
    (lambdaexpr ((lambda list-of-identifiers expr) `(lambda ,$2 ,$3)))
   
    (list-of-exprs
     ((open-paren close-paren) '())
     ((open-paren cexprs close-paren) $2))
   
    (cexprs
     ((expr) `(,$1))
     ((expr comma cexprs) `(,$1 ,@$3)))
   
    (identifiers
     (() '())
     ((identifier) `(,$1))
     ((identifier ellipsis) $1)
     ((identifier comma identifiers) `(,$1 ,@$3)))
   
    (list-of-identifiers
     ((open-paren identifiers close-paren) $2))
   
    (fun
     ((identifier) $1)
     ((open-paren + close-paren) '+)
     ((open-paren * close-paren) '*)
     ((open-paren / close-paren) '/)
     ((open-paren // close-paren) 'quotient)
     ((open-paren - close-paren) '-)
     ((open-paren > close-paren) '>)
     ((open-paren < close-paren) '<)
     ((open-paren = close-paren) '=)
     ((open-paren >= close-paren) '>=)
     ((open-paren <= close-paren) '<=)
     ((open-paren eq? close-paren) 'eq?)
     ((open-paren eqv? close-paren) 'eqv?)
     ((open-paren equal? close-paren) 'equal?)
     ((open-paren ^ close-paren) 'expt)
     ((open-paren cons close-paren) 'cons)
     ((open-paren append close-paren) 'append))
   
    (condcases
     ((condcase) `(,$1))
     ((condcase condcases) `(,$1 ,@$2)))
   
    (condcase
     ((open-bracket expr close-bracket) `(,$2))
     ((open-bracket expr expr close-bracket) `(,$2 ,$3))
     ((open-bracket expr => fun close-bracket) `(,$2 => ,$4))
     ((open-bracket else expr close-bracket) `(else ,$3)))
   
    (bindings
     ((binding) `(,$1))
     ((binding comma bindings) `(,$1 ,@$3)))
   
    (binding
     ((identifier = expr) `(,$1 ,$3))))))

(define (parse-port ip)
  (port-count-lines! ip)
  (letrec ((one-line
            (lambda ()
              (let ((result (parseit (lambda () (lexit ip)))))
                (if result result (one-line))))))
    (one-line)))
(define (parse-string s)
  (parse-port (open-input-string s)))

(parse-string "
fact := λ(x) letrec loop = λ(x,n) if zero?(x) then n else loop(x-1,x*n) in loop(x,1)
fibs := λ(x) letrec loop = λ(a,b,x,r) if zero?(x) then reverse(a:r) else loop(b,a+b,x-1,a:r) in loop(0,1,x,nil)
")
;'(begin
;   (define fact (lambda (x) (letrec ((loop (lambda (x n) (if (zero? x) n (loop (- x 1) (* x n)))))) (loop x 1))))
;   (define fibs (lambda (x) (letrec ((loop (lambda (a b x r) (if (zero? x) (reverse (cons a r)) (loop b (+ a b) (- x 1) (cons a r)))))) (loop 0 1 x '())))))

Name: Anonymous 2011-03-03 6:36

>>180
i think you missed the entry date

Name: Anonymous 2011-03-03 6:40

>>181
I'm prepared for the next one if there will be another

Name: Anonymous 2011-03-03 10:36

>>182
Why the hell would a challenge repeat itself?

Name: Anonymous 2011-03-03 10:38

>>183
So that the room will be empty.

Name: Anonymous 2011-03-03 12:06

>>184
A U T I S M

Name: Anonymous 2011-03-03 21:11

DICKS

Name: Anonymous 2011-03-04 4:27

lol dicks

Name: Anonymous 2011-03-04 5:48

<--- check em

Name: Anonymous 2011-03-04 7:11

>>188
Not nice. You have LeadingOne disease. And autism.

Name: Anonymous 2012-10-03 6:00

/prog/ Challenge
Why don't we have such threads anymore?

Name: Harry Pothead 2012-10-03 6:15

The game of Nim (http://en.wikipedia.org/wiki/Nim)
Da flying nimbus.

Name: Anonymous 2012-10-03 6:51

>>190
Because everyone who knew enough about programming left this boards long ago.

Only trolls and clueless first-grade CS students remain here.

Name: Anonymous 2012-10-03 11:50

>>192
Are you a troll or a clueless first-grade CS student?

Name: Anonymous 2012-10-03 13:20

>>192
Expert programmer here, I wrote an ANSI C compiler when I was 9.

Name: Anonymous 2012-10-03 14:23

>>194
I masturbated to Yukari when I was 8.

Name: Anonymous 2012-10-03 14:30

>>194
ANSI C a shit. You should be ashamed of yourself.

Name: Anonymous 2012-10-03 14:50

>>196
As soon as I finished it, I realized C was undefined shit, so I wrote a JIT-accelerated Lisp interpreter in assembly; it took me a bit longer than a week to complete it because I had promised Gerry to correct the final draft of SICP and it was chock-full of stupid mistakes.

Name: Anonymous 2012-10-03 16:23

>>197
I want to suck your dick.

Name: Anonymous 2012-10-03 21:26

>>190
Because you don't bother to start them. We had http://dis.4chan.org/read/prog/1337015808 only a few months ago. /prog/ may be full of Redditors now, but it's still possible to do this sort of thing.

Name: Anonymous 2012-10-03 22:43

>>198
HEY I WAS THERE FIRST!

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