TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Lambdas in C

111 点作者 wingo将近 14 年前

12 条评论

eps将近 14 年前
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 未加载
jensnockert将近 14 年前
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 未加载
brohee将近 14 年前
Am I really out of my mind or is this not a lambda at all but just an anonymous function?
评论 #2718638 未加载
Kototama将近 14 年前
<i>Note: unlike lambdas in functional languages, this lambda does not capture the containing environment.</i>
评论 #2718415 未加载
评论 #2718343 未加载
athom将近 14 年前
My favorite part: <i>l_anonymous_functions_name</i><p>Sorry, I just like the irony.
snorkel将近 14 年前
Cute, but functions pointers suit me just fine.
评论 #2720353 未加载
评论 #2721031 未加载
wbhart将近 14 年前
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).
chrisjsmith将近 14 年前
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)
jpr将近 14 年前
More accurate title would be "Something like, but not as useful or generic as, lambdas in gcc's dialect of C".
评论 #2720018 未加载
CPlatypus将近 14 年前
If I worked on static code analysis tools for a living, this would make me cry.
demallien将近 14 年前
<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.
juiceandjuice将近 14 年前
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 未加载