Jump to content

Reflection/List properties: Difference between revisions

m
(→‎{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details)
Line 7:
 
=={{header|Fortran}}==
Fortran offers services somewhat as desired, at two levels. Suppose <code>X</code> is the name of some variable. Then, <code>WRITE (6,*) X</code> would send to file unit six (the modern default unit number for "standard output"), the value of <code>X</code>, whatever its type - be it an array, a complex number, an integer, a character variable, or, (with F90 and later) an aggregate or "structure", all with appropriate formats for each part, single or double precision, ''etc''. This is the "free-format" or "list-directed" style, signified by the asterisk in place of a format code or the label of a FORMAT statement. With arrays, repeated values are shown with a repetition count, as in 66*303 meaning sixty-six values of 303. Alas, the @ symbol is not used. Thus, inspection of the style of such output will reveal whether <code>X</code> was an integer, ''etc''.
 
The second level requires slightly more effort: a declaration such as <code>NAMELIST /STUFF/ X</code> enables the use of a statement such as <code>WRITE (6,STUFF)</code> whereupon each item's value will be prefixed with its name in the style of an assignment statement, as in <code>X = 2.7182818</code> if <code>X</code> were to be the name of a simple floating-point variable.
1,220

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.