
https://bitcoin20xx.xyz/未来を変える暗号通貨を作っていこう
面白そうだったので,ちょっと作ってみました.
----------
#include <stdio.h>char* str = "#include <stdio.h>%c%cchar* str = %c%s%c;%c%cint main ( void )%c{%c printf( str, 10, str, 10, 10, 34, str, 34, 10, 10, 10, 10, 10, 10, 10 );/* Hello World!! */%c return 0;%c}%c";int main ( void )
{
printf( str, 10, 10, 34, str, 34, 10, 10, 10, 10, 10, 10, 10 );/* Hello World!! */
return 0;
}
----------C言語で,関数printfについて対角化して不動点を作ってみました.
全てのプログラムに対する不動点を作ろうとおもうと,本物のコンパイラを作ることになってしまいますが,特定の関数の不動点が欲しいだけだったら,その関数についてだけ対角化できればいいので...
-
{D(e)} = {e}{e}いわゆるクワインです.
C言語でもメモリイメージがわかると,カリー化可能な例だったりします(無理やり感は否めませんが).
#include<stdio.h>
typedef int(*F)(int);
int add(int a,int b){return a+b;}
static int add_a;
static int addn(int b){return add(add_a,b);}
/* ポイント1 static なところ */
F curried_add(int a){add_a=a;return addn;}
int main(){
F add10=curried_add(10);
/ ポイント2 add10のアドレスは,引数10を与えたcurried_addのアドレスになっています.add10(3)とcurried_add(10)(3)/
printf("%d = add10(3)\n",add10(3));
printf("%d = curried_add(10)(3)\n",curried_add(10)(3));
printf("%d = add(10,3)\n",add(10,3));
}
13 = add10(3)
13 = curried_add(10)(3)
13 = add(10,3)