User:Tpaefawzen/Notes

From Esolang
Jump to navigation Jump to search

Dis step function

#pragma once

typedef unsigned short DisInt;
static void assertIsDis(DisInt x) {
   if (x >= 59049)
      __builtin_trap();
}

typedef enum {
   DisStepOk,
   DisStepOkWritten,
   DisStepOkRead,
   DisStepHalt,
   DisStepWantRead,
   DisStepWantWrite,
} StepResult;

static DisInt rot(DisInt);
static DisInt opr(DisInt, DisInt);

static StepResult dis_step(DisInt *a, DisInt *c, DisInt *d, DisInt mem[59049],
      _Bool can_write, unsigned char *outc,
      _Bool is_eof, _Bool can_read, unsigned char in_ch)
{
   StepResult r = DisStepOk;

   assertIsDis(*a); assertIsDis(*c); assertIsDis(*d);
   assertIsDis(mem[*c]);
   assertIsDis(mem[*d]);

   DisInt x = mem[*c];
   if (x == 33) {
      return DisStepHalt;
   } else if (x == 42) {
      *d = mem[*d];
   } else if (x == 62) {
      *a = mem[*d] = rot(mem[*d]);
   } else if (x == 94) {
      *c = mem[*d];
   } else if (x == 123) {
      if (*a == 59048) {
         return DisStepHalt;
      }
      if (can_write) {
         *outc = (unsigned char)*a;
         r = DisStepOkWritten;
      } else {
         return DisStepWantWrite;
      }
   } else if (x == 124) {
      *a = mem[*d] = opr(*a, mem[*d]);
   } else if (x == 125) {
      if (is_eof) {
         *a = 59048;
      } else if (can_read) {
         *a = (unsigned char)in_ch;
         r = DisStepOkRead;
      } else {
         return DisStepWantRead;
      }
   }

   *c = (*c + 1) % 59049;
   *d = (*d + 1) % 59049;

   return DisStepOk;
}

Grass is procedural language

Output double u sixteen times

ww
  WWw
  WWWw
v
w
  WWww
  Wwww
  Wwwwww
  Wwwwwwwww

Styled
f1 = read
f2 = 119
f3 = next
f4 = out
f5 v5 v6 =
  let v7 = v5 v6 in
  let v8 = v5 v7 in
  v8
f6 v6 =
  let v7 = f5 f5 in
  let v8 = v7 f5 in
  let v9 = v8 f4 in
  let v10 = v9 v2 in
  v10
main = f6 f6

f x y =
  let v = x y in
  x v

main' x =
  let v = f f in
  let v2 = v f in
  let v3 = v2 out in
  v3 119

THEREFORE

f x y = x (x y)
main' _ = ((f f) f) out 119
main = main' main'

Catプログラムとか言われてた gらっsおnawkのやつなんでeofのときにエラー吐かずにできたのか解析してみたら127が入るまでのcatだった

f1 = read
f2 = 119
f3 = next
f4 = out
f5 v5 v6 =
  let v7 = v5 v6 in
  let v8 = v5 v7 in
  v8
f6 v6 =
  let v7 = f5 f5 in
  let v8 = v7 f3 in
  let v9 = v8 f2 in
  let v10 = v8 v9 in
  let v11 = f1 v10 in
  let v12 = v11 v10 in
  let v13 = v12 v12 in
  let v14 = v13 f4 in
  let v15 = v14 v11 in
  let v16 = v13 v6 in
  let v17 = v16 v6 in
  v17
return f6 f6

mazu f6 f6 is
f6 nite let v7 is f5 f5 in
let v8 is v7 f3 is
  f5 f5 f3 is do
    let v5 is f5 v6 is f3 in
    let v7 is v5 v6 is f5 f3 in
    return v8 is f5 (f5 f3)
  therefore v8 is f5 (f5 f3)
let v9 is v8 f2 is f5 (f5 f3) f2 is do
  let v5 is (f5 f3) and v6 is f2 in
  let v7 is v5 v6 is f5 f3 f2 is do
    let v5 is f3 v6 is f2 do
    let v7 is f3 f2 is next 119 is 120
    ret v5 v7 is next 120 is 121
  is 121 in
  let v8 is v5 v7 is (f5 f3) 121 is do
    let v5 is f3 v6 is 121 do
    return 123
  iZ 123 in
  return 123
is 123 in
let v10 is v8 v9 is f5 (f5 f3) 123 is do
  return 127
is 127 in
let v11 is f1 v10 is read 127 is
range 0 thru 255 in
let v12 is v11 v10 is 0thru255 127 is
either False or True in
let v13 is v12 v12 is
  if v12 is False then id
  else const True
in
let v14 is v13 f4 is Either(id, const True) out in
let v15 is v14 v11 is Either
  id out 0thru255 is Output 0thru255 then 0thru255
  const True 0thru125 is True
in
let v16 is v13 v6 is Either
  id f6 is f6
  const True f6 is True
in
let v17 is v16 v6 is Either
  f6 f6 is ...
  True f6
in
return v17

なんかすごい立体的な高階関数を定義してたのかと思ってたけど違った。0から255まで全部を一つずつ比較して最終的にどれにも合致しなかったら終わるやつなのかと思ってたけど違った。少しがっかり。でも頑張れば作れるんでしょ?