Skip to content

Commit

Permalink
lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
zaoqi committed Aug 5, 2018
1 parent 1f43b47 commit 0412770
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
10 changes: 7 additions & 3 deletions >require
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,9 @@ _HELPER_prelude_staticDefine_inlineDefine_ void make_void(){}
#define _HELPER_prelude_if_then_else_A_(b) (b): _HELPER_prelude_if_then_else_B_
#define _HELPER_prelude_if_then_else_B_(b) (b))

#define _HELPER_prelude_function_(value) {return (value);}
#define _HELPER_prelude_ignore_(x) _HELPER_prelude_global_nothing_
/*例 lambda(int, int x, int y)({x+y;}) */
#define lambda(return_type, ...) ({return_type _TEMP_prelude_lambda_(__VA_ARGS__) _HELPER_prelude_lambda_
#define _HELPER_prelude_lambda_(value) {return (value);}_TEMP_prelude_lambda_;})

/*参考https://blog.csdn.net/u011787119/article/details/53815950*/
#define _HELPER_prelude_ATTR_(args) args
Expand All @@ -629,6 +630,9 @@ _HELPER_prelude_staticDefine_inlineDefine_ void make_void(){}
(__VA_ARGS__))

#define declare_public(t, n) extern t n
#define _HELPER_prelude_function_(value) {return (value);}
#define _HELPER_prelude_ignore_(x) _HELPER_prelude_global_nothing_


#endif//_HEAD_prelude_static_

Expand All @@ -651,7 +655,7 @@ _HELPER_prelude_staticDefine_inlineDefine_ void make_void(){}
# define _HELPER_prelude_define_public2(t, n) declare_public(t, n);t n
#endif

/*例子
/*
define_private_function(int add(int x, int y))({
x+y;
});*/
Expand Down
8 changes: 8 additions & 0 deletions example-lambda.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "module<"
#include "stdio.h"
define_public_function(int main())({
int (*f)(int)=lambda(int, int x)(x+1);
printf("%d", f(1));
0;
})
#include ">module"
10 changes: 7 additions & 3 deletions module<
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ _HELPER_prelude_staticDefine_inlineDefine_ void make_void(){}
#define _HELPER_prelude_if_then_else_A_(b) (b): _HELPER_prelude_if_then_else_B_
#define _HELPER_prelude_if_then_else_B_(b) (b))

#define _HELPER_prelude_function_(value) {return (value);}
#define _HELPER_prelude_ignore_(x) _HELPER_prelude_global_nothing_
/*例 lambda(int, int x, int y)({x+y;}) */
#define lambda(return_type, ...) ({return_type _TEMP_prelude_lambda_(__VA_ARGS__) _HELPER_prelude_lambda_
#define _HELPER_prelude_lambda_(value) {return (value);}_TEMP_prelude_lambda_;})

/*参考https://blog.csdn.net/u011787119/article/details/53815950*/
#define _HELPER_prelude_ATTR_(args) args
Expand All @@ -108,6 +109,9 @@ _HELPER_prelude_staticDefine_inlineDefine_ void make_void(){}
(__VA_ARGS__))

#define declare_public(t, n) extern t n
#define _HELPER_prelude_function_(value) {return (value);}
#define _HELPER_prelude_ignore_(x) _HELPER_prelude_global_nothing_


#endif//_HEAD_prelude_static_

Expand All @@ -130,7 +134,7 @@ _HELPER_prelude_staticDefine_inlineDefine_ void make_void(){}
# define _HELPER_prelude_define_public2(t, n) declare_public(t, n);t n
#endif

/*例子
/*
define_private_function(int add(int x, int y))({
x+y;
});*/
Expand Down
10 changes: 7 additions & 3 deletions prelude.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ _HELPER_prelude_staticDefine_inlineDefine_ void make_void(){}
#define _HELPER_prelude_if_then_else_A_(b) (b): _HELPER_prelude_if_then_else_B_
#define _HELPER_prelude_if_then_else_B_(b) (b))

#define _HELPER_prelude_function_(value) {return (value);}
#define _HELPER_prelude_ignore_(x) _HELPER_prelude_global_nothing_
/*例 lambda(int, int x, int y)({x+y;}) */
#define lambda(return_type, ...) ({return_type _TEMP_prelude_lambda_(__VA_ARGS__) _HELPER_prelude_lambda_
#define _HELPER_prelude_lambda_(value) {return (value);}_TEMP_prelude_lambda_;})

/*参考https://blog.csdn.net/u011787119/article/details/53815950*/
#define _HELPER_prelude_ATTR_(args) args
Expand All @@ -107,6 +108,9 @@ _HELPER_prelude_staticDefine_inlineDefine_ void make_void(){}
(__VA_ARGS__))

#define declare_public(t, n) extern t n
#define _HELPER_prelude_function_(value) {return (value);}
#define _HELPER_prelude_ignore_(x) _HELPER_prelude_global_nothing_


#endif//_HEAD_prelude_static_

Expand All @@ -129,7 +133,7 @@ _HELPER_prelude_staticDefine_inlineDefine_ void make_void(){}
# define _HELPER_prelude_define_public2(t, n) declare_public(t, n);t n
#endif

/*例子
/*
define_private_function(int add(int x, int y))({
x+y;
});*/
Expand Down
10 changes: 7 additions & 3 deletions require<
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,9 @@ _HELPER_prelude_staticDefine_inlineDefine_ void make_void(){}
#define _HELPER_prelude_if_then_else_A_(b) (b): _HELPER_prelude_if_then_else_B_
#define _HELPER_prelude_if_then_else_B_(b) (b))

#define _HELPER_prelude_function_(value) {return (value);}
#define _HELPER_prelude_ignore_(x) _HELPER_prelude_global_nothing_
/*例 lambda(int, int x, int y)({x+y;}) */
#define lambda(return_type, ...) ({return_type _TEMP_prelude_lambda_(__VA_ARGS__) _HELPER_prelude_lambda_
#define _HELPER_prelude_lambda_(value) {return (value);}_TEMP_prelude_lambda_;})

/*参考https://blog.csdn.net/u011787119/article/details/53815950*/
#define _HELPER_prelude_ATTR_(args) args
Expand All @@ -625,6 +626,9 @@ _HELPER_prelude_staticDefine_inlineDefine_ void make_void(){}
(__VA_ARGS__))

#define declare_public(t, n) extern t n
#define _HELPER_prelude_function_(value) {return (value);}
#define _HELPER_prelude_ignore_(x) _HELPER_prelude_global_nothing_


#endif//_HEAD_prelude_static_

Expand All @@ -647,7 +651,7 @@ _HELPER_prelude_staticDefine_inlineDefine_ void make_void(){}
# define _HELPER_prelude_define_public2(t, n) declare_public(t, n);t n
#endif

/*例子
/*
define_private_function(int add(int x, int y))({
x+y;
});*/
Expand Down

0 comments on commit 0412770

Please sign in to comment.