FazBrowse Wikipedia Viewer | Main Page |
Search Wikipedia:
|
Viewing: https://en.wikipedia.org/wiki/Pascal_programming_language

Pascal (programming language)

Contents
    Subrange types
    Record types
    Procedures and functions

{{Cite web\n | url-status = dead\n | archive-url = https://web.archive.org/web/20120627043929/http://java.sun.com/docs/white/delegates.html\n | title = About Microsoft's \"Delegates\"\n | website = Sun Developer Network\n | url = http://java.sun.com/docs/white/delegates.html\n | archive-date = June 27, 2012\n | quote = We looked very carefully at Delphi [[Object Pascal]] and built a working prototype of bound method references in order to understand their interaction with the Java programming language and its APIs ... Our conclusion was that bound method references are unnecessary and detrimental to the language. This decision was made in consultation with Borland International, who had previous experience with bound method references in Delphi Object Pascal.\n | access-date = October 16, 2026}}</ref><ref>{{Cite web\n | author = TechMetrix Research\n | date = 1999\n | url-status = dead\n | archive-url = https://web.archive.org/web/20160822235943/http://www.fscript.org/prof/javapassport.pdf\n | title = History of Java\n | work = Java Application Servers Report\n | url = http://www.fscript.org/prof/javapassport.pdf\n | archive-date = August 22, 2016\n | quote = The project went ahead under the name \"green\" and the language was based on an old model of [[UCSD Pascal]], which makes it possible to generate interpretive code\n | access-date = October 16, 2026}}</ref><ref>{{Cite journal\n | last = Allman\n | first = Eric\n | date = August 31, 2004\n | url = https://queue.acm.org/doi/10.1145/1016998.1017013\n | title = A Conversation with James Gosling\n | journal = Queue\n | volume = 2\n | issue = 5\n | publisher = Association for Computing Machinery\n | doi = 10.1145/1016998.1017013\n | url-status = live\n | archive-url = https://web.archive.org/web/20251121221939/https://queue.acm.org/detail.cfm?id=1017013\n | archive-date = November 21, 2025\n | access-date = October 16, 2026}}</ref>\n | [[Nim (programming language)|Nim]]\n | [[Modula]]{{\\}}[[Modula-2|-2]]{{\\}}[[Modula-3|-3]]\n | [[Oberon (programming language)|Oberon]]{{\\}}[[Oberon-2|-2]]\n | [[Object Pascal]]\n | [[Oxygene (programming language)|Oxygene]]\n | [[DEC MICA#Programming|Pillar]]\n | [[Microsoft Power Fx|Power Fx]]\n | [[Standard ML]]\n | [[Structured text]]\n | [[VHDL]]}}"},"wikibooks":{"wt":"Pascal Programming"}},"i":0}}]}'>
Pascal
Paradigm
Dialects

Pascal is an imperative and procedural programming language, designed by Niklaus Wirth as a small, efficient language intended to encourage good programming practices using structured programming and data structuring. It is named after French mathematician, philosopher and physicist Blaise Pascal.

Pascal was developed on the pattern of the ALGOL 60 language. Wirth was involved in the process to improve the language as part of the ALGOL X efforts and proposed a version named ALGOL W. This was not accepted, and the ALGOL X process bogged down. In 1968, Wirth decided to abandon the ALGOL X process and further improve ALGOL W, releasing this as Pascal in 1970.

On top of ALGOL's scalars and arrays, Pascal enables defining complex data types and building dynamic and recursive data structures such as lists, trees and graphs. Pascal has strong typing on all objects, which means that one type of data cannot be converted to or interpreted as another without explicit conversions. Unlike C (and also unlike most other languages in the C family), Pascal allows nested procedure definitions to any depth, and allows most kinds of definitions and declarations inside subroutines (procedures and functions). A program is thus syntactically similar to a single procedure or function. This is similar to the block structure of ALGOL 60, but restricted from arbitrary block statements to just procedures and functions.

Pascal became very successful in the 1970s, notably on the burgeoning minicomputer market. Compilers were also available for many microcomputers as the field emerged in the late 1970s. It was widely used as a teaching language in university-level programming courses in the 1980s, and also used in production settings for writing commercial software during the same period. It was displaced by the C programming language during the late 1980s and early 1990s as UNIX-based systems became popular, and especially with the release of C++.

A derivative named Object Pascal designed for object-oriented programming was developed in 1985. This was used by Apple Computer (for the Lisa and Macintosh machines) and Borland in the late 1980s and later developed into Delphi on the Microsoft Windows platform. Extensions to the Pascal concepts led to the languages Modula-2 and Oberon, both developed by Wirth.

packed keyword tells the compiler to use the most efficient method of storage for the structured data types: sets, arrays and records, rather than using one word for each element. Packing may slow access on machines that do not offer easy access to parts of a word.

Subrange types

edit

Subranges of any ordinal data type (any simple type except real) can also be made:

Pascal compilers:

ifiin[0..3,7,9,12..15]then...

For these examples, which involve sets over small domains, the improved performance is usually achieved by the compiler representing set variables as bit vectors. The set operators can then be implemented efficiently as bitwise machine code operations.

Record types

edit

A record is a structure comprising any number of member elements called fields. Fields are defined by specifying an identifier–data type pair delimited by a colon; nested records are possible. The field list is then terminated by the end keyword. A record variable's fields can later be accessed by inserting a dot (.) between the record name and the field identifiers. An example of a Pascal record type:

type x=integer; y=x; ...

Further, complex types can be constructed from simple types:

type a=fileofinteger; b=record x:integer; y:char end; c=fileofb;

As shown in the example above, Pascal files are sequences of components. Every file has a buffer variable which is denoted by f^. The procedures get (for reading) and put (for writing) move the buffer variable to the next element. Read is introduced such that read(f, x) is the same as x := f^; get(f);. Write is introduced such that write(f, x) is the same as f^ := x; put(f); The type new(NodePtr); ... NodePtr^.a:=10; NodePtr^.b:='A'; NodePtr^.c:=nil; ...

This could also be done using the with statement, as follows:

whilea<>bdoWriteLn('Waiting'); ifa>bthenWriteLn('Condition met'){no semicolon allowed before else} elseWriteLn('Condition not met'); fori:=1to10do{no semicolon here as it would detach the next statement} WriteLn('Iteration: ',i); repeat a:=a+1 untila=10; caseiof 0:Write('zero'); 1:Write('one'); 2:Write('two'); 3,4,5,6,7,8,9,10:Write('?') end;

Procedures and functions

edit

Pascal structures programs into procedures and functions. Generally, a procedure is used for its side effects, whereas a function is used for its return value.


View original on Wikipedia | Back | FazBrowse Home