2.1 Introduction to Data abstraction

Source: Internet
Author: User

"sicp?2.1 Data Abstract Introduction" look uncomfortable, spit trough a bit.

The basic idea of data abstraction was to structure the programs that was to use compounddata objects so that they The operate on ' abstract data. ' Interface operates on an abstraction.

At the same time, a "concrete" data representation is defined independentof the programs, the data. The interface between these and parts of Oursystem would be a set of procedures, calledselectors and construct ORS, that's implement theabstract data in terms of the concrete representation. Don't quite understand the meaning of this interface.

The specific representation of the data is independent of the program that uses it. Selectors and constructors is the implementation tool for the specific representation of the data, and why is this two-part interface?

Take fractions as an example:

Well, package the adhesive above, assuming there are now (Make-rat <n> <d>), (Numer <x>), (Denom <x>). We do not consider how the scores are expressed, and regardless of how the above functions are implemented, we wishful thinking (this wishful thinking, wishful thinking alone should be humorous, reasonable assumption): On the basis of the above Make-rat functions, Add-rat and other +-*/methods are designed ....

Halo,Selectorsand constructors refers to Make-rat, Numer, denom?!

I don't like this kind of narration.

"Introduction to Programming (Java) 4.1.3 string", first of all: it is generally considered that the minimum set of interfaces required by a string should contain 5 methods, the programmer only uses the minimum interface set of 5 methods, determine whether the string has the specified prefix (and description: Actually, the String class provides a Boolean StartsWith (Stringprefix). Outside of the minimum interface set, String provides a number of inexpensive methods such as prefix suffix judgment, case change, character replacement, and removal of useless blank trim (). )。 】

Indeed, (Make-rat<n> <d>), (Numer <x>), (denom <x>) can form the smallest interface for fractions, but I have always put the 3 common functions associated with pair cons, car, Cdr is believed to be selectorsand constructors. Dizzy, not tangled up.

In addition, (refer to the previous note) if the Make-rat, Numer, denom as the minimum interface, then you can determine that the data type is a fraction, directly using cons, car, CDR, we are just bonding data.

Note: Interfaces (interface) are all the information that users of this method need to know, including method headers (method prototypes), and very important documentation. Whether or not a document is written, the purpose of the function is part of the interface, so Make-rat is the interface. Although

(Define Make-rat cons)

Make-rat and cons, are different levels of things.

The so-called different levels, SICP it called abstraction barriers, in fact, such as "4.1.3 String", the minimum interface set and inexpensive method is not necessary to separate two layers. If you want to subdivide, do not know how many barriers can be produced. Moreover, the minimum set of interfaces for each data type is difficult to define. Unless, like SICP, the Selectorsand constructors is referred to as the minimum set of interfaces for all data types and is not specifically cons, car, CDR (spit again).

Simply put, there is only one layer of skin-the interface. The user program uses the interface; The implementation of the interface uses cons, car, and CDR internally.


What is meant by Data? Not at the moment, what's the point?

Data (types) are defined by their interfaces, and they must meet a specific set of conditions, that is, the minimum set of interfaces.

Order pairs-the way you make data types, you can use cons or processes, and then what?

Exercise 2.6 We can get by without numbers!

Wow!!! What is a man? In a corner description: People are a bunch of atoms!!!

Abstract a variety of data types to facilitate programmer programming. But in essence, all the elements of a functional language are defined by the lowest-level lambda expression. To some extent, we can directly program with lambda expressions without defining any data, operators (just as it is programmed directly using 01 machine language). However, we need to abstract, compare cons its process implementation ....


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

2.1 Introduction to Data abstraction

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.