Use ironscheme to enter the world of scheme programming languages

Source: Internet
Author: User

Use SchemeProgramVoice: Hello world. Open your editor, create a file named hello. SS, and save the following text:

 
; Hello. SS (Import (rnrs) (begin; display "Hello world.") (newline ))

The first line is a comment. Scheme ignores the semicolon (;) and text content after it.

Begin is transmittedSubordinate statement segment(Subform) a method of sequence. In the preceding example, there are two sub-statement segments. Call the display processing function in section 1st: Output its real parameter (string "Hello world.") to the console (or "standard output "). Section 2nd is the call of the newline processing function: A carriage return is output.

To run the program, open the ironscheme console and enter:

 
(Load "E: \ work \ hello. SS ")

Scheme will execute the content in hello. SS and OutputHello world.Followed by a carriage return.

In "Higher-order functions: functions used as parameters, functions generated, and anonymous functions", use an anonymous function to calculate the square of a given number:

 
; Square. SS (Import (rnrs); defines the square function (define Square; anonymous function (lambda (x) (* X); calls the square function, then display (square 3) (newline) (Display (Square 4) (newline)

Result of executing the square. SS content

In the "FP" shared by Abruzzi, the list parameters are accumulated using the apply processing function:

 
; List. SS (Import (rnrs) (define (sum Arglist) (apply + Arglist) (define P' (1 2 3 4 5 6) (Display (sum p )) (newline)

AboveCodeNote: use single quotes to specify the list. You can also write it as follows:

 
(List 1 2 3 4 5 6)

Refer:

Teach Yourself scheme in fixnum days)

(End)

Related Article

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.