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

Pages: 1-

Fuck You, Write Code

Name: Anonymous 2013-05-29 1:07

/prog/, I throw down a gauntlet to you.

From http://esolangs.org/wiki/Category:Unimplemented , select a programming language. Write an implementation for it and post it. If you want to pick something else and implement it better than what's already there, go for it. No prizes or shit, because real EXPERT PROGRAMMERS do it for the thrill of the chase.

(No, I'm not L.A. Calculus, I'm not angry enough.)

I'll throw my hand in as well, so you can at least get the satisfaction of laughing at me.  I might do CAT or Knight Shuffling Tower.

Name: Anonymous 2013-05-29 1:29

Just do a Lisp on ParrotVM.

We can always use new Lisps

Name: Anonymous 2013-05-29 2:00

Esoteric languages are stupid.

Name: Anonymous 2013-05-29 9:57

http://esolangs.org/wiki/Hexish

Fuck me some of these are dumb.

Anyway, Enigma2D
#include <stdio.h>
#include <stdlib.h>

// Counted string
typedef struct {
    char *data;
    size_t len;
} str;

// Counted array of counted strings
typedef struct {
    str *arr;
    size_t len;
} arr_strs;

arr_strs make_jagged_array(char *restrict in, size_t len) {
    char *linestart = in;
    size_t num_lines = 1;

    for (size_t i = 0; i < len; i++) {
        if (in[i] == '\r' || in[i] == '\n') {
            num_lines++;
            if (in[i] == '\r' && i + 1 < len && in[i + 1] == '\n') {
                i++;
            }
        }
    }

    str *jagg = malloc(sizeof(str) * num_lines);
    int line = 0;

    for (size_t i = 0; i < len; i++) {
        char c = *in;
        if (c == '\r' || c == '\n') {
            jagg[line++] = (str) {.data = linestart, .len = in - linestart};
            if (c == '\r' && i + 1 < len && *(in + 1) == '\n') { in++; i++; }
            linestart = in + 1;
        }
        in++;
    }
    jagg[line++] = (str) {.data = linestart, .len = in - linestart};

    return (arr_strs) {.arr = jagg, .len = line};
}

typedef struct {
    int row, col, dir_row, dir_col;
    int data_pointer, data_allocated;
    int *data;
    arr_strs script;
} interpreter_state;

void interpreter_error(char *error, interpreter_state *restrict s) {
    char *direction = "???";
    if (s->dir_row == 1 && s->dir_col == 0) direction = "Down";
    else if (s->dir_row == -1 && s->dir_col == 0) direction = "Up";
    else if (s->dir_row == 0 && s->dir_col == 1) direction = "Right";
    else if (s->dir_row == 0 && s->dir_col == -1) direction = "Left";

    fprintf(stderr, "\n---Error---\n%s\nLine %d char %d\nDirection: %s\nData pointer: %d\nData cells (hex):\n", error, s->row, s->col, direction, s->data_pointer);
    for (int i = 0; i < s->data_allocated; i++) {
        fprintf(stderr, "\t%08X: %08X\n", i, s->data[i]);
    }
}

int ensure_data(interpreter_state *restrict s) {
    if (s->data_pointer < 0) {
        interpreter_error("Tried to write to a negative address", s);
        return 0;
    }
    if (s->data_pointer >= s->data_allocated) {
        int orig_allocated = s->data_allocated;
        s->data_allocated = s->data_pointer + 1;
        s->data = realloc(s->data, s->data_allocated * sizeof(*s->data));
        if (s->data == NULL) {
            interpreter_error("Out of memory", s);
            return 0;
        }
        while (orig_allocated < s->data_allocated) {
            s->data[orig_allocated++] = 0;
        }
    }
    return 1;
}

int within_bounds(interpreter_state *restrict s) {
    if (s->row < 0 || s->col < 0) return 0;
    if (s->row >= s->script.len) return 0;
    if (s->dir_row == 0 && s->col >= s->script.arr[s->row].len) return 0;
    return 1;
}

int interpret_once(interpreter_state *restrict s) {
    switch (s->script.arr[s->row].data[s->col]) {
        case '<':
            s->data_pointer--;
            break;
        case '>':
            s->data_pointer++;
            break;
        case '+':
            if (!ensure_data(s)) return 0;
            s->data[s->data_pointer]++;
            break;
        case '-':
            if (!ensure_data(s)) return 0;
            s->data[s->data_pointer]--;
            break;
        case '.':
            if (!ensure_data(s)) return 0;
            putchar(s->data[s->data_pointer]);
            break;
        case ',':
            if (!ensure_data(s)) return 0;
            s->data[s->data_pointer] = getchar();
            break;
        case 'U':
            s->dir_row = -1;
            s->dir_col = 0;
            break;
        case 'D':
            s->dir_row = 1;
            s->dir_col = 0;
            break;
        case 'L':
            s->dir_row = 0;
            s->dir_col = -1;
            break;
        case 'R':
            s->dir_row = 0;
            s->dir_col = 1;
            break;
        case '[':
            if (!ensure_data(s)) return 0;
            if (s->data[s->data_pointer] == 0) {
                int num_brackets = 1;
                do {
                    s->row += s->dir_row;
                    s->col += s->dir_col;
                    if (!within_bounds(s)) break;

                    char c = s->script.arr[s->row].data[s->col];
                    if (c == '[') num_brackets++;
                    else if (c == ']') num_brackets--;
                } while (num_brackets > 0);

                if (!within_bounds(s)) {
                    interpreter_error("Fell off the end of the script looking for a \"]\"", s);
                    return 0;
                }
            }
            break;
        case ']':
            if (!ensure_data(s)) return 0;
            if (s->data[s->data_pointer] != 0) {
                int num_brackets = 1;
                do {
                    s->row -= s->dir_row;
                    s->col -= s->dir_col;
                    if (!within_bounds(s)) break;

                    char c = s->script.arr[s->row].data[s->col];
                    if (c == ']') num_brackets++;
                    else if (c == '[') num_brackets--;
                } while (num_brackets > 0);

                if (!within_bounds(s)) {
                    interpreter_error("Fell off the end of the script looking for a \"[\"", s);
                    return 0;
                }
            }
            break;
        case ' ':
            break;
        default:
            interpreter_error("Invalid opcode", s);
            return 0;
    }
    return 1;
}

void interpret(arr_strs script) {
    interpreter_state s = {.dir_col = 1, .script = script};
    while (within_bounds(&s)) {
        if (s.col < s.script.arr[s.row].len)
            if (!interpret_once(&s))
                break;
        s.row += s.dir_row;
        s.col += s.dir_col;
    }

    if (s.data != NULL) free(s.data);
}

int main(int argc, char **argv) {
    if (argc < 2) {
        puts("At least give me some files to execute.");
        return 0;
    }

    for (int i = 1; i < argc; i++) {
        FILE *f = fopen(argv[i], "rb");
        if (!f) {
            fprintf(stderr, "Could not open the script \"%s\": ", argv[i]);
            perror(NULL);
            continue;
        }

        fseek(f, 0, SEEK_END);
        long f_len = ftell(f);
        fseek(f, 0, SEEK_SET);

        char *script_raw = malloc(f_len);
        fread(script_raw, 1, f_len, f);

        fclose(f);

        arr_strs script = make_jagged_array(script_raw, f_len);
        interpret(script);
        free(script.arr);
        free(script_raw);
    }
}

Name: Anonymous 2013-05-29 9:59

Tested with a simple piece of shit script and then again with the script "+[,.+]" which acts like cat.

Spec: http://esolangs.org/wiki/Enigma-2D

Name: Anonymous 2013-05-29 15:15

White code is pig disgusting

Name: Anonymous 2013-06-02 5:20

>>1
I'll throw my hand in as well, so you can at least get the satisfaction of laughing at me
Take your fucking time OP.

Name: Anonymous 2013-06-02 15:26

I wrote a minimal functional extension for m4, so it is easy to port pure haskell code to m4:


changecom(`#',`')dnl
dnl#
dnl# `Id`
dnl#
define(Id, $1)dnl
dnl# `Lambda'
dnl#
define(Lambda, `define($1, `$2')')dnl
define(Curry1, `define($1,`$2'($3,$`'1,$`'2,$`'3,$`'4))')dnl
define(Curry2, `define($1,`$2'($3,$4,$`'1,$`'2,$`'3,$`'4))')dnl
define(Curry3, `define($1,`$2'($3,$4,$5,$`'1,$`'2,$`'3,$`'4))')dnl
define(Curry4, `define($1,`$2'($3,$4,$5,$6,$`'1,$`'2,$`'3,$`'4))')dnl
define(Curry5, `define($1,`$2'($3,$4,$5,$6,$7,$`'1,$`'2,$`'3,$`'4))')dnl
define(Curry6, `define($1,`$2'($3,$4,$5,$6,$7,$8,$`'1,$`'2,$`'3,$`'4))')dnl
dnl#
dnl# `Logical operators'
dnl#
define(True, 1)dnl
define(False,0)dnl
define(Not, `ifelse($1, True, False, `ifelse($1, False, True, `errprint(Not a bool)')')')dnl
define(isBool, `ifelse($1, True, True, `ifelse($1, False, True, False)')')dnl
define(And, `ifelse($1, True, `ifelse($2, True, True, False)', False)')dnl
define(Or, `ifelse($1, True, True, `ifelse($2, True, True, False)')')dnl
dnl#
dnl# `List operators'
dnl#
define(Empty, [])dnl
define(Prep, `ifelse($2,[],[$1;],[$1;`substr($2,1,decr(len($2)))')')dnl
define(App, `ifelse($2,[],[$1;],`substr($2, 0, decr(len($2)))'$1;])')dnl
define(Next, `substr($2,$1,1)')dnl
define(Getpos, `ifelse(Next($1,$2),$3,$1,`Getpos(incr($1), $2, $3)')')dnl
define(Head, `substr($1, 1, decr(Getpos(0, $1,;)))')dnl
define(Tail, `ifelse($1,[],`errprint(tail: empty list)',[`substr($1,incr(Getpos(0,$1,;)))')')dnl
define(Index, `ifelse($1,0,`Head($2)',`Index(decr($1), Tail($2))')')dnl
define(Null, `ifelse($1,[],True,False)')dnl
dnl# `Foldr continuation passing style'
dnl# Foldr :: (a -> b ->  b) -> b -> [a] -> b
define(_Step, `$4(`$1',$1(Head($3),$2),Tail($3))')dnl
define(Foldr, `ifelse(Null($3),True,$2,`_Step(`$1',$2,$3,`Foldr')')')dnl
dnl# `Foldl continuation passing style'
dnl# Foldl :: (b -> a -> b) -> b -> [a] -> b
define(_Stepl, `$4(`$1',$1($2,Head($3)),Tail($3))')dnl
define(Foldl, `ifelse(Null($3),True,$2,`_Stepl(`$1',$2,$3,`Foldl')')')dnl
dnl# `Sum example usage of Foldr'
define(Plus, `eval($1+$2)')dnl
define(Sum, `Foldr(`Plus',0,$1)')dnl
dnl# `Filter'
dnl# `Filter creates an locally scoped curried function, implemented withdefine..undefine'
dnl# ` ```$1''' is just a trick to get the function unpacked at the right place. Every passing
dnl# `removes a `' from the functionname'
dnl# Filter :: (a -> Bool) -> [a] -> [a]
define(_Stepf, `ifelse($1($2), True, Prep($2, $3), $3)')dnl
define(Filter,`Curry1(__Stepf,`_Stepf',```$1''')Foldr(`__Stepf',Empty,`$2')undefine(`__Stepf')')dnl
dnl# ZipWith zips two lists with a binary operation
dnl# zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
define(ZipWith,`ifelse(Null($1), True, [], `ifelse(Null($2), True, [], Prep($3(Head($1),Head($2)), ZipWith(Tail($1), Tail($2), `$3')))')')dnl


Some examples:

dnl#
dnl# Example ZipWith
dnl#
define(s, Prep(3, Prep(2, Empty)))dnl
define(t, Prep(3, Prep(3, Prep(4, Empty))))dnl
dnl#
Lambda(z,`eval($1-($2))')dnl
`ZipWith'(-) [3;2] [3;3;4] : ZipWith(s,t,`z')
dnl#
dnl# `Example foldr and foldl'
define(p, Prep(3,Prep(2,Prep(1, Empty))))dnl
Lambda(x,`eval($1-($2))')dnl
`foldr'(`x',0,[3;2;1]) is : Foldr(`x',0,p)
`foldl'(`x',0,[3;2;1]) is : Foldl(`x',0,p)
dnl#
dnl# Example filter
dnl#
Lambda(y, `eval($1 == 1 )')dnl
filter : Filter(`y', p)dnl

define(xs, Prep(3,Prep(4, Prep(5, Empty))))dnl
define(ys, Prep(9,Prep(8, Prep(7, Empty))))dnl

Add two lists together:

Lambda(fs, `eval($1 + $2)')dnl

ZipWith(xs, ys, `fs')


Monadic code would be difficult. Lisp code is portable too, unless you start to use call/cc or side effects, which will fuck everything up.

Name: Anonymous 2013-06-02 15:37

Name: Anonymous 2013-06-02 19:30

>>8
That isn't even esoteric. C/C++ templates on the other hand are.

Name: Anonymous 2013-06-02 19:31

just check them

Name: Anonymous 2013-06-02 19:33

>>10
other esoteric crap is
#define VectorType int
#include <vector_template>
#undef VectorType

which gets a lot of use in big C/C++ projects.

Name: Anonymous 2013-06-02 19:33

>>11
"check" what?

Name: Anonymous 2013-06-02 19:53

>>9
Yep! Set Theory is definitely esoteric. I dont understand why people treat mathematics like something normal and even use it to describe physical phenomena.

Name: L. A. Calculus !!wKyoNUUHDOmjW7I 2013-06-02 20:44

>>14
COS DEYRE A BUNCH OF RETOIDED MATH BOYS. DATS Y.

Name: Anonymous 2013-06-02 21:00

>>15
What is your favorite infinite set, Calculus-kun?

Name: Anonymous 2013-06-02 21:12

>>16
OUT OF MY THRED YA FUCKIN RETOID

Name: Anonymous 2013-06-02 21:18

>>17
Not before you answer my question.

What is your favorite infinite set, Calculus-kun?

Name: L. A. Calculus !!wKyoNUUHDOmjW7I 2013-06-02 21:39

>>18
TAKE THY SHIT FROM OUT THY MOUTH, AND TAKE THY MATH FROM OUT THY MIND.

Name: Anonymous 2013-06-02 21:42

>>19
Not before you answer my question.

What is your favorite infinite set, Calculus-kun?

Name: Anonymous 2013-06-02 22:30

>>22
fuck you, nice dubs

Name: Dubs Guy 2013-06-02 22:31

Fuck You, Check 'Em

Name: Anonymous 2013-06-02 22:42

>>22
checked

Name: Anonymous 2013-06-03 2:06

>>7
Yeah, I know I'm late.  I've got it almost working now, just some bugs with the AST generation.  It thinks it's supposed to generate arithmetic for every operation instead of functions.

Name: L. A. Calculus !!wKyoNUUHDOmjW7I 2013-06-03 2:21

>>20
REAPATRA! AREE SSSSYARRR REEHHEHF SSSSSSYARRR REEEHEHF SSSSSYARRRRR REHEHF!

HURGH! HURGH!

Name: Anonymous 2013-06-06 1:45

OP, late as fuck, of course.  I blame it on the fact that the sample programs on KST were actually incorrect.  I ended up doing actual AST building and such, so it's a bit too large to just post the code.

http://repo.or.cz/w/knight_shuffling_tower.git

Name: Anonymous 2013-06-06 13:11

Oh, I wrote a P′′ interpreter in Haskell a couple of days ago, but had forgotten to post it here:

{-# LANGUAGE TypeOperators #-}

module P'' where

import Control.Category ((>>>))
import Control.Lens hiding (Tape)
import Control.Monad

data Term = R | Lam | Seq Term Term | Loop Term
type Tape = Top :>> [Int] :>> Int

-- Run a P'' term over a tape, in an alphabet of size n.
-- Returns Nothing if the program moves off the tape. Note
-- that directions are flipped; the left-infinite tape is
-- implemented as a right-infinite list zipper.
runTerm :: Int -> Term -> Tape -> Maybe Tape
runTerm n R         = leftward
runTerm n Lam       = focus %~ (\x -> succ x `mod` n) >>> rightward
runTerm n (Seq p q) = runTerm n p >=> runTerm n q
runTerm n (Loop p)  = \tape ->
    case tape ^. focus of
        0 -> Just tape
        _ -> runTerm n p >=> runTerm n (Loop p) $ tape

-- Run a P'' program over an empty tape.
runP'' :: Int -> Term -> Maybe Tape
runP'' n p = runTerm n p blankTape
    where blankTape = zipper (repeat 0) & fromWithin traverse

Name: Anonymous 2013-06-06 19:53

>>27
Nice - I had actually seen that page go from Unimplemented to Implemented, but I didn't think to connect it with this thread.

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