Extended Pascal: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Extended Pascal
| Old | New | Line | |
|---|---|---|---|
| 1 | + | **Extended Pascal** is the name given to the version of Pascal specified in International Organization for Standardization (ISO) standard 10206. It specifies an enhanced version of the [[Standard Pascal]] language that was specified in the ISO 7185 specification. The 214-page ISO 10206 document was published in May 1991 and not been revised since. | |
| 2 | + | ||
| 3 | + | Support in Free Pascal for Extended Pascal is planned, and will be via [[Mode extendedpascal|compiler mode extendedPascal]]. | |
| 4 | + | ||
| 5 | + | ## Enhancements to Standard Pascal | |
| 6 | + | ||
| 7 | + | - Modularity and separate compilation (implemented with new keywords **module**, **import**, **export**, **only**, **qualified** and **protected**). | |
| 8 | + | - Direct access file handing (via **SeekRead**, **SeekWrite**, **SeekUpdate** and **update** procedures, and the **position**, **LastPosition** and **empty** functions as well as an *update file mode*). | |
| 9 | + | - The procedure **extend** prepares an existing file for appending data | |
| 10 | + | - The declaration parts of a program (labels, constants, types, variables, procedures, and functions) can appear in any order | |
| 11 | + | - Complex numbers | |
| 12 | + | ||
| 13 | + | ## Reserved Words | |
| 14 | + | ||
| 15 | + | In addition to all the [[Standard Pascal|reserved words of Standard Pascal]] the following (referred to as *word-symbols* in the ISO 10206 document) have been added to Extended Pascal: | |
| 16 | + | ||
| 17 | + | - and_then (short circuit version of "and"; right side not evaluated if not necessary) | |
| 18 | + | - bindable | |
| 19 | + | - export | |
| 20 | + | - import | |
| 21 | + | - module | |
| 22 | + | - only | |
| 23 | + | - or_else (short circuit version of "or"; right side not evaluated if not necessary) | |
| 24 | + | - otherwise (used with the **case** statement and *variant records*) | |
| 25 | + | - pow (exponentiation for integer, real and complex numbers to real and integer powers) | |
| 26 | + | - protected | |
| 27 | + | - qualified | |
| 28 | + | - restricted | |
| 29 | + | - value | |
| 30 | + | ||
| 31 | + | ## Symbols | |
| 32 | + | ||
| 33 | + | In addition to all the [[Standard Pascal|symbols of Standard Pascal]] the following have been added to Extended Pascal: | |
| 34 | + | ||
| 35 | + | - ** (exponentiation for integer, real and complex numbers to real and integer powers) | |
| 36 | + | - \>\< (computes a set symmetric difference) | |
| 37 | + | - =\> | |
| 38 | + | ||
| 39 | + | ## Free Pascal support for Extended Pascal | |
| 40 | + | ||
| 41 | + | Free Pascal has traditionally only supported the Borland dialects of Pascal, but Extended Pascal support will be available via [[Compiler Mode|compiler mode]] [[Mode extendedpascal|extendedpascal]]. [Bug 0032549](https://bugs.freepascal.org/view.php?id=32549) has been set up to track its progress. Below is a list of things that have been implemented (if only in unapplied patches) and things that are planned. The planned features are subject to change. | |
| 42 | + | ||
| 43 | + | ### Already supported features | |
| 44 | + | ||
| 45 | + | These features are already supported in Free Pascal 3.0 and some earlier versions. | |
| 46 | + | ||
| 47 | + | - The declaration parts of a program (labels, constants, types, variables, procedures, and functions) can appear in any order | |
| 48 | + | - The **ReadStr** and **WriteStr** procedures. | |
| 49 | + | - The **Halt** procedure. | |
| 50 | + | - The **otherwise** clause of case statements. | |
| 51 | + | - The [[for-in loop|for ... in]] loop | |
| 52 | + | - Array and string slices (mostly working, though assigning to them doesn't). | |
| 53 | + | - The * and \>\< operators of sets. | |
| 54 | + | - The ** operator (requires the Math unit) | |
| 55 | + | - Various features from ISO 7185 not supported in the Borland dialects (requires ISO mode) | |
| 56 | + | ||
| 57 | + | ### Conformant arrays (not yet implemented) | |
| 58 | + | ||
| 59 | + | This is the standard way to pass arrays of various sizes to routines. | |
| 60 | + | ||
| 61 | + | ### Set improvements (not yet implemented) | |
| 62 | + | ||
| 63 | + | In addition to the * and \>\< operators, ISO 10206 also has a **Card** function, for retrieving the number of elements in a set. In Free Pascal, sets will still be limited to 256 elements for the foreseeable future (see [Future Plans](https://freepascal.org/future.var)). | |
| 64 | + | ||
| 65 | + | ### Generalized ordinal functions (not yet implemeted) | |
| 66 | + | ||
| 67 | + | - **Succ** and **Pred** can take a second argument, making them essentially equivalent to Borland's **Inc** and **Dec**. | |
| 68 | + | ||
| 69 | + | ### Modules (not yet implemented) | |
| 70 | + | ||
| 71 | + | Modules are the standard way for modular programs, covering the same domain as UCSD units. There are two types of modules: those written in a single file and those written in two files. For modules written in one file, Free Pascal will search for them as it does for units (*modulename*.{p,pp,pas}). Suggestion for those written in two files as this is not provided in the standard: the compiler will search for the implementation file normally and then search for *modulename*.imp.{p,pp,pas}. The interface is in *modulename*.int.{p,pp,pas}, unless otherwise specified by a {\$INTERFACE} directive. | |
| 72 | + | ||
| 73 | + | - The **import** section specifies modules to import (much like UCSD's **uses**) and can be used with the keywords **only** (to only import certain identifiers (functions, procedures, types, variables, constants)), and **qualified** (qualified identifiers; that is, *modulename*.*identifier*, rather than just *identifier*). Identifiers can be renamed on import. An example: | |
| 74 | + | ||
| 75 | + | ``` pascal | |
| 76 | + | program PathTest; | |
| 77 | + | ||
| 78 | + | import | |
| 79 | + | SysUtils qualified only (GetEnvironmentVariable => GetEnv); | |
| 80 | + | ||
| 81 | + | begin | |
| 82 | + | WriteLn(SysUtils.GetEnv('PATH')); | |
| 83 | + | end. | |
| 84 | + | ``` | |
| 85 | + | ||
| 86 | + | - Modules must export identifers for them to be usable to programs or other modules. | |
| 87 | + | - On export, identifers can also be renamed and the **protected** keyword can be specified so that other programs and modules can't change the variable's value. | |
| 88 | + | - In the module, the **restricted** keyword can be used to make opaque types. To use the example given in the standard: | |
| 89 | + | ||
| 90 | + | ``` pascal | |
| 91 | + | type | |
| 92 | + | real_widget = record | |
| 93 | + | f1: integer; | |
| 94 | + | f2: real | |
| 95 | + | end; | |
| 96 | + | widget = restricted real_widget; | |
| 97 | + | ``` | |
| 98 | + | ||
| 99 | + | - The **to begin do** statement specifies what happens when the module loads (equivalent to Delphi's **initialization** section). | |
| 100 | + | - The **to end do** statement specifies what happens when the module unloads (equivalent to Delphi's **finalization** section). The example in the standard uses **to begin do** to bind a text file on module load, writes to the text file during runtime, and then closes the text file in **to end do**. | |
| 101 | + | ||
| 102 | + | Two extensions from [[GNU Pascal]] are also planned: | |
| 103 | + | ||
| 104 | + | - The **all** keyword to export all identifers from a module's interface (specified identifers can be renamed). | |
| 105 | + | - [[PXSC]]-style modules, which are essentially implementation modules without an interface part. (Free Pascal already supports PXSC-style operator overloading, as does GNU Pascal.) | |
| 106 | + | ||
| 107 | + | #### Required interfaces | |
| 108 | + | ||
| 109 | + | The modules **StandardInput** and **StandardOutput** are equivalent to **input** and **output** in a program's header. | |
| 110 | + | ||
| 111 | + | ### Schemata (not yet implemented) | |
| 112 | + | ||
| 113 | + | The standard defines a schema as a collection of similar types. Essentially, though, a schema is a data type that takes one or more arguments (called discriminants). | |
| 114 | + | ||
| 115 | + | - The ISO 10206 string type is a schema type. | |
| 116 | + | - The **New** procedure can be used to set a schema's discriminants at runtime. | |
| 117 | + | - The **New** procedure can also be used to set a variant record's discriminant. | |
| 118 | + | ||
| 119 | + | ### File routines | |
| 120 | + | ||
| 121 | + | - The **bindable** keyword allows the binding of a variable to an external resource (not implemented, and it might stay that way; GNU Pascal also doesn't allow binding non-files) | |
| 122 | + | - Indexed files (not yet implemented) | |
| 123 | + | - The **Bind** procedure to bind a variable to an external resource | |
| 124 | + | - **Unbind** | |
| 125 | + | - **Binding** returns a **BindingType** record, whose Bound field tells if the file was successfully bound | |
| 126 | + | - **Empty** | |
| 127 | + | - **Extend** | |
| 128 | + | - **SeekRead** | |
| 129 | + | - **SeekWrite** | |
| 130 | + | - **SeekUpdate** | |
| 131 | + | - **Update** | |
| 132 | + | - **Position** | |
| 133 | + | - **LastPosition** (currently, it always returns 0, as its functioning requires support of indexed files) | |
| 134 | + | ||
| 135 | + | ### Date/Time | |
| 136 | + | ||
| 137 | + | The **GetTimeStamp** procedure fills a **TimeStamp** record with details about the current time, which can be converted to a human-readable format via the **Date** and **Time** functions. | |
| 138 | + | ||
| 139 | + | ### String functions | |
| 140 | + | ||
| 141 | + | - **Substr**, equivalent to **Copy**. | |
| 142 | + | - **Index**, equivalent to **Pos**. | |
| 143 | + | - **Trim**. | |
| 144 | + | - String comparison through **EQ**, **NE**, **LT**, **GT**, **LE**, and **GE** (equal to, not equal to, less than, greater than, less than or equal to, greater than or equal to). | |
| 145 | + | ||
| 146 | + | ### Complex Numbers | |
| 147 | + | ||
| 148 | + | - There's a **complex** data type. In Free Pascal, it's implemented as a record with two fields, but you shouldn't count on that. Instead use the **Re** and **Im** functions to get the real and imaginary parts, respectively. | |
| 149 | + | - Use **Cmplx** to create a complex number from Cartesian arguments or **Polar** to create one from polar arguments. | |
| 150 | + | - The standard operators and functions (**abs**, **arctan**, **cos**, **exp**, **ln**, **sin**, **sqr**, and **sqrt**) are overloaded to take complex arguments. | |
| 151 | + | - The function **arg** gets the complex number's argument. | |
| 152 | + | ||
| 153 | + | ### Number bases (not yet implemented) | |
| 154 | + | ||
| 155 | + | It's possible to use any number base from 2 to 36. | |
| 156 | + | ||
| 157 | + | ### Exponents | |
| 158 | + | ||
| 159 | + | The ** operator for real exponents has existed in Free Pascal for a while, but the **pow** operator for integer exponents remains unimplemented. | |
| 160 | + | ||
| 161 | + | ### New constants | |
| 162 | + | ||
| 163 | + | - **maxchar** - The highest codepoint supported by a Pascal implementation. | |
| 164 | + | - **minreal** - The minimum real value supported. | |
| 165 | + | - **maxreal** - The maximum real value supported. | |
| 166 | + | - **epsreal** - The precision of reals. | |
| 167 | + | ||
| 168 | + | ### Ensuring the proper order of Boolean expressions (not yet implemented) | |
| 169 | + | ||
| 170 | + | ISO 10206 introduces the **and_then** and **or_else** operators when you need your expression to evaluated left to right. The **and** and **or** operators, on the other hand, can evaluate the Boolean expressions in any order. These new operators are especially useful for pointer operations, where you need to know whether a pointer is assigned before trying to dereference it. | |
| 171 | + | ||
| 172 | + | ### The value keyword (not yet implemented) | |
| 173 | + | ||
| 174 | + | The **value** keyword specifies the default value for a variable, type, parameter, or record field. | |
| 175 | + | ||
| 176 | + | - For variables and default parameters, this is equivalent to the Delphi operator =. | |
| 177 | + | - For record fields and types, there's no direct equivalent in the Borland dialects, but the [[management operators|initialize “management operator”]] could perform the same task. | |
| 178 | + | ||
| 179 | + | Note: Default parameters aren't defined in ISO 10206, but are in Appendix C.4 of the [[Object-Oriented Extensions to Pascal|OOE]] draft. | |
| 180 | + | ||
| 181 | + | ### Function result variables (not yet implemented) | |
| 182 | + | ||
| 183 | + | Allows to bind a function's result to a variable, sort of like Delphi's **Result**. | |
| 184 | + | ||
| 185 | + | ### Protected parameters (not yet implemented) | |
| 186 | + | ||
| 187 | + | The **protected** keyword can also be used with parameters to indicated that they can't be changed in the routine, giving the compiler hints to aid optimization. To use the example given in the standard: | |
| 188 | + | ||
| 189 | + | ``` pascal | |
| 190 | + | procedure illustrate(a: integer; var b: integer; protected c: integer; protected var d: integer); | |
| 191 | + | begin | |
| 192 | + | a := 1; { value param } | |
| 193 | + | b := 1; { variable param } | |
| 194 | + | { c := 1; not legal } | |
| 195 | + | { d := 1; not legal } | |
| 196 | + | end; | |
| 197 | + | ``` | |
| 198 | + | ||
| 199 | + | ### Type inquiry (not yet implemented) | |
| 200 | + | ||
| 201 | + | Allows you to make the type of one variable or parameter the same as another variable or parameter. | |
| 202 | + | ||
| 203 | + | ### Value constructors (not yet implemented) | |
| 204 | + | ||
| 205 | + | This provides a cleaner alternative to Borland's typed constants (which aren't really constants at all) and gives a shortcut to constructing arrays and records at runtime. | |
| 206 | + | ||
| 207 | + | ### Local variables with dynamic size (not yet implemented) | |
| 208 | + | ||
| 209 | + | This should work but doesn't currently: | |
| 210 | + | ||
| 211 | + | ``` pascal | |
| 212 | + | procedure p(n: integer); | |
| 213 | + | var | |
| 214 | + | v: 1..n; | |
| 215 | + | begin | |
| 216 | + | ... | |
| 217 | + | end; | |
| 218 | + | ``` | |
| 219 | + | ||
| 220 | + | ### Acceptable Identifiers (not yet implemented) | |
| 221 | + | ||
| 222 | + | - An underscore (`_`) may neither begin or end an identifier. | |
| 223 | + | - Two underscores may not appear in succession, thus `Foo__bar` (*two* underscores) is illegal. | |
| 224 | + | - Merely all-numeric [[Label|labels]] are allowed and have a maximum length of four digits. | |
| 225 | + | ||
| 226 | + | ## External links | |
| 227 | + | ||
| 228 | + | - [ISO/IEC 10206:1991](http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=18237), [PDF](http://www.pascal-central.com/docs/iso10206.pdf): Extended Pascal standard | |
| 229 | + | ||
| 230 | + | --- | |
| 231 | + | *From the Free Pascal wiki, page "Extended Pascal", as it stood on 2024-02-28 after a change by Alextp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* | |
| 232 | + | Category: Pascal |
