[ prog / sol / mona ]

prog


Marvin Minsky - The Beauty of the Lisp Language

53 2020-10-07 01:45

Its not like loops are some magic fundamental to C that can't be re-implemented in other ways.
#include <stdio.h>
int main(){

#define sum(i,acc) acc+=i
#define sumprinti(i,acc) acc+=i;printf("%d,",i);
//lets abuse more GCC extensions:
#define loop(x,y,acc,func) ({ label loop1,end1;int i=0;\
static void *gotoarray[] = {&&loop1,&&end1};\
loop1:\
func(i,acc); i++; goto *gotoarray[i>y];end1:; acc;})
#define sumloop(x,y,func) ({int acc=0;loop(x,y,acc,func);})

sumloop(1,10,sumprinti);printf("\n%d",sumloop(1,10,sum));
}

301


VIP:

do not edit these