摆弄无点代码?

发布于 2024-09-16 12:37:18 字数 237 浏览 9 评论 0原文

我一直在学习 Factor 和 J 语言来尝试无点编程。这些语言的基本机制似乎很清楚,但了解如何进行算法设计是一个挑战。

对我来说,一个特别令人困惑的地方是应该如何构建代码,以便可以轻松地尝试不同的参数。我的意思是 Mathematica 和 Matlab 非常擅长的事情;您设置一个算法,然后操纵变量并观察会发生什么。

在没有显式变量的情况下如何做到这一点?也许我对这一切的思考都是错误的。在无点编程中我应该如何解决这个问题?

I have been learning the Factor and J languages to experiment with point-free programming. The basic mechanics of the languages seem clear, but getting a feeling for how to approach algorithm design is a challenge.

A particular source of confusion for me is how one should structure code so that it is easy to experiment with different parameters. By this, I mean the sort of thing Mathematica and Matlab are so good at; you set up an algorithm then manipulate the variables and watch what happens.

How do you do this without explicit variables? Maybe I'm thinking about this all wrong. How should I approach this in point-free programming?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏天碎花小短裙 2024-09-23 12:37:18

以下是我发现在处理连接范例时非常有用的三个重要建议(在我的案例中适用于 Factor 编程语言):

  • 无情地分解你的代码。编写非常小的函数:如果堆栈参数超过 3-4 个,也许您可​​以将其分成更小的部分。
  • 投入时间学习数据流组合器(bi、tri、cleave、spread...)。它们允许表达常见的数据流模式,同时消除复杂的堆栈改组的需要。
  • 学习从其他报价中构建报价。使用柯里化技术(curry、with、...)从堆栈参数构建简单的引用,当事情变得过于复杂时,使用 Fried 引用(“fry”词汇)。它们允许轻松地从模式构建复杂的嵌套引用,而无需任何堆栈改组。

一如既往,阅读并“走进”现有代码。在 Factor 中,探索运行时并查看事情是如何工作的非常容易。

对于您的具体混乱来源,如果您的算法中有很多输入参数,那么最重要的事情就是研究它们将如何使用。收获数据流模式。您必须真正考虑在最小的相关参数集上“安排”操作的最佳方法。

这是一次相当困难的经历,但成功时也是非常有益的。之后我们感觉自己就像一个人类编译器......

祝你好运!

Here are three important advices that I found really helpful while dealing with the concatenative paradigm (applied to the Factor programming language in my case):

  • Factor your code mercilessly. Write extremely small functions: if there is more than 3-4 stack parameters, maybe you could break it into smaller parts.
  • Invest your time in learning dataflow combinators (bi, tri, cleave, spread,...). They allow to express common dataflow patterns while removing the need of complex stack shuffling.
  • Learn to build quotations from other quotations. Use currying techniques (curry, with, ...) to build simple quotations from stack parameters, and when things get too complex use Fried quotations (the "fry" vocab). They allow to easily build complex nested quotations from patterns, without any stack shuffling.

And as a always, read and "Walk" into existing code. In Factor it is quite easy to explore the runtime and see how things are working.

For your specific source of confusion, if you have a lot of input parameters in your algorithm, the most important thing to do is to study how they will be used. Harvest for dataflow patterns. You must really THINK about the best way to "schedule" operations on the smallest set of related parameters.

It is a quite difficult experience, but it is also really rewarding one when it succeed. We feel like a human compiler after that..

Good luck!

花海 2024-09-23 12:37:18

我对串联编程语言 Joy 和 Backus 类似 FP< /a> 语言。关于算法设计,我可以说是一个非常结构化的算法设计。

如何在没有显式变量的情况下做到这一点?

事实上,像 Backus FP 这样的语言中没有全局变量。但是,没有什么可以阻止使用某些受限制的局部变量,例如实例变量。

I have had a little experience in the concatenative programming language Joy and in a Backus FP-like language. Regarding the algorithm design, I can say that it is a very structured algorithm design.

How do you do this without explicit variables?

In fact, there are no global variables in languages like Backus FP. However, there is nothing to prevent the use of somewhat restricted local variables such as the instance variables.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文