[ prog / sol / mona ]

prog


Marvin Minsky - The Beauty of the Lisp Language

75 2020-10-07 10:46

#include <stdio.h>
#include <stdlib.h>
//this is probably the closest thing to first example
int main(){
#define evenp(x) (!((x)&1))
#define loop(loopbody,code) for(loopbody){code;}
#define loop1(x,y) ({typeof(x)* arr=malloc((y-x)*sizeof(x));size_t arr_index=0;\
loop(size_t a=x;a<y;a++,if(evenp(a))arr[arr_index++]=a);\
realloc(arr,arr_index*sizeof(x));\
arr;})
#define printint(x) printf(" %d",x)
/*
(loop for i upto 10
when (evenp i)
collect i)
*/
int* qarr=loop1(2,100);
loop(size_t z=0;qarr[z];z++,printint(qarr[z]));

}

301


VIP:

do not edit these