伏特加酒是为创意作家(LISP)提供的创意编码环境

2020-11-21 18:27:41

Permalink GitHub是超过5000万开发人员的家园,他们共同致力于托管和审查代码,管理项目以及共同构建软件。

注册

数以百万计的开发人员和公司在GitHub(全球最大,最先进的开发平台)上构建,发行和维护其软件。

So, you've installed Vodka, and you've loaded it up in a browser, and you're staring at a completely empty browser window.

If you're a writer like me, seeing a blank sheet of paper can evoke all sorts of emotions: sometimes fear and insecurity, but also the excitement of unrealized potential. So let's start filling up this digital paper with words, shall we?

抓住键盘,然后开始输入。您应该能够键入文本行,如果输入有误,则按Enter键进入下一行,按Backspace键...基本上执行了通常在文字处理器中执行的许多基本操作。

Once you've filled up the screen with some language, do me a favor and escape key. I want to show you something cool.

Have you ever wanted to open up the hood of your word processor and tinker with what it's doing? Exploded mode in Vodka is how you do that. Exploded mode shows the guts of your Vodka doc -- the data structures and information that is underlying what you're seeing.

You can see that the letters you typed are surrounded by boxes. Wordsare enclosed in yellow boxes, lines are enclosed in blue boxes, and the entire document that you typed is in a green box. These boxes are called nexes. Actually, the letters you typed are nexes too,along with everything else you will see and work with in Vodka, andthe boxes are more properly termed nex containers. But I won't bog you down with too much terminology quite yet.

如果现在用鼠标单击,您将看到不仅可以选择字母,还可以选择其他框。您仍然可以使用箭头键转到上一个或下一个字母,就像在分解文档之前一样,但是您可能还想知道可以使用Tab和Shift-Tab键向下或向上导航(分别)在此嵌套的盒子层次结构中。在继续之前,请尝试一下。

Now that you can see all the data in your document laid out in visibly, and you can navigate through it,you are in a position where you can actually write some code. Let's do that. Click on the word vodka (so that the yellow box around it is selected) and hit the shift key twice (press it andrelease it without typing any other keys). You should see a red dotted outline appear around the word. Now type the ~ key.

This has spawned a new type of nex container, and it's surrounding the word you were interested in. This nex container is called a command. It is a way of running some code on the data (the words) in your Vodka doc.

There are many commands, and commands can be put inside other commands, or run in sequences and loops. This is how you write code in Vodka! In this case, since it's your first program, we are just going to run one command. Type the word "first" and hit enter.

You've written a little code. This command, first, extracts the firstelement of whatever nex container you pass into it. But how do you run this code? Well, with Vodka, we don't have to switch windows or go run our code in some other environment. We can run our code right here, in the same place where we've written it. Make sure your command is still selected (it will be red if it's selected) and hit the enter key.

And look at that! You've run this command, and it did what you asked it to do -- it extracted the first letter of the word vodka, and replaced the contents of the doc at that location with the result. Congratulations, you have taken your first few baby steps toward writingdigital literature in Vodka.

伏特加酒具有许多不同类型的列表(或nex容器)和原子(或值nexes)。下面列出了这些内容,以及用于创建这些nexe之一的热键。

a space, punctuation mark, or other typographic character that either separates words or isn't considered part of the word it's next to

调用一个函数(在其他地方定义),您可以在其中传递参数,这将返回一些结果值

函数的定义,对参数执行一些操作并返回结果

与书面文档无关的通用容器,仅在代码中使用

Typing the hotkeys listed above should create the appropriate nexes in most cases where you would expect them to. However, it's importantto be aware that in Vodka, keyboard input is "contextual."Depending on what the currently selected nex is, typing hotkeysmight do different things. So, if you're inside a doc, typingan exclamation point might give you a separator, because youare probably typing a sentence and want to end it in anexciting way! On the other hand, if you're inside a command,then typing an exclamation point will create a boolean nex. [^1] If you're ever in a situation with Vodka where Vodka isn't creating the nex type that you want it to, you should be able to copy and paste a nex of any type from any location into any other location. If that doesn't work, please file a bug describing the problem you're having.

Most code-type nexes have some sort of value. Integers have a numeric value, strings have characters, and commands have a command name that is meant to be executed. When you first create a nex, it starts out in "editing" mode, which means that letters you type will change the value of that selected nex.

You can tell that a nex is being edited because it will be selected (red) but the selected color will be a muted red (pink) instead of a dark red. You can press enter when you're done editing, but Vodka will also attempt to guess when you're done editing, so if you type some character that is not allowed in the current editing context, Vodka will assume you're done editing and exit the editor.

Vodka is based on a family of programming languages called Lisp. If you're not familiar with Lisp, don't worry about it... I'll try to tell you all you need to know here.

Lisps允许您使用少量语法元素来构建程序。本质上有两种类型的元素:原子和列表。列表用括号表示,可以包含其他列表或原子,而原子是语言可以表达的其他任何形式:

When you run a lisp program, lists are "evaluated", which means that the interpreter looks at the first item in the list, and looks up a command that corresponds to that name, and executes it. For this reason, mathematical operations in Lisp programs look a little strange -- the operator comes before the operands:

在大多数编程语言中,这只能写为2 +(5 * 6)。经典的Lisp编程范例涉及使用小的函数,这些函数以递归方式调用自己。例如,该程序获取小于零的列表的第一个元素:

(defun find-negative (list) (let item (first list)) (if (< item 0) item (find-negative (rest list))))

This program defines a function called find-negative. You pass it a list. The first thing this function does is grab the first item from the list and store it in a variable called "item". Then it tests the item to see if it's less than zero. If it is, it returns it. Otherwise, it calls the find-negative function on the "rest" of the list, i.e. the remaining items in the list (minus the first one).

此功能有一个错误。您认为可以找到它吗?如果列表为空会怎样?

伏特加酒是Lisp,但使用括号而不是括号。您之前输入的单词周围的黄色框?这些相当于Lisp中的括号。