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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Fexl - a Function Expression Language

28 点作者 sheffield将近 14 年前

6 条评论

fexl将近 14 年前
Ah, thanks for posting about my Fexl language. Although I'm the author of it, and somewhat fond of it, I must emphasize this caveat: <a href="http://news.ycombinator.com/item?id=2717560" rel="nofollow">http://news.ycombinator.com/item?id=2717560</a> .<p>Although lazy evaluation is quite amazing, in certain circumstances I find that it's kicking my ass. For example, consider a function that simply sums the numbers from 1 to N:<p><pre><code> \sum == (\N long_le N 0 0 (long_add N (sum (long_sub N 1))) ) </code></pre> Or, more tersely, using the semicolon as a syntactic "pivot" to avoid right-nesting:<p><pre><code> \sum == (\N long_le N 0 0; long_add N; sum; long_sub N 1) </code></pre> The problem is that when you call (sum 100000) it builds up a giant chain of (long_add 100000; long_add 99999; long_add 99998; ...) and then evaluates that monstrosity recursively.<p>So I need to do some more work on forcing early evaluation. You can start by using the standard accumulator trick:<p><pre><code> \sum == (\total\N long_le N 0 total (sum (long_add total N) (long_sub N 1)) ) \sum = (sum 0) </code></pre> But even then you still have the massive recursion problem because you're not forcing the addition operation early.<p>I'm thinking I just need to allow basic types like "long" to be called as functions with no effect (i.e. equivalent to the identity function, so you can do things like this:<p><pre><code> \sum == (\total\N long_le N 0 total ( \total = (long_add total N) total; # force evaluation; result is I (identity function) sum total (long_sub N 1) ) ) </code></pre> However, <i>even that</i> doesn't always do the trick, particularly when you're dealing with higher-level values that aren't basic data types. The problem occurs generally when you build up a big "chain" of calculations with arbitrary values, and you have no simple way of forcing evaluation along the way.<p>This is, of course, the classic struggle between eager and lazy evaluation. But if I don't do the evaluation lazily, I can't define recursion in terms of the closed-form Y combinator, namely (Y F) = (F (Y F)). Instead I'd have to define it in terms of some kind of run-time "environment" using either key-value pairs or the de Bruijn positional technique -- something I've managed to avoid thanks to lazy evaluation in terms of pure combinators.<p>So I must say that although Fexl is an interesting pure-combinator lazy evaluation language, the jury is still out on its practical utility, in my humble opinion. I've used it in some projects as an embedded interpreter, but the application was quite constricted so you didn't encounter some of these larger issues.<p>That is why I emphasized this caveat earlier today: <a href="http://news.ycombinator.com/item?id=2717560" rel="nofollow">http://news.ycombinator.com/item?id=2717560</a> .
评论 #2717835 未加载
评论 #2717917 未加载
评论 #2717885 未加载
mahmud将近 14 年前
What is an "expression language"? I just started doing Java EE crap and there is an assortment of "ELs" that you can embed in your java apps.<p>Outside of Java, an "expression language" doesn't make any sense to me. An expression, statement, binding, assignment, application, and abstraction are all constructs, or elements of programming languages. Most of them can be implemented using others, sure, but I expect all useful languages to be capable of <i>all</i>. So, my question is, what makes an expression language an <i>expression</i> language, to the exclusion of all other constructs? (IOW, why is that particular part being made into a defining characteristic of the language?)
评论 #2718087 未加载
pwang将近 14 年前
Can you contrast this with Joy?<p><a href="http://en.wikipedia.org/wiki/Joy_(programming_language)" rel="nofollow">http://en.wikipedia.org/wiki/Joy_(programming_language)</a>
评论 #2720175 未加载
Gotttzsche将近 14 年前
i dont understand the identity function that uses just C and S. :(<p>C x y = x<p>S x y z = (x z) (y z)<p>\I = (S C C)<p>so uh... that would evaluate to (\z (C z) (C z)), right? and then to (\z z z)? but then you got z twice. what does that even mean? applying z to z?
评论 #2718716 未加载
评论 #2718698 未加载
评论 #2719635 未加载
fexl将近 14 年前
What a difference a day makes. The day after this discussion about my problems with lazy evaluation, I figured out an incredibly simple solution: <a href="http://fexl.com/eager_and_lazy" rel="nofollow">http://fexl.com/eager_and_lazy</a>
gmartres将近 14 年前
So, how is this different/better than other functional languages?
评论 #2718407 未加载