TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Lambdas in C

111 pointsby wingoalmost 14 years ago

12 comments

epsalmost 14 years ago
In other words - he discovered gcc's ({ }) construct and decided to write a macros named <i>lambda</i> around it.<p><a href="http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_4.html#SEC62" rel="nofollow">http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_4.html#SEC62</a>
评论 #2718528 未加载
评论 #2720125 未加载
评论 #2718517 未加载
jensnockertalmost 14 years ago
Blocks, <a href="http://clang.llvm.org/docs/BlockLanguageSpec.txt" rel="nofollow">http://clang.llvm.org/docs/BlockLanguageSpec.txt</a><p>Much better solution to the problem, hopefully coming to standard GCC soon(tm).
评论 #2721553 未加载
broheealmost 14 years ago
Am I really out of my mind or is this not a lambda at all but just an anonymous function?
评论 #2718638 未加载
Kototamaalmost 14 years ago
<i>Note: unlike lambdas in functional languages, this lambda does not capture the containing environment.</i>
评论 #2718415 未加载
评论 #2718343 未加载
athomalmost 14 years ago
My favorite part: <i>l_anonymous_functions_name</i><p>Sorry, I just like the irony.
snorkelalmost 14 years ago
Cute, but functions pointers suit me just fine.
评论 #2720353 未加载
评论 #2721031 未加载
wbhartalmost 14 years ago
I have not been able to work out two things here:<p>1) If I define a lambda inside a function, I cannot return the lambda from the function and use it right?<p>2) Recursive lambdas are not possible on account of the lack of recursion in C macros (not sure if that even makes sense without 1).
chrisjsmithalmost 14 years ago
Isn't this a step closer to Greenspuns Tenth Rule?<p>"Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified, bug-ridden, slow implementation of half of CommonLisp"<p>(bar the environment/scope issue it avoids that is)
jpralmost 14 years ago
More accurate title would be "Something like, but not as useful or generic as, lambdas in gcc's dialect of C".
评论 #2720018 未加载
CPlatypusalmost 14 years ago
If I worked on static code analysis tools for a living, this would make me cry.
demallienalmost 14 years ago
<p><pre><code> printf("I am bad and evil %p\n", ({int bad_and_evil(void){return 0;};&#38;bad_and_evil;})); printf("I am bad and evil2 %d\n", ({0x4FFFFFF;})); void* result = ({void* bad_and_evil(int dummy){return 0;};&#38;bad_and_evil;}); printf("bad and evil 3 = %p\n", result); </code></pre> * shudder * Getting a return value from a block, by inserting it in parantheses.
juiceandjuicealmost 14 years ago
This is just too clumsy, and this is exactly why I think go will take off.<p><pre><code> package main import "fmt" func main() { add := func(x int, y int) int{ return x+y } max := func(x int, y int) int{ if x&#62;y {return x} return y } fmt.Printf("lambda: add:%d\n",add(2,3)) fmt.Printf("lambda: max:%d\n",max(2,3)) } </code></pre> Although it'd be nice if you could have a ternary or something like<p><pre><code> return {x} if x&#62;y else {y}</code></pre>
评论 #2720215 未加载
评论 #2720020 未加载