[Introduction to Scheme]3 Eqv?, loop, let, Letrec, do, etc. comparison and use

Source: Internet
Author: User

I. Comparison of objects


1, eq?

This function is used to compare the addresses of 2 objects, and returns #t if the same is true. In scheme, it is true that #t is used for false #f.

For example, (eq? STR str) returns #t because the address of STR itself is the same, but "scheme" and "scheme" are stored in different addresses, so the function returns #f. Note that you do not use EQ to compare numbers, because there are no specified return values in R5rs and mit-scheme, we recommend using eqv or = instead. Here are some examples:

(Define STR "scheme")

; Value:str

(eq. str str)

; Value: #t

(eq?) "Scheme" "scheme")

; Value: () in R5rs, return #f here


2, Eqv?

The function compares the type and value of 2 objects stored in memory and returns #t if both types and values are consistent. The comparison of a procedure (lambda expression) relies on a specific implementation. This function cannot be used for sequence comparisons similar to tables and strings, because although these sequences appear to be consistent, they are stored in different addresses. The following are also some examples:

(Eqv? 1.0 1.0)

; Value: #t

(eqv? 1 1.0)

; Value: ()

(Eqv?) (List 1 2 3)                (List 1 2 3)) Don't compare sequences.

; Value: ()

(Eqv?) "Scheme" "scheme")

; Value: ()


3, equal?

The comparison sequence should be the function.

(equal?) (List 1 2 3) (List 1 2 3))

; Value: #t

(equal?) "Hello" "Hello")

; Value #t


4. Some other functions for comparison

pair? #t

list? If the object is a table, return #t

null? If the object is empty table ' () then return #t .

symbol? If the object is a symbol, return #t .

char? If the object is a character, return #t .

string? If the object is a string, return #t .

number? If the object is a number, return #t .

complex? If the object is a complex number, return .

real? If the object is a real number, return .

rational? If the object is a rational number then return #t .

integer? If the object is an integer, return .

exact? If the object is not a floating-point number, it returns .

Inexact? Returns the #tif the object is a floating-point number.

Odd? returns the #tIf the object is an odd number.

Even? if the object is an even number, the #tis returned.

Postitive? returns the #tif the object is a positive number.

< Span style= "line-height:200%; font-family: ' Microsoft Ya Black ', ' sans-serif '; font-size:12pt ">negative? .

Zero? returns the #tif the object is 0.

Similar to comparing numbers with <=, you can use char=? ,, char<? char>? , char<=? and char>=? functions when comparing characters.

比较字符串时,可以使用string=?string-ci=?等函数。





[Introduction to Scheme]3 Eqv?, loop, let, Letrec, do, etc. comparison and use

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.