Live data from Hacker News

Anonymous functions in C

github.com

1–10 of 51 posts

Re: Anonymous functions in C

#2
This is basically a way of obfuscating your C code. If you want to write obfuscated code, C++ has extensive support for this. I think it's actually a strength of C to not have many features. It ultimately makes code more readable and reliable.

Re: Anonymous functions in C

#3
That's neat, but without closures I don't really see how you could do much with it outside of toy examples. Going off the examples -- how often do you write something like a foreach or a map or reduce that doesn't reference its enclosing scope?

Re: Anonymous functions in C

#4
post #2

This is basically a way of obfuscating your C code. If you want to write obfuscated code, C++ has extensive support for this. I think it's actually a strength of C to not have many features. It ultimately makes code more readable and reliable.

I don't think I can agree more with your comment.

C++ in fact is only usable (in a team) if its features are pruned and limited in a team. Really

Throw in some fine preprocessor magic and you'll end up with completely unmaintanable and impossible to understand code.

Re: Anonymous functions in C

#5
Anonymous (or inner) functions aren't really valuable per se but syntactic sugar for writing the code into a static function somewhere in the same file: closures give anonymous (or inner) functions the power which is what makes them useful.

Re: Anonymous functions in C

#6
post #2

This is basically a way of obfuscating your C code. If you want to write obfuscated code, C++ has extensive support for this. I think it's actually a strength of C to not have many features. It ultimately makes code more readable and reliable.

I don't think I can agree more with your comment. C++ in fact is only usable (in a team) if its features are pruned and limited in a team. Really Throw in some fine preprocessor magic and you'll end up with completely unmaintanable and impossible to understand code.

Yeah. C is a boring language that barely ever changes. But I'm not sure there isn't wisdom in being dull.

Re: Anonymous functions in C

#7
post #3

That's neat, but without closures I don't really see how you could do much with it outside of toy examples. Going off the examples -- how often do you write something like a foreach or a map or reduce that doesn't reference its enclosing scope?

If you look at Redroid (a project which makes extensive use of lambdapp) you'll see how map/list/etc can take advantage of this https://github.com/graphitemaster/redroid hashtable.c and list.c look for [hashtable|list]_foreach. Another good example is config_save in config.c.

Re: Anonymous functions in C

#8
post #3

That's neat, but without closures I don't really see how you could do much with it outside of toy examples. Going off the examples -- how often do you write something like a foreach or a map or reduce that doesn't reference its enclosing scope?

You could do closure conversion, but then you run into problems with the lifetimes of things, oh and then you're basically reimplementing lisp.

Re: Anonymous functions in C

#9
post #6

Earlier quoted context omitted.

I don't think I can agree more with your comment. C++ in fact is only usable (in a team) if its features are pruned and limited in a team. Really Throw in some fine preprocessor magic and you'll end up with completely unmaintanable and impossible to understand code.

Yeah. C is a boring language that barely ever changes. But I'm not sure there isn't wisdom in being dull.

Compound literals in C are awesome like it's 1999:

Assuming you have this:

   struct point {
      float x, y, z;
   };
   void do_something_with_point(struct point *p);
You can do this:

   do_something_with_point(&(struct point){.x = 1.5, .y = 1.5, .z = 3.5});

Re: Anonymous functions in C

#10
post #2

This is basically a way of obfuscating your C code. If you want to write obfuscated code, C++ has extensive support for this. I think it's actually a strength of C to not have many features. It ultimately makes code more readable and reliable.

Anonymous functions are a way of de-obfuscating code that is heavy in callbacks. Instead of having the logic flow indirectly to some external method that might be far away, the logic can live within one function body.
Post reply on HN