我学习了 Snobol,然后编写了一个玩具 Forth。
I learned Snobol and then wrote a toy Forth

原始链接: https://ratfactor.com/snobol/

Snobol4 是一种引人入胜的语言,其核心在于模式匹配,类似于 Awk,但功能强大得多。与依赖 C 风格脚本进行匹配后操作的 Awk 不同,Snobol 使用模式匹配语句来实现所有逻辑和控制流,展现出非凡的纯粹性。每一行都由可选的标签、主题、模式、替换和 goto 部分组成,这使其成为一种独特的语言。 虽然对现代开发者来说可能显得陌生,但其核心概念使其易于使用和上手。Snobol 对新手程序员尤其友好,因为它使用易于追踪的 GOTO 来控制流程。 然而,其非结构化编程风格(典型的 20 世纪 60 年代风格)可能使得构建和维护大型软件项目变得困难。

这个Hacker News帖子讨论了一个项目,有人用Snobol编写了一个玩具Forth解释器。评论者分享了他们使用Snobol的经验,称赞其模式匹配能力及其对Icon、awk和Perl等后继语言的影响。一些人指出了Snobol模式匹配的低效性。 该帖子还深入探讨了Forth的持续使用,提到了它在引导加载程序(FreeBSD,RedoxOS)、开放式固件,甚至比特币脚本语言中的存在。对于那些有兴趣学习Forth的人,推荐了“Threaded Interpretive Languages”和“Moving Forth”等资源。帖子中还提到了几个非玩具级的Forth实现,包括gforth和Factor。最后,有人建议学习Joy语言。
相关文章
  • (评论) 2024-09-15
  • 我为什么用 Lisp 编程 2025-04-11
  • (评论) 2025-03-28
  • (评论) 2025-04-14
  • (评论) 2024-01-17

  • 原文

    Here’s my conclusions about the Snobol4 language itself, which get their own pages:

    In short, I think Snobol is fascinating. The singular focus on pattern matching kind of reminds me of Awk. Except Awk doesn’t do nearly as much with patterns, it devolves into a C-like script to do things with pattern matches. Snobol uses no such crutches, just pattern matching statements for all logic and control flow. Its purity is impressive.

    No kidding: Every single line in a Snobol program consists of five parts: label, subject, pattern, replacement, goto. All of those parts are optional.

    That certainly makes it a Weird Language to the modern developer, but once you get the hang of it, it’s easy to see why Snobol was once popular and well-regarded by computer users of all stripes.

    It’s extremely easy for seasoned developers to forget that even a simple loop construct is a conceptual leap for beginners. I remember being that beginner. By contrast, I think conditional GOTO-style control flow is easy for beginners to follow because you can "see" it. You can trace the logic with your finger.

    Of course, simplicity of language is good for programming in the small, but maybe not so good for programming in the large. Snobol4 is basically 1960s-style "unstructured programming", which is generally understood to rapidly break down in large programs.

    Still, Snobol proves that programming using "this one weird trick" can be surprisingly effective.

    联系我们 contact @ memedata.com