Logo 编程语言
Logo Programming Language

原始链接: https://el.media.mit.edu/logo-foundation/what_is_logo/logo_programming.html

Logo 程序是由一系列小型模块化过程组成的。通过使用 `to` 命令后跟一个名称,并以 `end` 结束,用户可以定义与内置原语功能完全相同的新指令。这些过程充当了构建块;简单的任务(如绘制正方形)可以嵌套在更复杂的序列中(如创作一朵花或整个花园)。 Logo 的一个主要优势是其可扩展性。编程涉及扩展语言的词汇量,即基于它已理解的词汇来教授它新词。一旦定义完成,用户创建的过程与语言的原始命令便没有区别,从而实现了自定义逻辑的无缝集成。这种分层方法使用户能够通过易于管理的渐进步骤构建复杂的项目,这反映了人类学习和构建语言的自然方式。

最近一个 Hacker News 帖子探讨了 Logo 编程语言的长久影响力,许多用户将其视为他们计算机科学的启蒙。参与者们回忆了使用 Commodore 64、Apple IIe 和 ZX Spectrum 等平台来操控标志性“海龟”的经历。 对许多人来说,Logo 不仅仅是一个绘图工具,它还提供了对递归、函数和模块化代码的基础理解。用户们描述了该语言高度交互的特性(常被比作 Lisp)是如何自然地教会他们将复杂问题拆解为更小的、可复用的组件。无论是绘制六边形、制作烟花动画,还是创建简单的花卉图案,该语言的“to”命令和逻辑结构都为他们日后的软件工程职业生涯奠定了基础。 这场讨论反映了对 80 年代计算时代的共同怀念,强调了 Logo 的简洁性和即时的视觉反馈如何让编程变得易于上手且引人入胜,从而对一代开发者产生了深远的影响。
相关文章

原文

Logo programs are usually collections of small procedures. Generally, procedures are defined by writing them in a text editor. The special word to is followed by the name of the procedure. Subsequent lines form the procedure definition. The word end signals that you're finished.

In our turtle graphics example we defined a procedure to draw a square

to square
repeat 4 [forward 50 right 90]
end

and used it as a subprocedure of another procedure

to flower
repeat 36 [right 10 square]
end

Similarly, flower could be a building block of something larger

to garden
repeat 25 [set-random-position flower]
end

No, set-random-position is not a primitive, but random is and so is setposition (or setpos or setxy). Or you could write set-random-position using forward and right with random.

Once a Logo procedure is defined it works like the Logo primitives. In fact, when you look at Logo programs there's no way of knowing which words are primitives and which are user-defined unless you know that particular Logo implementation. In our language sample we used the procedure pick to randomly select an item from a list, for example in the procedure who.

to who
output pick [Sandy Dale Dana Chris]
end

In some versions of Logo pick is a primitive while in others you have to write it yourself. Who would look and work the same way in either case.

Logo allows you to build up complex projects in small steps. Programming in Logo is done by adding to its vocabulary, teaching it new words in terms of words it already knows. In this way it's similar to the way people learn spoken language.

联系我们 contact @ memedata.com