Anonymous user
First-class functions/Use numbers analogously: Difference between revisions
First-class functions/Use numbers analogously (view source)
Revision as of 08:30, 22 May 2010
, 14 years ago→[[First-class_functions/Use_numbers_analogously#ALGOL 68]]: add multiplier
(→[[First-class_functions/Use_numbers_analogously#ALGOL 68]]: add multiplier) |
|||
Line 23:
=={{header|ALGOL 68}}==
{{trans|python}}{{wont work with|ALGOL 68|Revision 1 - scoping rules forbid exporting a procedure out of it's scope}}▼
▲{{wont work with|ALGOL 68|Revision 1 - scoping rules forbid exporting a procedure out of it's scope}}
{{wont work with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny] - scoping rules forbid exporting a procedure out of it's scope - detected at compile time and again at runtime}}
{{works with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d]}}
Note: Standard ALGOL 68's scoping rules forbids exporting a '''procedure''' (or '''format''') out of it's scope (closure). Hence this specimen will run on [[ELLA ALGOL 68]], but is non-standard. For a discussion of first-class functions in ALGOL 68 consult [http://www.cs.ru.nl/~kees/home/papers/psi96.pdf "The Making of Algol 68"] - [http://en.wikipedia.o.rg/wiki/Cornelis_H.A._Koster C.H.A. Koster] (1993). <!-- Retrieved April 28, 2007 -->
<lang algol68>REAL
PROC multiplier = (REAL n1, n2)F: ((REAL m)REAL: n1 * n2 * m);
# Numbers as members of collections #
▲x := REAL: 2;
[]REAL num list = (x, y, z),
▲xi := REAL: 0.5;
inv num list = (xi, yi, zi);
▲y := REAL: 4;
▲yi := REAL: 0.25;
▲z := REAL: x + y;
▲zi := REAL: 1 / ( x + y );
# Apply numbers from list #
FOR key TO UPB num list DO
REAL n = num list[key],
inv n = inv num list[key];
▲))</lang>
Output:
<pre>
+.500000000000000e +0
+.500000000000000e +0
</pre>
|