Awake. Did not appreciate the nightmares. Blergh.

@vaporeon_ i don’t have any experience writing quines so i don’t really have much to say besides “nice, that’s sick”

@vaporeon_ the fact that printf template strings allow quines to happen is more or less the same idea as this hack to do general recursion without explicit recursion

#include <stdio.h>

int fac(void *f, int n) {
int (*g)(void *, int) = f;

if (n == 0) {
return 1;
}
return n * g(f, n - 1);
}

int main(void) {
printf("6! == %d\n", fac(&fac, 6));
}

a technique that is generalizable, btw. (not that you would ever need to use the Y combinator in any purractical situation)

@aescling Though I do wonder what the point of this construct is... You're still having fac recursively calling itself, so it still only works if your system / programming language supports recursion... If you tried this in a language that instead of allocating stack frames for each new function calls, for example, saved the return address at the start of the function and a recursive call overwrites it and breaks everything (that's what PDP-8 assembly does; I've heard something about ancient FORTRAN also not supporting recursion), then this construct won't help you...

Follow

@vaporeon_ it enables recursion-like behavior in with just lambda abstraction and application:

# (fun f n -> if n == 0 then 1 else n * f f (n - 1))
(fun f n -> if n == 0 then 1 else n * f f (n - 1))
6;;
- : int = 720

@vaporeon_ (i say "pure lambda calculus" but i'm using if statements and purrimitive types. you COULD actually do this in Pure Lambda Calculus but it would be a bit obnoxious)

Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.