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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Functional programming in C

23 点作者 rudenoise超过 15 年前

7 条评论

demallien超过 15 年前
Of course, I can't help thinking of Greenspun's Tenth Rule when I see this sort of thing.<p>That said, my day job is C programming, and I am of course a heavy user of function pointers (how else can you get anything interesting done in C?). But C's type system does tend to get in the way, so you end up casting all pointers to void*, and things like that, just to shut the compiler up. Some Lisp-style macros would certainly help with this!
ajross超过 15 年前
This seems to be kinda missing the point. Yes, you can do functional programming in almost anything that supports recursion and function indirection. But the essence of functional programming is <i>not</i> simply using a function pointer for everything. Those "if and switch statements" are perfectly functional concepts. It's the avoidance of side effects that generally distinguishes "functional" idioms from imperative ones.
akkartik超过 15 年前
Functional? If anything this is a poor man's OO, simulating a vtable. Even if it is using higher-order functions, that seems like a more accurate analogy.
wlievens超过 15 年前
It's not functional programming if you don't have nested functions and/or closures, is it?
评论 #1035639 未加载
评论 #1034612 未加载
评论 #1034820 未加载
DrJokepu超过 15 年前
Invoking functional pointers (call eax) is very very slow. If you're using C chances are you're using it because you need the extra performance.
评论 #1034673 未加载
pan69超过 15 年前
<a href="http://www.newty.de/fpt/index.html" rel="nofollow">http://www.newty.de/fpt/index.html</a>
wendroid超过 15 年前
Lots of the plan9 code is written in a style like this but with enums<p>A bit tricky to find the best example on my phone while on the bus but here's a flavour, the in-memory file system<p><a href="http://plan9.bell-labs.com/sources/plan9/sys/src/cmd/ramfs.c" rel="nofollow">http://plan9.bell-labs.com/sources/plan9/sys/src/cmd/ramfs.c</a><p>Edit : can anyone see how to add a comment to the article, I wanted to share the above info with him but comments don't seem open to me now I'm at my desk.<p>The plan9 way uses an interface style, the sort that is made explicit in Go :<p>from <a href="http://plan9.bell-labs.com/sources/plan9/sys/src/cmd/nntpfs.c" rel="nofollow">http://plan9.bell-labs.com/sources/plan9/sys/src/cmd/nntpfs....</a><p><pre><code> Srv nntpsrv = { .destroyfid= fsdestroyfid, .attach= fsattach, .clone= fsclone, .walk1= fswalk1, .open= fsopen, .read= fsread, .write= fswrite, .stat= fsstat, }; </code></pre> These file systems all run in user mode btw (as can all the disk based ones). Mycrotiv has even done a kernel with a built in rc shell that you attach your file systems after booting as yourself - a disk failure will not take down your system!
评论 #1034689 未加载