mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-02-03 23:40:14 +08:00
translated
This commit is contained in:
parent
745de1be29
commit
3bae3161d7
@ -1,192 +0,0 @@
|
||||
[#]: subject: "Write a cute program with Emojicode"
|
||||
[#]: via: "https://opensource.com/article/23/4/emojicode"
|
||||
[#]: author: "Jessica Cherry https://opensource.com/users/cherrybomb"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: "geekpi"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
Write a cute program with Emojicode
|
||||
======
|
||||
|
||||
In this article, I'll cover the greatest coding language to learn how to make anything! It's called Emojicode. Created in 2014 by Theo Belaire, Emojicode is an open source programming language that uses emoji characters to represent its syntax. When working in Emojicode, emoji are used to create variables, functions, and control structures. Because it's a statically typed language, variable types must be declared before use, but it also supports object-oriented concepts like classes and inheritance. This language can be run on every OS, and it's a super fun way to code, especially if you're a non-native English speaker. This is helpful because pictographic representations can bring us all together and allow us to speak the same language in a way similar to math.
|
||||
|
||||
### Prerequisites
|
||||
|
||||
In this tutorial, I'm using a Debian-based OS. My tools may be different than what your OS may require. Here's what I'm using:
|
||||
|
||||
- [Geany][1], an open source IDE for Linux.
|
||||
- IBus, which allows you to pick emoji and place them in your editor. The interface I'm using is called **emoji picker**.
|
||||
- Debian-based Linux.
|
||||
- A C++ compiler. I'm using the `g++` compiler.
|
||||
- [Emojicode][2]
|
||||
|
||||
I'm using a Linux OS, but you can [read the docs][3] to learn about any special steps you might need to take to use it on another OS.
|
||||
|
||||
### Intall Emojicode on Linux
|
||||
|
||||
There are a couple ways to install Emojicode on your computer, but they have a cool [magic install page][4] that can tell you exactly what to do. Here's what I did:
|
||||
|
||||
```
|
||||
$ wget https://github.com/emojicode/emojicode/releases/download/v1.0-beta.2/Emojicode-1.0-beta.2-Linux-x86_64.tar.gz -O emojicode.tar.gz \
|
||||
&& tar -xzf emojicode.tar.gz && rm emojicode.tar.gz \
|
||||
&& cd Emojicode-1.0-beta.2-Linux-x86_64 && ./install.sh \
|
||||
&& cd .. && rm -r Emojicode-1.0-beta.2-Linux-x86_64
|
||||
```
|
||||
|
||||
This is the output of that command.
|
||||
|
||||
![The emojicode installation procedure provides useful feedback along the way.][5]
|
||||
|
||||
Now that you have everything installed, it's time to move on to some code!
|
||||
|
||||
### How does this whole thing work?
|
||||
|
||||
To start, all Emojicode file extensions end in filename.🍇 but because you can't do that in your average file name, it translates to `filename.emojic`. Here are the most important syntax elements:
|
||||
|
||||
- Put 🏁 at the beginning of a line to indicate what blocks of code are meant to be executed
|
||||
- Start a block of code with 🍇
|
||||
- End a block of code using 🍉
|
||||
- Want to print something? Just use 😀 🔤 `<string>` 🔤 ❗
|
||||
|
||||
There's way more to it, so here are some practical examples.
|
||||
|
||||
### Print a haiku
|
||||
|
||||
First up, try printing a nice haiku for fun! I'll add a single comment in this example. See if you can identify it.
|
||||
|
||||
```
|
||||
🏁🍇
|
||||
💭 This is a single line comment for fun
|
||||
😀 🔤Emojicode is great,🔤 ❗
|
||||
😀 🔤Fun and expressive code,🔤 ❗
|
||||
😀 🔤no sadness, just joy.🔤 ❗
|
||||
🍉
|
||||
```
|
||||
|
||||
Now we need to save our code and run it through our compiler to make a nice executable file:
|
||||
|
||||
```
|
||||
$ emojicodec haiku.emojic
|
||||
$ ls
|
||||
haiku haiku.emojic haiku.o
|
||||
```
|
||||
|
||||
As you can see, the code has been compiled and generated two files, one of which is executable. Run the `haiku` file:
|
||||
|
||||
```
|
||||
$ ./haiku
|
||||
Emojicode is great,
|
||||
Fun and expressive code,
|
||||
no sadness, just joy.
|
||||
```
|
||||
|
||||
### Math and variable manipulation
|
||||
|
||||
Next up, you're going to do a couple of things at once: a little bit of math and the changing of the variable. Start by assigning a variable to 0:
|
||||
|
||||
```
|
||||
0 ➡️ 🖍🆕x
|
||||
```
|
||||
|
||||
You just created a new variable by using the crayon emoji, and the new emoji next to the variable name, while also assigning that variable to 0.
|
||||
|
||||
Next, print a line that includes the variable using the magnets emoji:
|
||||
|
||||
```
|
||||
😀 🔤The value is 🧲x🧲 🔤 ❗
|
||||
```
|
||||
|
||||
Next, change the variable using the plus sign and arrow emojis:
|
||||
|
||||
```
|
||||
x ⬅️➕ 1
|
||||
```
|
||||
|
||||
Then print another line with the value. I continue this for a while and print the final value. Here's what I did:
|
||||
|
||||
```
|
||||
🏁 🍇
|
||||
|
||||
💭Updating a variable using math
|
||||
0 ➡️ 🖍🆕x
|
||||
😀 🔤The value is 🧲x🧲 🔤 ❗
|
||||
|
||||
x ⬅️➕ 1
|
||||
😀 🔤The value is 🧲x🧲 🔤 ❗
|
||||
|
||||
x ⬅️➕ 15
|
||||
😀 🔤The value is 🧲x🧲 🔤 ❗
|
||||
|
||||
x ⬅️➖ 9
|
||||
😀 🔤The value is 🧲x🧲 🔤 ❗
|
||||
|
||||
x ⬅️➗ 2
|
||||
😀 🔤The final value is 🧲x🧲 🔤 ❗
|
||||
🍉
|
||||
```
|
||||
|
||||
Next, compile the code using `emojicodec`, and then use your executable code to see the outcome:
|
||||
|
||||
```
|
||||
$ emojicodec math.emojic
|
||||
$ ./math
|
||||
The value is 0
|
||||
The value is 1
|
||||
The value is 16
|
||||
The value is 7
|
||||
The final value is 3
|
||||
```
|
||||
|
||||
As you can see, everything printed out as the variable was updated with the new math. You can take this even further with the many mathematic emojis available. Here are just a few more operators:
|
||||
|
||||
```
|
||||
🚮 is your modulo
|
||||
◀ Less than
|
||||
▶ Greater than
|
||||
◀🙌 less than or equal to
|
||||
▶🙌 greater than or equal to
|
||||
```
|
||||
|
||||
### Emojicode quirks
|
||||
|
||||
While I was bouncing around the docs, I found some interesting quirks. One of those is that while grabbing input from a user, the skin tone of the ear matters due to some known compiler issue.
|
||||
|
||||
The action for getting user input is this:
|
||||
|
||||
```
|
||||
🆕🔡▶️👂🏼❗️
|
||||
```
|
||||
|
||||
The action for getting and assigning user input is this:
|
||||
|
||||
```
|
||||
🆕🔡▶️👂🏼❗️ ➡️ inputText
|
||||
```
|
||||
|
||||
I was attempting to get that to work but was having some issues with my compiler when I found that. You may also run into some small things here and there. If you do, be sure to create an [issue][6], so it has a chance of being fixed.
|
||||
|
||||
### No tricks, just great code
|
||||
|
||||
While I could go through so much more, I can assure you the docs behind this amazing code are very extensive. Even though I was inspired to write this article just for fun in time April Fool's Day, I have to admit this is one of the best languages ever made because it teaches you a lot about very real programming concepts. I earnestly suggest this as a fun way to teach some of your friends, kids, or maybe a classmate, who is interested in coding. Hopefully, you have a fun-filled April Fool's Day!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/23/4/emojicode
|
||||
|
||||
作者:[Jessica Cherry][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/cherrybomb
|
||||
[b]: https://github.com/lkxed/
|
||||
[1]: https://github.com/geany/geany
|
||||
[2]: https://github.com/emojicode/emojicode
|
||||
[3]: https://www.emojicode.org/docs/
|
||||
[4]: https://www.emojicode.org/docs/guides/
|
||||
[5]: https://opensource.com/sites/default/files/2023-03/emoji.webp
|
||||
[6]: https://github.com/emojicode/emojicode/issues
|
@ -0,0 +1,193 @@
|
||||
[#]: subject: "Write a cute program with Emojicode"
|
||||
[#]: via: "https://opensource.com/article/23/4/emojicode"
|
||||
[#]: author: "Jessica Cherry https://opensource.com/users/cherrybomb"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: "geekpi"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
用 Emojicode 写一个可爱的程序
|
||||
======
|
||||
|
||||
在这篇文章中,我将介绍一个最好的编码语言,学习如何制作任何东西!它叫做 Emojicode。Emojicode 由 Theo Belaire 在 2014 年创建,是一种开源的编程语言,使用 emoji 字符来表示其语法。在 Emojicode 中工作时,emoji 被用来创建变量、函数和控制结构。因为它是一种静态类型的语言,变量类型必须在使用前声明,但它也支持类和继承等面向对象的概念。这种语言可以在每个操作系统上运行,它是一种超级有趣的编码方式,特别是当你是一个非英语母语的人时。这很有帮助,因为象形图表示法可以把我们大家聚集在一起,让我们以类似数学的方式说同样的语言。
|
||||
|
||||
### 先决条件
|
||||
|
||||
在本教程中,我使用的是基于 Debian 的操作系统。我的工具可能与你的操作系统的要求不同。以下是我所使用的工具:
|
||||
|
||||
- [Geany][1],一个 Linux 下的开源 IDE。
|
||||
- IBus,它允许你挑选 emoji 并把它们放在你的编辑器中。我使用的界面被称为 **emoji picker**。
|
||||
- 基于 Debian 的 Linux。
|
||||
- 一个 C++ 编译器。我使用的是 `g++` 编译器。
|
||||
- [Emojicode][2]
|
||||
|
||||
我使用的是 Linux 操作系统,但你可以[阅读文档][3]了解在其他操作系统上使用它时可能需要采取的任何特殊步骤。
|
||||
|
||||
### 在 Linux 上安装 Emojicode
|
||||
|
||||
有几种方法可以在你的电脑上安装 Emojicode,但他们有一个很酷的[神奇的安装页面][4],可以告诉你具体该怎么做。下面是我的做法:
|
||||
|
||||
```
|
||||
$ wget https://github.com/emojicode/emojicode/releases/download/v1.0-beta.2/Emojicode-1.0-beta.2-Linux-x86_64.tar.gz -O emojicode.tar.gz \
|
||||
&& tar -xzf emojicode.tar.gz && rm emojicode.tar.gz \
|
||||
&& cd Emojicode-1.0-beta.2-Linux-x86_64 && ./install.sh \
|
||||
&& cd .. && rm -r Emojicode-1.0-beta.2-Linux-x86_64
|
||||
```
|
||||
|
||||
emojicode的安装过程提供了有用的反馈。
|
||||
|
||||
![The emojicode installation procedure provides useful feedback along the way.][5]
|
||||
|
||||
现在,你已经安装好了,是时候开始编写代码了!
|
||||
|
||||
### 整体是如何进行的?
|
||||
|
||||
首先,所有 Emojicode 文件的扩展名都以文件名.🍇结尾,但因为你不能在一般的文件名中这样做,所以它被翻译成 `filename.emojic`。这里是最重要的语法元素:
|
||||
|
||||
- 把 🏁 放在一行的开头,表示要执行哪些代码块
|
||||
- 用 🍇 开始一个代码块
|
||||
- 用 🍉 来结束一个代码块
|
||||
- 想打印什么吗?就用 😀 🔤 `<string>` 🔤 ❗
|
||||
|
||||
还有很多其他的,所以这里有一些实际的例子。
|
||||
|
||||
### 打印一首俳句
|
||||
|
||||
首先,试着打印一首漂亮的俳句来玩玩吧! 在这个例子中,我将添加一行注释。看看你是否能识别它。
|
||||
|
||||
```
|
||||
🏁🍇
|
||||
💭 This is a single line comment for fun
|
||||
😀 🔤Emojicode is great,🔤 ❗
|
||||
😀 🔤Fun and expressive code,🔤 ❗
|
||||
😀 🔤no sadness, just joy.🔤 ❗
|
||||
🍉
|
||||
```
|
||||
|
||||
现在我们需要保存我们的代码,并通过我们的编译器运行它,使之成为一个漂亮的可执行文件:
|
||||
|
||||
```
|
||||
$ emojicodec haiku.emojic
|
||||
$ ls
|
||||
haiku haiku.emojic haiku.o
|
||||
```
|
||||
|
||||
正如你所看到的,代码已经被编译并生成了两个文件,其中一个是可执行的。运行 `haiku` 文件:
|
||||
|
||||
|
||||
```
|
||||
$ ./haiku
|
||||
Emojicode is great,
|
||||
Fun and expressive code,
|
||||
no sadness, just joy.
|
||||
```
|
||||
|
||||
### 数学和变量操作
|
||||
|
||||
接下来,你要同时做几件事:一点点数学和变量的改变。首先,将一个变量赋值为0:
|
||||
|
||||
```
|
||||
0 ➡️ 🖍🆕x
|
||||
```
|
||||
|
||||
你刚刚使用 crayon emoji 和变量名称旁边的新 emoij 创建了一个新变量,同时还将该变量赋值为 0。
|
||||
|
||||
接下来,用磁铁的 emoji 打印一行包括该变量的内容:
|
||||
|
||||
```
|
||||
😀 🔤The value is 🧲x🧲 🔤 ❗
|
||||
```
|
||||
|
||||
接下来,使用加号和箭头 emoji 改变变量:
|
||||
|
||||
```
|
||||
x ⬅️➕ 1
|
||||
```
|
||||
|
||||
然后打印另一行的值。我继续这样做了一会儿,然后打印出最终的数值。下面是我的做法:
|
||||
|
||||
```
|
||||
🏁 🍇
|
||||
|
||||
💭Updating a variable using math
|
||||
0 ➡️ 🖍🆕x
|
||||
😀 🔤The value is 🧲x🧲 🔤 ❗
|
||||
|
||||
x ⬅️➕ 1
|
||||
😀 🔤The value is 🧲x🧲 🔤 ❗
|
||||
|
||||
x ⬅️➕ 15
|
||||
😀 🔤The value is 🧲x🧲 🔤 ❗
|
||||
|
||||
x ⬅️➖ 9
|
||||
😀 🔤The value is 🧲x🧲 🔤 ❗
|
||||
|
||||
x ⬅️➗ 2
|
||||
😀 🔤The final value is 🧲x🧲 🔤 ❗
|
||||
🍉
|
||||
```
|
||||
|
||||
接下来,用 `emojicodec` 编译代码,然后用你的可执行代码来看看结果:
|
||||
|
||||
```
|
||||
$ emojicodec math.emojic
|
||||
$ ./math
|
||||
The value is 0
|
||||
The value is 1
|
||||
The value is 16
|
||||
The value is 7
|
||||
The final value is 3
|
||||
```
|
||||
|
||||
如你所见,作为变量打印出来的所有内容都已使用新数学进行了更新。你可以用许多数学 emoji 来进一步操作。下面是一些更多的运算符:
|
||||
|
||||
```
|
||||
🚮 is your modulo
|
||||
◀ Less than
|
||||
▶ Greater than
|
||||
◀🙌 less than or equal to
|
||||
▶🙌 greater than or equal to
|
||||
```
|
||||
|
||||
### Emojicode 的怪癖
|
||||
|
||||
当我在文档中来回查看时,我发现了一些有趣的怪癖。其中之一是,当从用户那里抓取输入时,由于一些已知的编译器问题,耳朵的肤色很重要。
|
||||
|
||||
获取用户输入的动作是这样的:
|
||||
|
||||
```
|
||||
🆕🔡▶️👂🏼❗️
|
||||
```
|
||||
|
||||
获取和分配用户输入的操作是这样的:
|
||||
|
||||
```
|
||||
🆕🔡▶️👂🏼❗️ ➡️ inputText
|
||||
```
|
||||
|
||||
我试图让它工作,但当我发现它时我的编译器出现了一些问题。 你也可能会在这里和那里遇到一些小问题。 如果你遇到了,请创建一个[问题][6],这样它就有可能被修复。
|
||||
|
||||
### 没有技巧,只有很棒的代码
|
||||
|
||||
虽然我可以了解更多,但我可以向你保证,这段令人惊叹的代码背后的文档非常广泛。尽管我写这篇文章只是为了赶上愚人节的乐趣,但我不得不承认这是有史以来最好的语言之一,因为它教会了你很多非常真实的编程概念。我恳切地建议把它作为一种有趣的方式来教你的一些朋友、孩子,或者是对编码感兴趣的同学。 希望你度过了一个充满乐趣的愚人节!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/23/4/emojicode
|
||||
|
||||
作者:[Jessica Cherry][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/cherrybomb
|
||||
[b]: https://github.com/lkxed/
|
||||
[1]: https://github.com/geany/geany
|
||||
[2]: https://github.com/emojicode/emojicode
|
||||
[3]: https://www.emojicode.org/docs/
|
||||
[4]: https://www.emojicode.org/docs/guides/
|
||||
[5]: https://opensource.com/sites/default/files/2023-03/emoji.webp
|
||||
[6]: https://github.com/emojicode/emojicode/issues
|
Loading…
Reference in New Issue
Block a user