[fpc-pascal] array & record output/input
Vannus
vannus at gmail.com
Wed Jun 2 14:56:29 CEST 2010
On 2 June 2010 11:34, spir <denis.spir at gmail.com> wrote:
> Hello,
>
>
> Is there a (builtin, simple) way to output the content of an array or of a
> record. Something like arrayToStr / recordToStr, that would return a normal
> form similar to the literal notation used for intialisation? If no, is there
> a way to write custom funcs for this purpose (meaning access at runtime to
> types of items/fields). I constantly need such a feature.
> writeln(recordTostr(aPosition)) // --> (x:1 ; y:2 ; z:3)
> writeln(arrayTostr(someInts)) // --> (9, 8, 7)
> (Additionally, once we have this, a "view" func could call the appropriate
> *ToStr according to actual type, and a "show" procedure could use writeln on
> the result of view... then I'm happy :-)
>
ooh. php has 'print_r' for printing arrays/objects - an equivalent
ArrayToStr would be handy to have in Pascal. while pascal is my favourite
language, I'm finding it poorly supported compared with php :(
> Side-question, upon the opposite point, just to be really sure: array &
> record literal notations can only be used in declaration (var/const),
> meaning for initialisation. But cannot be used to assign a var in a
> statement block. Correct? If yes, what is the issue (for the
> parser/compiler/runtime)?
>
>
> Denis
>
- V
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20100602/b8be5eba/attachment.html>
More information about the fpc-pascal
mailing list