Name: Anonymous 2011-09-07 23:03
So while watching the Baywatch that takes place on Hawaii I came up with this thing in GNU-C.
I don't know any Lisp or any Lambda calculus but I was wondering if these qualify for ``closures'' and/or ``anonymous functions''?
If it helps you may also nest the definitions and call the functions directly like this:
No doubt the syntax is horrendous, there's probably some way to prettify it.
The Baywatch that takes place in Hawaii is pretty good in my opinion, it has David Hasselhoff as its executive producer I think. I just watched an episode where a stalker starts liking, dating and stalking one of the Baywatch women and she wears really suggestive clothing, I wasn't really paying attention but I think he (the stalker) earlier in the episode shot some other dude under the water in the hand (I think it was the stalkers friend but I'm not sure) with a harpoon and he was all like ``it was an accident!'' but people were like meh. Later on he knew the Baywatch ladies preference (it was that she liked soy milk in her coffee) without her ever telling him to which she was like wow this is weird. He later showed up at her house and he had turned the gas on and was acting all crazy and knocked the Baywatch lady out, she was like ``oh my god!'' and he was like ``I'M GOOD FOR YOU!'' with a really angry face but then he got knocked out by one of the Baywatch dudes and they saved the chick. Some other chick was dating a dude that was about to enter the witness protection program I don't know what the deal was but I think it was the Mafia that was after him.
I don't know any Lisp or any Lambda calculus but I was wondering if these qualify for ``closures'' and/or ``anonymous functions''?
#include <stdlib.h>
#include <stdio.h>
#define lambda(type, ...) \
({ \
type (*__lambda_fptr)(__VA_ARGS__); \
type __lambda(__VA_ARGS__)
#define lambda_end \
__lambda_fptr = __lambda; \
})
int main(void) {
int i, * array;
const int size = 10;
array = malloc(size * sizeof(int));
for (i = 0; i < size; i++)
array[i] = -i;
qsort(
array,
size,
sizeof(int),
lambda(int, const void * _a, const void * _b) {
int * a = (int *) _a;
int * b = (int *) _b;
return *a - *b;
} lambda_end );
for (i = 0; i < size; i++)
printf("%d: %d\n", i, array[i]);
free(array);
return 0;
}If it helps you may also nest the definitions and call the functions directly like this:
#include <stdio.h>
#define lambda(type, ...) \
({ \
type (*__lambda_fptr)(__VA_ARGS__); \
type __lambda(__VA_ARGS__)
#define lambda_end \
__lambda_fptr = __lambda; \
})
int main(void) {
printf("%f\n",
lambda(double, double x) {
return 2.0 * lambda(double, double x) {
return 3.0 * x;
} lambda_end (x);
} lambda_end (5.0) );
return 0;
}No doubt the syntax is horrendous, there's probably some way to prettify it.
The Baywatch that takes place in Hawaii is pretty good in my opinion, it has David Hasselhoff as its executive producer I think. I just watched an episode where a stalker starts liking, dating and stalking one of the Baywatch women and she wears really suggestive clothing, I wasn't really paying attention but I think he (the stalker) earlier in the episode shot some other dude under the water in the hand (I think it was the stalkers friend but I'm not sure) with a harpoon and he was all like ``it was an accident!'' but people were like meh. Later on he knew the Baywatch ladies preference (it was that she liked soy milk in her coffee) without her ever telling him to which she was like wow this is weird. He later showed up at her house and he had turned the gas on and was acting all crazy and knocked the Baywatch lady out, she was like ``oh my god!'' and he was like ``I'M GOOD FOR YOU!'' with a really angry face but then he got knocked out by one of the Baywatch dudes and they saved the chick. Some other chick was dating a dude that was about to enter the witness protection program I don't know what the deal was but I think it was the Mafia that was after him.