The most beautiful Programming Language Scheme-Basic Expressions

Source: Internet
Author: User

Scheme is hailed by many as "the most beautiful in the worldProgramming Language". Even with their words, scheme started its journey.

Currently, scheme is mostly used for scientific research and is rarely used for commercial use. But even so, it will not be "beautiful ".

Let's join me in the world of scheme.

 

Like other programming languages, playing scheme requires a development environment. We can search for MIT-GNU-scheme through Google. It includes windows, Linux, and Mac OS X. Download the corresponding version based on your operating system. I have used Windows and Mac OS X, but the interfaces are the same-they are all in the console.

We enterProgramYou can press Ctrl + h and then press t to view the wizard. Here we will teach you how to use this tool.

Press Ctrl + X, then press B, and then enter the scheme expression calculation mode.

 

Next let's take a look at one of scheme's simplest expressions: 1 + 2

In the tool, enter:

(+ 1 2) 

Then press Ctrl + X, then press Ctrl + e, and then we can see the output:

; Value: 3

 

We use Ctrl + X, CTRL + e to calculate each of the following expressions.

 

We can see from the first program example that the expression of scheme is a prefix expression, that is, the operator is placed at the leftmost. In this way, you can define a real parameter process with any number.

In scheme, like an imperative language such as C/C ++, 0,346,-3.5, and so on are used as the most basic expressions. The above (+ 1 2) is already a compound expression.

We will list some more complex expressions below:

(+ 1 2 3 4 5) <br/>; Value: 15 <br/> (+ 10 (-100 20) <br/>; value: 90 <br/> (+ 1 (* 3 4) (-2 4) (/6 3) <br/>; Value: 13 

Scheme is also an explanatory language, so it has many dynamic features.

One of them is the ability to automatically recognize real numbers and integers. For example:

(+ 1 1.5) <br/>; Value: 2.5 <br/> (/3 2) <br/>; Value: 3/2 <br/> (/3.0 2.0) <br/>; Value: 1.5 

We use the aboveCodeWe can know that the value type is dynamically recognized by the interpreter. In the second sentence, the output is 3/2, not 1. This helps to maintain accuracy.

 

The following describes how to define a variable in scheme. Define a variable in scheme and associate the variable with the expression. For example, we define an X as 2:

(Define x 2) <br/>; Value: x 

In terms of semantics, X is associated with expression 2. Let's take a look at the definition of x and combine it with other expressions:

(Define x 2) <br/>; Value: x <br/> (+ x 10) <br/>; value: 12 <br/> (define y (/3 2) <br/>; Value: y <br/> (+ y 0.5 x) <br/>; value: 4. <br/> (+ y 0.1) <br/>; Value: 1.6 

We can see the multiplication of the previously reserved integers. When the real number is encountered, its precision is still preserved.

 

In the next chapter, we will learn how to use scheme to define the process.

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.