Content deleted Content added
m Open access bot: hdl updated in citation with #oabot. |
+cat. |
||
(16 intermediate revisions by 8 users not shown) | |||
Line 42:
| wikibooks = Pascal Programming
}}
'''Pascal''' is an [[Imperative programming|imperative]] and [[Procedural programming|procedural]] [[programming language]], designed by [[Niklaus Wirth]] as a small, efficient language intended to encourage good programming practices using [[structured programming]] and [[data structure|data structuring]]. It is named after French mathematician, philosopher and physicist [[Blaise Pascal]].{{efn|In an issue of ''[[Electronics (magazine)|Electronics]]'' in 1978, Wirth explained why he named the language after Blaise Pascal: "Actually, I am neither capable of fully understanding his philosophy nor of appreciating his religious exaltations. Pascal, however, was (perhaps one of) the first to invent and construct [[Pascal's calculator|a device]] that we now classify as a digital computer."<ref>{{cite magazine |last=Wirth |first=Niklaus |author-link=Niklaus Wirth |date=1978-12-21 |title=Obeisance to Pascal, inventor |magazine=[[Electronics (magazine)|Electronics]] |publisher=Dan McMillan |editor1-first=Kemp |editor1-last=Anderson |department=Readers' comments |issn=0013-5070 |url=https://www.worldradiohistory.com/Archive-Electronics/70s/78/Electronics-1978-12-21.pdf |access-date=2024-08-13 |archive-url=https://web.archive.org/web/20240520045053/https://www.worldradiohistory.com/Archive-Electronics/70s/78/Electronics-1978-12-21.pdf |archive-date=2024-05-20 |url-status=live |page=6}}</ref>}}
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 [[variable (computer science)|scalar]]s and [[array (data type)|arrays]], Pascal enables defining complex datatypes and building dynamic and recursive data structures such as [[list (abstract data type)|list]]s, [[tree (data structure)|tree]]s and [[graph (abstract data type)|graph]]s. Pascal has [[strong and weak typing|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 level of depth, and also 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. [[Compiler]]s were also available for many [[microcomputer]]s 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)|C programming language]] during the late 1980s and early 1990s as [[UNIX]]-based systems became popular, and especially with the release of [[C++]].
Line 63:
===Pascal===
Pascal was influenced by the ALGOL W efforts, with the explicit goals of teaching programming in a [[structured programming|structured fashion]] and for the development of system software.<ref>{{Cite book|chapter-url=https://link.springer.com/chapter/10.1007/10722581_1|doi = 10.1007/10722581_1|chapter = The Development of Procedural Programming Languages Personal Contributions and Perspectives|title = Modular Programming Languages|series = Lecture Notes in Computer Science|year = 2000|last1 = Wirth|first1 = Niklaus|volume = 1897|pages = 1–10|isbn = 978-3-540-67958-5}}</ref> A generation of students used Pascal as an introductory language in undergraduate courses. Other goals included providing a reliable and efficient tool for writing large programs,<ref>{{cite journal |last1=Wirth |first1=N. |title=The Programming Language Pascal |journal=Acta Informatica |date=1971 |volume=1 |issue=1 |pages=35–63 |doi=10.1007/BF00264291|hdl=20.500.11850/68712 |hdl-access=free }}</ref>
One of the early successes for the language was the introduction of [[UCSD Pascal]], a version that ran on a custom [[operating system]] that could be ported to different platforms. A key platform was the [[Apple II]], where it saw widespread use as [[Apple Pascal]]. This led to Pascal becoming the primary [[high-level language]] used for development in the [[Apple Lisa]], and later, the [[Mac (computer)|Macintosh]]. Parts of the original [[Classic Mac OS|Macintosh operating system]] were hand-translated into [[Motorola 68000]] [[assembly language]] from the Pascal [[source code]].<ref>Hertzfeld, Andy. "[http://www.folklore.org/StoryView.py?project=Macintosh&story=Hungarian.txt&topic=Software%20Design&sortOrder=Sort%20by%20Date&detail=medium Hungarian folklore.org] {{webarchive|url=https://web.archive.org/web/20151118082558/http://www.folklore.org/StoryView.py?project=Macintosh&story=Hungarian.txt&topic=Software%20Design&sortOrder=Sort%20by%20Date&detail=medium |date=2015-11-18}}: Macintosh Stories. Retrieved 2012-03-06.</ref>
Line 83:
===Object Pascal===
During work on the Lisa, [[Larry Tesler]] began corresponding with Wirth on the idea of adding object-oriented extensions to the language, to make Pascal a [[Programming paradigm|
The Object Pascal extensions were added to [[Turbo Pascal]] with the release of version 5.5 in 1989.<ref>{{cite web|title=Antique Software: Turbo Pascal v5.5|url=http://edn.embarcadero.com/article/20803|access-date=2018-05-17|archive-date=2010-11-24|archive-url=https://web.archive.org/web/20101124090934/http://edn.embarcadero.com/article/20803|url-status=dead}}</ref> Over the years, Object Pascal became the basis of the [[Delphi (software)|Delphi]] system for [[Microsoft Windows]], which is still used for developing Windows applications, and can [[cross-compile]] code to other systems. [[Free Pascal]] is an open source, cross-platform alternative with its own graphical [[integrated development environment|IDE]] called [[Lazarus (IDE)|Lazarus]].
Line 96:
A completely new compiler was completed by Welsh et al. at QUB in 1977. It offered a source-language diagnostic feature (incorporating profiling, tracing and type-aware formatted postmortem dumps) that was implemented by Findlay and Watt at Glasgow University. This implementation was ported in 1980 to the [[ICL 2900]] series by a team based at [[Southampton University]] and Glasgow University. The Standard Pascal Model Implementation was also based on this compiler, having been adapted, by Welsh and Hay at [[Manchester University]] in 1984, to check rigorously for conformity to the BSI 6192/ISO 7185 Standard and to generate code for a portable abstract machine.
The first Pascal [[compiler]] written in North America was constructed at the [[University of Illinois at Urbana–Champaign|University of Illinois]] under [[Donald B. Gillies#Later career|Donald B. Gillies]] for the [[PDP-11]] and generated native machine code. Microsoft had Pascal compilers for IBM PCs, see [[Microsoft Pascal]].
==={{anchor|Pascal-P}}The Pascal-P system===
Line 173:
|-
| [[Array data type|array]]
| a countable group of any of the preceding data types,
|-
| [[Record (computer science)|record]]
| A collection of any of the preceding data types or of other records
|-
| [[string (computer science)|string]]
Line 182:
|}
The range of values allowed for the basic types (except Boolean) is implementation defined. Functions are provided for some data conversions. For conversion of <code>real</code> to <code>integer</code>, the following functions are available: <code>round</code> (
The programmer has the freedom to define other commonly used data types (e.g. byte, string, etc.) in terms of the predefined types using Pascal's type declaration facility, for example
Line 284:
end;
c = file of a;
</syntaxhighlight>
Further, complex types can be constructed from other complex types recursively:
:<syntaxhighlight lang="pascal">
const
Jack = 11;
Queen = 12;
King = 13;
Ace = 14;
type
valueType = 2..Ace;
suitType = club, diamond, heart, spade;
cardType = record
suit: suitType;
value: valueType;
end;
deckType = array [1..52] of cardType;
person = record
surname: packed array [1..20] of char;
age: integer;
end;
table = record
hands: array [1..3] of deckType;
players: array [1..4] of person;
end;
</syntaxhighlight>
Line 388 ⟶ 419:
end;
function triple(
begin
triple := x * 3
Line 506 ⟶ 537:
===Early criticism===
Wirth's initial definition of the language was widely criticized. In particular, [[Nico Habermann]] commented in his "Critical Comments on the Programming Language Pascal" (1973) that many of its constructs were poorly defined, in particular for [[Data type|data types]], [[Range (computer programming)|ranges]], [[Record (computer science)|structures]], and [[goto]].<ref>{{Cite journal |last=Habermann |first=A. N. |date=1973 |title=Critical comments on the programming language Pascal |url=http://dx.doi.org/10.1007/bf00288652 |journal=Acta Informatica |volume=3 |issue=1 |pages=47–57 |doi=10.1007/bf00288652 |issn=0001-5903}} ([https://kilthub.cmu.edu/articles/Critical_comments_on_the_programming_language_PASCAL/6604568/files/12094973.pdf full text of technical report])</ref> Later, [[Brian Kernighan]], who popularized the [[C (programming language)|C language]], outlined his criticisms of Pascal in 1981 in his article "Why Pascal is Not My Favorite Programming Language".<ref>Brian W. Kernighan (1981). [http://www.lysator.liu.se/c/bwk-on-pascal.html "Why Pascal is Not My Favorite Programming Language"]. {{webarchive |url=https://web.archive.org/web/20090428163341/https://www.princeton.edu/~mike/unixhistory |date=2009-04-28}}</ref> The most serious problem Kernighan described was that array sizes and string lengths were part of the type, so it was not possible to write a function that would accept variable-length arrays or even strings as parameters. This made it unfeasible to write, for example, a sorting library. Kernighan also criticized the unpredictable order of evaluation of Boolean expressions, poor library support, and lack of [[static variable]]s, and raised a number of smaller issues. Also, he stated that the language did not provide any simple constructs to "escape" (knowingly and forcibly ignore) restrictions and limitations. More general complaints from other sources<ref name="Hoare.Sneeringer.Welsh.1977"/><ref>
===Rising popularity in the 1970s and 1980s===
In the two decades after 1975, Pascal gained increasing attention and became a major programming language for important platforms (including Apple II, Apple III, Apple Lisa, Commodore systems, Z-80-based machines and IBM PC) due to the availability of UCSD Pascal and Turbo Pascal.<ref>{{cite web |last1=Crespo |first1=Diego |title=Pascal: The language that almost took over the world part 1 |url=https://www.deusinmachina.net/p/pascal-the-language-that-almost-took?utm_source=publication-search |website=www.deusinmachina.net |access-date=4 January 2025 |language=en}}</ref>
Despite initial criticisms, Pascal continued to evolve, and most of Kernighan's points do not apply to versions of the language which were enhanced to be suitable for commercial product development, such as Borland's [[Turbo Pascal]]. As Kernighan predicted in his article, most of the extensions to fix these issues were incompatible from compiler to compiler. Since the early 1990s, however, most of the varieties seem condensed into two categories: ISO and Borland-like. Extended Pascal addresses many of these early criticisms. It supports variable-length strings, variable initialization, separate compilation, short-circuit Boolean operators, and default (<code>otherwise</code>) clauses for case statements.<ref>{{Cite web |url=http://pascal-central.com/ppl/chapter3.html#Extended |title=Extended Pascal |url-status=dead |archive-url=https://web.archive.org/web/20151018023934/http://www.pascal-central.com/ppl/chapter3.html |archive-date=2015-10-18 |access-date=2015-10-17 }}</ref>
Some of the problems arising from the differences in the implementations of Pascal were later partly solved by the advent of Free Pascal, which supports several dialects with mode directives.<ref>{{cite web |last1=Crespo |first1=Diego |title=Pascal: The language that almost took over the world part 2 |url=https://www.deusinmachina.net/p/pascal-the-language-that-almost-took-56a?utm_source=publication-search |website=www.deusinmachina.net |access-date=4 January 2025 |language=en}}</ref>
==Notes==
Line 539 ⟶ 570:
* C. A. R. Hoare: "Notes on data structuring". In O.-J. Dahl, E. W. Dijkstra and C. A. R. Hoare, editors, ''Structured Programming'', pages 83–174. Academic Press, 1972.
* C. A. R. Hoare, Niklaus Wirth: ''An Axiomatic Definition of the Programming Language Pascal''. 335–355, Acta Informatica, Volume 2, 1973.
* Kathleen Jensen and Niklaus Wirth: ''[https://web.archive.org/web/20050314152247/http://www.cs.inf.ethz.ch/~wirth/books/Pascal/ Pascal – User Manual and Report]''. Springer-Verlag, 1974, 1985, 1990, 1991, {{ISBN|0-387-97649-3}} and {{ISBN|3-540-97649-3}}.
* Niklaus Wirth: ''[[Algorithms + Data Structures = Programs]]''. Prentice-Hall, 1975, {{ISBN|0-13-022418-9}}.
* Niklaus Wirth: ''An assessment of the programming language Pascal''. 23–30 ACM SIGPLAN Notices Volume 10, Issue 6, June 1975.
Line 566 ⟶ 597:
<!-- Hidden categories below -->
[[Category:Articles with example Pascal code]]
[[Category:Compiled programming languages]]
|