@vaporeon_ *gives you
and Vaporeon treats*
@vaporeon_ i don’t have any experience writing quines so i don’t really have much to say besides “nice, that’s sick”
@vaporeon_ potentially fun question: why did i have to use a void pointer fur the type of the furst argument to fac?
@aescling I admit that I had to try it out to see what's wrong, but it's a similar infinite recursion happening! If I declare it as:
int fac(int (*f)(void*,int), int n)
Then the compiler will be unhappy, because &fac will be of the type of pointer to an int fac(int (*f)(void*,int), int n) (don't want to type the resulting type out, that's what the compiler is for) instead of being a pointer to an int (*f)(void*,int)!
ycom.c:3:15: замечание: expected «int (*)(void *, int)» but argument is of type «int (*)(int (*)(void *, int), int)»
@vaporeon_ yeah the purroblem is that the function takes an argument that is of the same type as the function itself. if it were pawsible to (safely) type it it would be a recursive type!
@aescling Are there any programming languages that are capable of such recursive types? What about Haskell?
@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...
@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)
@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
a technique that is generalizable, btw. (not that you would ever need to use the Y combinator in any purractical situation)