An introduction to the whirlwind of intimate number programming language

Source: Internet
Author: User

      • Why Learn to Program
      • Hello World
      • Arithmetic operations
      • Operations and viewing stacks
      • Get help
      • Data type
      • Control statements
        • Repeat
        • Branch
        • Cycle
      • Defining keywords
      • Drawing
        • Coordinates
        • Basic drawing Commands
        • Turtle Chart
      • Conclusion

Why Learn to Program

Here I want to quote a paragraph of text.

The anthropological language learns not only to listen and to speak, but to learn not only to read but also to write; now as we move towards a more digital world, we should not only learn how to use the program, but also how to develop it. In the future, faced with a highly programmed world, if you can't develop software, then you will become software. It's that simple: either programming or being programmed (program or be programmed). “

The original text is the famous media technology scholar Douglas Rushkof, I see this passage is 36 krypton above translation. As a programmer, I see this as a good thing. Your automatic washing machine, your TV remote control, and your phone are all running on the program. The importance of the program is needless.

And we're not sure that the whole world is a god-designed Sims program. I always really feel that our whole world is a program. Understanding programming may be the key to understanding our world. Let me give you some examples of what science fiction or popular science articles might be in these examples, I can't remember.

The electrons run around the nucleus in orbit, and the planets run around the stars in orbit, which is like a lazy (clever) programmer using an object-oriented approach to apply a model to two places.

The speed at which information travels across the universe cannot exceed that of the speed of light, which is not like the limit of the host processor processing power that is running in our world, The Sims game?

There are many myths in ancient times, such as Nu wa and Hou Yi Shoot day, it is not like because the ancient version of the program 1.0 defects (bugs) more, and now is the 2.0 version of these defects have been fixed?

Do these examples persuade you that the whole world may be a program? Let's use the program and the world to say hello.

Hello World

Introduction to the book conventions of programming languages the first program is "Hello World", she can give the beginner confidence, programming is not so difficult, and she can also ensure that the programming and execution of the program environment ready. The intimate number programming language can be run directly in the browser, all you need is a computer (or mobile phone) that can surf the internet. Opens a link to the read human operation output Loop (REPL) environment for the intimate number programming language. If successful (JavaScript is supported), you will see that three regions are input, output, and canvas, respectively.

The input box is used to enter the program. The output box is used to display the program output results. The canvas is used to display graphics.

Enter the following in the input box, and then 你好世界 press ENTER (or click the Run button), then enter, and then press ENTER, the output box will show the following results.

Our first program to say hello to the world is finished. To explain a little bit, 你好世界 it is a string, and it is placed on the stack when you type it into a string. The keyword is used to display everything in the stack.

Arithmetic operations

Arithmetic is a small meaning for computer languages. It is important to note that the intimacy Number programming language uses the inverse Polish expression, also known as the suffix expression. In order to calculate 1 + 2 , you need to enter 1和2加 or 一和二加 . Here and is the key word. used to separate numbers for addition operations. See the procedure below. Use the same to view the results.

In addition to the addition operation, the intimacy number programming language supports multiplication, division, subtraction, and the remainder (currently only supports integer operations, which do not support floating-point numbers), the corresponding keywords are ,, , .

The following program calculates (3+2)x(4+1)÷5

Operations and viewing stacks

What is a stack? You can imagine a stack of bowls. Most of the time, when the bowl is placed from the top, take the bowl from the top. The first take-back. In computer language, stacks are used much. In the intimate number programming language, it is more important.

Now that the stack is so important, here are a few key words to focus on the operation and viewing of the stack.

We used it in front of it to see everything inside the stack. For example, the following program is displayed 五〇六〇 .

But here's a question, and we don't know if it represents 五〇 六〇 a two or 五千零六十 a number. The keyword also outputs the contents of the stack, but uses it to separate the different elements within the stack. This is necessary in some cases. See the procedure below.

Sometimes we do not need to output all the elements in the stack, and only need to output the top of the stack of elements, this time can be used .

If you want to erase everything inside the stack, use it if you just want to remove the element from the top of the stack, or if you want to copy the top element of the stack, use it if you want to swap the top Two elements of the stack . These keywords are used in the following program calculations 四的平方减去三的平方 .

The keywords such as, and none of the output operations on the stack will change the contents of the stack. The rest will change the contents of the stack. and an element to the top of the stack. The two elements of the top of the stack are exchanged. There is also a keyword that affects the top three elements of a stack. This keyword takes the third element of the top of the stack out and puts it on top of the stack to become the first element on top of the stack. Here is An example of an application.

Get help

Looking at the previous introduction, you should have a preliminary understanding of the intimate number programming language. Can introduce so many key words, can't remember how to do? Keyword to see all the keywords supported in the intimate Number programming language dictionary. Keyword to see a brief description of these keywords. Keyword to see all the numbers supported by the intimate number programming language. The words in the dictionary will increase or change in the future. Users can also define their own words. The following chapters will show you how to define your own keywords.

Pro>WordWord Help number now look at the change of double ring subtraction negative and always turn the weight if not select when set pure cloth to move the line to rub step to go the inverse colorPro>HelpWord--all the words in the output dictionaryHelp--Get helpnumber--output all supported numbersnow--content of the output stack (delimited)See--content of the output stack (without delimiters)Tune--the detailed contents of the output stack are for debugging purposes.Glance--output (but not lose) the top element of the stacklost--discard the top element of the stackQing--Empty StackChange--two elements of the top of the swap stackDouble--copy stack top elementRing--rotate the top three elements of a stackPlus--add two elements to the top of a stackminus--subtract two elements from the top of a stackMultiply--multiply two elements at the top of a stackexcept--divide two elements at the top of a stackYu--two elements in the top of the stack for remainderNegative--stack top element multiply negative oneand the--used to separate adjacent numbers or strings.Start--Identity list StartEnd--End of Identity listTurn--Escape the next wordLine--Perform a listHeavy--repeat a specified number of timesif--If True, execute theNo--unless true (if False) is performedChoose--If True then candidate one if False then execute candidate twowhen--if it's true, keep doing it.Set--Custom WordPure--Clear All custom wordscloth--display the properties of a canvasMove--move to the specified positionLine--draw a line to a specified positionRub--clear the content on the canvasStep--Set Step sizeGo--Take a step (leave a trail)Jump--Skip one step (leave no traces)Shun--turn right (clockwise)Inverse--Turn Left (counterclockwise)Color--Set the color (red,Green,Blue)Pro>number012345678901234567890 1234567890 One and three Woolu Qi Ba Jiu10 hundred thousand million trillion
Data type

The data types currently supported by the intimacy Number programming language are integers, strings, keywords, and lists.

100or 一〇〇 , or, is an integer type. Integer types can participate in arithmetic operations and can also be used as parameters for keywords.

中国人, etc. is a string type.

The words defined in an intimate number programming language dictionary are keywords. The dictionary includes system-predefined words and user-defined words. User-defined words cannot overwrite system-predefined words. User-defined words can override user-defined words.
You can view all the words contained in the dictionary.

The list type begins with the keyword and ends with the keyword . When you define a list, the content is treated as a normal string. However, you can 行重若不择当 run the contents of the list by using keywords. Keywords can also be used to define the keyword as a list, and then calling the new defined keyword is equivalent to executing the content in this list. A list type is an important part of constructing control statements, which can be said to be intimate with the Shuma of the programming language.

The following program uses numbers, strings, and lists.

亲> 10和20和30始加加只羊终亲> 现一〇和二〇和三〇和始加加只羊终亲> 行亲> 看六〇只羊

Keyword is used to execute the contents of the list, which is the first time we use it. When you talk about control statements later, the list will have more apps.

Control statements

The previous programs are executed sequentially, straightforward. It's nothing to be proud of if the program is executed like this. The program should let the computer help us do the work that we humans are not good at but the computer is good at, such as repeating one thing many times.

Repeat

Keyword is used to repeat the list or keyword. The following program outputs 10 times 我爱你 .

亲> 清亲> 1和10始瞥1加我爱你瞥丢终亲> 重一我爱你二我爱你三我爱你四我爱你五我爱你六我爱你七我爱你八我爱你九我爱你一〇我爱你
Branch

Often we need to decide what to do based on certain preconditions. For example: If it rains, I will wash my hair, if fall into the river, I will bathe. If you don't come, I'll keep waiting. Here 天下雨 , 掉河里 你不来 all are prerequisites. 天下雨and 掉河里 is a prerequisite for certainty. 你不来is a precondition for negation.

The intimacy Number programming language does not have a special Boolean value, but is like the C language with 0 and not 0 for false and true. If the element above the stack is a value of 0, then the precondition is false. If the element above the stack is a non-0 value, the precondition is true.

The keyword is 如果 used to determine the positive precondition, and if the precondition is true, the statement is executed.

The following program uses the keyword .

亲> 1亲> 始我爱你终亲> 若亲> 现我爱你

The keyword represents a 除非 precondition for judging negation, and executes the statement if the precondition is false.

The following program uses the keyword .

亲> 清亲> 0亲> 始我恨你终亲> 不亲> 现我恨你

Keywords are used for synthesis 如果 and 除非 scenarios. It is semantically equivalent to executing statement two if the precondition is true.

The following program uses the keyword .

亲> 清亲> 1始我跟你玩终始我不跟你玩终亲> 择亲> 现我跟你玩
Cycle

We can use keywords in cases where the number of repetitions is known . If you need to decide when to end a repetition based on a precondition, you can use the keyword .

The keyword first takes a list or string from the top of the stack as the statement to execute, and then takes the next element as a precondition. When the precondition is true, the statement is executed, otherwise it is not executed. After executing the statement, it still takes the next element out of the stack and decides whether to continue execution by judging whether it is true. You can control whether the loop continues by modifying the elements at the top of the stack in the executed statement.

The following program uses the keyword to output 一〇 to .

亲> 清亲> 10和10始瞥1减双终亲> 当一〇九八七六五四三二一
Defining keywords

If the intimate number programming language can only use predefined keywords, then it is closed, like the current Chinese Internet, if it allows users to define new keywords, then it is open, just like the current U.S. Internet. The intimacy Number programming language is open, which allows the use of keywords to define new keywords.

You can define a new keyword as a number. For example, the following program is defined as 1 million.

亲> 清亲> 兆亲> 1000000亲> 设亲> 兆兆加亲> 现二〇〇〇〇〇〇

You can define a new keyword as a string. For example, the following program is defined as a string 自恋自大狂 . A new keyword is used to clear all user-defined keywords.

亲> 清亲> 纯亲> 我和自恋自大狂亲> 现我和自恋自大狂亲> 设亲> 现亲> 我我我亲> 看自恋自大狂自恋自大狂自恋自大狂

Defining a new keyword as a number or string can use this keyword as a variable. You can also define a new keyword as a string or list that contains additional keywords.

The following program definition keyword is used to calculate the square, defining the keyword to be used to calculate the cube, and to define the new word in terms of strings and lists, respectively. The string contains the keywords and , in order to postpone the operation, to be escaped with the keyword . In the list, the word between and is already escaped, so you don't need a keyword. In and between if you want to include additional keywords, you need keywords .

亲>  清纯亲> 方和转双转乘设亲> 立始双双乘乘终设亲> 2方瞥四亲> 2立瞥八
Drawing

Sometimes a graph is worth thousands of thousand words (a picture is Worth a thousand Words). The grammar of the intimate number programming language is inspired by the Forth language, and the drawing function of the intimate number programming language is influenced by the logo language. In the previous program, we used the input, output area, now we can use the canvas area.

Coordinates

We draw the coordinate system called the decathlon coordinate system. Any point above the canvas is determined by the horizontal ordinate. In this coordinate system, the upper-left coordinate is (0,0), the right axis is increased, and the vertical axis is increased.

Basic drawing Commands

Keywords are used to empty the canvas.

The keyword takes two integers from the top of the stack as a horizontal ordinate to determine a point, and then moves the cursor to that point.

The keyword 线 takes two integers from the top of the stack as a horizontal ordinate to determine a point, and then draws a line to it, moving the cursor at the same time.

The following program 线 draws a triangle with these two commands.

亲> 清纯擦亲> 100和100移亲> 300和300线亲> 100和300线亲> 100和100线亲> 10和10移

Turtle Chart

If you know the logo language, you know in the logo language, the user can control a turtle (tortoise) to draw. Users can make it go forward, turn left, turn right, and so on. This time the user can forget the decathlon coordinate system and only consider their own (turtle) coordinate system. This coordinate system is the turtle's coordinate system, this geometry is called the turtle geometry, this kind of figure is called the Turtle chart.

The intimate number programming language is inspired by the logo language and can also be controlled by a small turtle to draw a turtle map. But because she is a native Chinese programming language, here I think the turtle is more suitable. So the intimacy number programming language can control a small clay turtle to draw the Soil Turtle chart. (My hometown has a curse words called "turtle grandson King eight Duzi turtle in-laws", it appears that these three kinds of animals are similar. )

Here are the commands related to the Turtle chart.

Keyword to view the properties of the current canvas. You can see the width and height of the canvas, the current position, step size, color, and orientation of the small turtle. See the procedure below.

亲> 布宽度1422高度320坐标(10,10)颜色rgb(0,0,0)步长16朝向北

Initially, the small clay turtle is facing north (upper north left west right east), the step is 16 pixels, the color is black.

The keyword allows the turtle to take a step towards the current direction and draw a trace on the canvas.

The keyword lets the turtle jump one step toward the current direction, leaving no traces on the canvas.

Keywords let the small turtle turn right, that is, 90 degrees clockwise turn.

Keywords let the small turtle turn left, that is, counterclockwise turn 90 degrees.

Keyword to reset the stride size. It takes the elements at the top of the stack as steps.

Keyword to reset the color. It takes three elements of the top of the stack, representing the red, green, and blue pigment values, which are mixed together to form the current color. The values of the pigments range from 0 to 255.

The following program draws 4 squares with a Turtle Chart command.

亲> 10和10移亲> 方始顺走走顺走走顺走走顺走走终设亲> 方亲> 32步亲> 方亲> 64步亲> 方亲> 255和0和0色亲> 128步亲> 方

Conclusion

It is said that the inventor of the Ruby language, Matsumoto, often went to the community to look at other people's programs to discover some new uses of the Ruby language. Although I realized the intimate number of Chinese programming language, but a lot of her unknown potential I was not expected to. I want to see you do something interesting with her and surprise me.

An introduction to the whirlwind of intimate number programming language

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.