这是用户在 2024-9-4 20:44 为 https://buildyourownlisp.com/chapter1_introduction#why_learn_c 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?

Introduction • Chapter 1
导言- 第 1 章

About 关于


In this book you'll learn the C programming language and at the same time learn how to build your very own programming language, a minimal Lisp, in under 1000 lines of code! We'll be using a library to do some of the initial work, so I'm cheating a bit on the line count, but the rest of the code will be completely original, and you really will create a powerful little Lisp by the end.
在本书中,你将学习 C 编程语言,同时学习如何用不到 1000 行的代码创建你自己的编程语言--一个最小的 Lisp!我们将使用一个库来完成部分初始工作,因此在代码行数上我有点作弊,但其余代码将是完全原创的,到最后你真的会创建一个功能强大的小 Lisp。

This book is inspired by other tutorials which go through the steps of building a programming language from scratch. I wrote this book to show that this kind of fun and creative project is a great way to learn a language, and not limited to abstract high-level languages, or experienced programmers.
本书受到其他教程的启发,这些教程介绍了从零开始构建一门编程语言的步骤。我写这本书是想告诉大家,这种充满乐趣和创意的项目是学习语言的好方法,并不局限于抽象的高级语言或经验丰富的程序员。

Many people are keen to learn C, but have nowhere to start. Now there is no excuse. If you follow this book I can promise that, in the worst case, you'll get a cool new programming language to play with, and hopefully you'll become an experienced C programmer too!
许多人热衷于学习 C 语言,但却无从下手。现在没有任何借口了。如果你按照本书的方法学习,我可以保证,在最坏的情况下,你会得到一门很酷的新编程语言,希望你也能成为一名经验丰富的 C 语言程序员!

Who this is for 适用对象


This book is for anyone wanting to learn C, or who has once wondered how to build their own programming language. This book is not suitable as a first programming language book, but anyone with some minimal programming experience, in any language, should find something new and interesting inside.
本书适合任何想学习 C 语言的人,或者曾经想知道如何构建自己的编程语言的人。本书并不适合作为第一本编程语言书籍,但任何具有最低限度编程经验的人,无论使用哪种语言,都会在书中发现一些新的有趣的东西。

ada

Ada Lovelace • Your typical brogrammer.
艾达-拉芙蕾丝(Ada Lovelace)--典型的兄弟程序员。

I've tried to make this book as friendly as possible to beginners. I welcome beginners the most because they have so much to discover! But beginners may also find this book challenging. We will be covering many new concepts, and essentially learning two new programming languages at once.
我尽量让这本书对初学者友好。我最欢迎初学者,因为他们有很多东西需要探索!但初学者也可能会觉得本书具有挑战性。我们将涉及许多新概念,而且基本上是同时学习两种新的编程语言。

If you look for help you may find people are not patient with you. You may find that, rather than help, they take the time to express how much they know about the subject. Experienced programmers might tell you that you are wrong. The subtext to their tone might be that you should stop now, rather than inflict your bad code on the world.
如果你寻求帮助,你可能会发现别人对你没有耐心。你可能会发现,他们不但不会帮助你,反而会花时间来表达他们对这个问题有多么了解。经验丰富的程序员可能会告诉你,你错了。他们语气的潜台词可能是,你现在就应该停下来,而不是把你的糟糕代码强加给全世界。

After a couple of engagements like this you may decide that you are not a programmer, or don't really like programming, or that you just don't get it. You may have thought that you once enjoyed the idea of building your own programming language, but now you have realised that it is too abstract and you don't care any more. You are now concerned with your other passions, and any insight that may have been playful, joyful or interesting will now have become an obstacle.
经过几次这样的接触之后,你可能会认为自己不是程序员,或者并不喜欢编程,或者根本就不懂 编程。你可能认为自己曾经喜欢过构建自己编程语言的想法,但现在你已经意识到它太抽象,你不再关心。你现在关心的是自己的其他爱好,而任何可能让你玩得开心、快乐或有趣的见解现在都成了你的障碍。

For this I can only apologise. Programmers can be hostile, macho, arrogant, insecure, and aggressive. There is no excuse for this behaviour. Know that I am on your side. No one gets it at first. Everyone struggles and doubts their abilities. Please don't give up or let the joy be sucked out of the creative experience. Be proud of what you create no matter what it is. People like me don't want you to stop programming. We want to hear your voice, and what you have to say.
对此,我只能表示歉意。程序员可能充满敌意、大男子主义、傲慢、不自信和咄咄逼人。这种行为没有任何借口。要知道,我是站在你们这边的。没有人一开始就能成功。每个人都会挣扎,都会怀疑自己的能力。请不要放弃,也不要让快乐从创作体验中消失。无论创作什么,都要为自己的作品感到自豪。像我这样的人不希望你停止编程。我们希望听到你的声音,听到你想说的话。

Why learn C 为什么学习 C 语言


C is one of the most popular and influential programming languages in the world. It is the language of choice for development on Linux, and has been used extensively in the creation of OS X and to some extent Microsoft Windows. It is used on micro-computers too. Your fridge and car probably run on it. In modern software development, the use of C may be escapable, but its legacy is not. Anyone wanting to make a career out of software development would be smart to learn C.
C 语言是世界上最流行、最有影响力的编程语言之一。它是 Linux 开发的首选语言,在 OS X 和一定程度上 Microsoft Windows 的创建过程中被广泛使用。它也用于微型计算机。你的冰箱和汽车可能就是在它的基础上运行的。在现代软件开发中,C 语言的使用可能是可以避免的,但它的遗产却无法避免。任何想以软件开发为职业的人,学习 C 语言都是明智之举。

fridge

A fridge • Your typical C user
冰箱--典型的 C 语言用户

But C is not about software development and careers. C is about freedom. It rose to fame on the back of technologies of collaboration and freedom - Unix, Linux, and The Libre Software Movement. It personifies the idea of personal liberty within computing. It wills you to take control of the technology affecting your life.
但 C 语言与软件开发和职业生涯无关。C 语言是关于自由的。它是在协作和自由技术--Unix、Linux 和自由软件运动--的背景下成名的。它是计算机领域个人自由理念的化身。它让你掌控影响你生活的技术。

In this day and age, when technology is more powerful than ever, this could not be more important.
在技术比以往任何时候都更加强大的今天,这一点再重要不过了。

The ideology of freedom is reflected in the nature of C itself. There is little C hides from you, including its warts and flaws. There is little C stops you from doing, including breaking your programs in horrible ways. When programming in C you do not stand on a path, but a plane of decision, and C dares you to decide what to do.
自由的意识形态体现在 C 本身的性质中。C 语言几乎不对你隐瞒什么,包括它的缺点和瑕疵。C 语言几乎不会阻止你做任何事,包括以可怕的方式破坏你的程序。用 C 语言编程时,你不是站在一条道路上,而是站在一个决定的平面上,C 语言让你敢于决定做什么。

C is also the language of fun and learning. Before the mainstream media got hold of it we had a word for this. Hacking. The philosophy that glorifies what is fun and clever. Nothing to do with the illegal unauthorised access of other peoples' computers. Hacking is the philosophy of exploration, personal expression, pushing boundaries, and breaking the rules. It stands against hierarchy and bureaucracy. It celebrates the individual. Hacking baits you with fun, learning, and glory. Hacking is the promise that with a computer and access to the internet, you have the agency to change the world.
C 语言也是一种有趣的学习语言。在主流媒体掌握它之前,我们有一个词来形容它。黑客。这是一种美化有趣和聪明的哲学。这与未经授权非法访问他人电脑无关。黑客哲学是探索、个人表达、突破界限和打破常规的哲学。它反对等级制度和官僚主义。它崇尚个人。黑客以乐趣、学习和荣誉为诱饵。黑客技术承诺,有了电脑和互联网,你就有能力改变世界。

To want to master C is to care about what is powerful, clever, and free. To become a programmer with all the vast powers of technology at his or her fingertips and the responsibility to do something to benefit the world.

How to learn C


There is no way around the fact that C is a difficult language. It has many concepts that are unfamiliar, and it makes no attempts to help a new user. In this book I am not going to cover in detail things like the syntax of the language, or how to write loops and conditional statements.

I will, on the other hand, show you how to build a real world program in C. This approach is always more difficult for the reader, but hopefully will teach you many implicit things a traditional approach cannot. I can't guarantee that this book will make you a confident user of C. What I can promise, is that those 1000 lines of code are going to be packed with content - and you will learn something worthwhile.

This book consists of 16 short chapters. How you complete these is up to you. It may well be possible to blast through this book over a weekend, or to take it more slowly and do a chapter or two each evening over a week. It shouldn't take very long to complete, and will hopefully leave you with a taste for developing your language further.

Why build a Lisp 为什么要构建 Lisp


The language we are going to be building in this book is a Lisp. This is a family of programming languages characterised by the fact that all their computation is represented by lists. This may sound scarier than it is. Lisps are actually very easy, distinctive, and powerful languages.
我们将在本书中使用的语言是 Lisp。这是一个编程语言家族,其特点是所有计算都由列表来表示。这听起来可能比实际情况更可怕。实际上,Lisp 是一种非常简单、独特和强大的语言。

mike

Mike Tyson • Your typical Lisp user
Mike Tyson - 典型的 Lisp 用户

Building a Lisp is a great project for so many reasons. It puts you in the shoes of language designers, and gives you an appreciation for the whole process of programming, from language all the way down to machine. It teaches you about functional programming, and novel ways to view computation. The final product you are rewarded with provides a template for future thoughts and developments, giving you a starting ground for trying new things. It simply isn't possible to comprehend the creativity and cleverness that goes into programming and computer science until you explore languages themselves.
构建 Lisp 是一个伟大的项目,原因有很多。它能让你站在语言设计者的角度,了解从语言到机器的整个编程过程。它让你了解函数式编程,以及看待计算的新方法。你最终获得的产品为未来的思考和发展提供了模板,为你尝试新事物提供了起点。在探索语言本身之前,你根本无法理解编程和计算机科学所蕴含的创造力和聪明才智。

The type of Lisp we'll be building is one I've invented for the purposes of this book. I've designed it for minimalism, simplicity and clarity, and I've become quite fond of it along the way. I hope you come to like it too. Conceptually, syntactically, and in implementation, this Lisp has a number of differences to other major brands of Lisp. So much so that I'm sure I will be getting e-mails from Lisp programmers telling me it isn't a Lisp because it doesn't do/have/look-like this or that.
我们要构建的 Lisp 是我为了本书的目的而发明的。我设计它的初衷是极简、简洁和清晰,而且在使用的过程中我已经对它产生了浓厚的兴趣。我希望你也会喜欢它。在概念上、语法上和实现上,这种 Lisp 与其他主要品牌的 Lisp 有许多不同之处。以至于我肯定会收到 Lisp 程序员的电子邮件,告诉我它不是 Lisp,因为它没有/有/看起来像这样或那样

I've not made this Lisp different to confuse beginners. I've made it different because different is good.
我让 Lisp 与众不同,并不是为了迷惑初学者。我让它与众不同是因为与众不同是件好事。

If you are looking to learn about the semantics and behaviours of conventional Lisps, and how to program them, this book may not be for you. What this book offers instead is new and unique concepts, self expression, creativity, and fun. Whatever your motivation, heed this disclaimer now. Not everything I say will be objectively correct or true! You will have to decide that for yourselves.
如果你想了解传统 Lisps 的语义和行为,以及如何对它们进行编程,那么这本书可能不适合你。本书提供的是新颖独特的概念、自我表达、创造力和乐趣。无论你的动机是什么,请注意以下免责声明。我所说的并不都是客观正确或真实的!这需要你们自己去判断。

Your own Lisp 您自己的 Lisp


The best way to follow this book is to, as the title says, write your own Lisp. If you are feeling confident enough I want you to add your own features, modifications and changes. Your Lisp should suit you and your own philosophy. Throughout the book I'll be giving description and insight, but with it I'll be providing a lot of code. This will make it easy to follow along by copy and pasting each section into your program without really understanding. Please do not do this!.
学习本书的最好方法就是像书名所说的那样,编写自己的Lisp。如果你有足够的自信,我希望你能添加自己的功能、修改和变化。你的 Lisp 应该适合你和你自己的理念。在整本书中,我将给出描述和见解,但同时也会提供大量代码。这将使你很容易在没有真正理解的情况下将每一部分复制粘贴到你的程序中。请不要这样做

Type out each piece of sample code yourself. This is called The Hard Way. Not because it is hard technically, but because it requires discipline. By doing things The Hard Way you will come to understand the reasoning behind what you are typing. Ideally things will click as you follow it along character by character. When reading you may have an intuition as to why it looks right, or what may be going on, but this will not always translate to a real understanding unless you do the writing yourself!

In a perfect world you would use my code as a reference - an instruction booklet and guide to building the programming language you always dreamed of. In reality this isn't practical or viable. But the base philosophy remains. If you want to change something, do it.

Navigation

• Contents •

Installation ›