 convert/record - Maple Programming Help

Home : Support : Online Help : Programming : Data Types : Conversion : convert/record

convert/record

convert an expression to a record

 Calling Sequence convert( e, 'record' ) convert( e, 'record'['packed'],  'deep' )

Parameters

 e - expression

Description

 • The calling sequence convert( e, 'record' ) converts the expression e to a record.
 • The input expression e must be a module without local variables, a list of equations whose left-hand sides are symbols, or a table all of whose indices are symbols. No other expression may be converted to a record.
 • The calling sequence convert( e, 'record', 'deep' ) converts the table e to a record and any entries of e that are tables are also converted to records recursively. The deep option works only for tables.
 Note: If the input expression e is a record, then it is returned unchanged.
 • If the input expression e is a module, then it must not have non-exported local variables to be converted to a record. The resulting record has the names of the module exports as slot names, and their assigned values (if any) as the corresponding slot values.
 • A list of equations of the form $[{\mathrm{name}}_{1}={\mathrm{value}}_{1},{\mathrm{name}}_{2}={\mathrm{value}}_{2},...,{\mathrm{name}}_{k}={\mathrm{value}}_{k}]$ may be converted to a record. Each left-hand side ${\mathrm{name}}_{i}$ must be a symbol. In this case, the resulting record is precisely the one that would be obtained by calling the Record constructor with the given equations as arguments.
 • If the input expression e is a table, then every one among its indices must be a symbol. The resulting record has the table indices as slot names, and the corresponding tabular values as the record slot values.
 • In any calling sequence, you can optionally use 'record'['packed'] in place of 'record' to specify that the output will be a packed Record.

Examples

 > $r≔\mathrm{Record}\left(a=1,b=2\right)$
 ${r}{≔}{\mathrm{Record}}{}\left({a}{=}{1}{,}{b}{=}{2}\right)$ (1)
 > $\mathrm{type}\left(r,'\mathrm{record}'\right)$
 ${\mathrm{true}}$ (2)
 > $\mathrm{convert}\left(r,'\mathrm{record}'\right)$
 ${\mathrm{Record}}{}\left({a}{=}{1}{,}{b}{=}{2}\right)$ (3)
 > $m≔\mathbf{module}\left(\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{_export}\left(a,b\right);\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}a≔1;\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}b≔2\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{end module}:$
 > $\mathrm{convert}\left(m,'\mathrm{record}'\right)$
 ${\mathrm{Record}}{}\left({a}{=}{1}{,}{b}{=}{2}\right)$ (4)
 > $m≔\mathbf{module}\left(\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{_export}\left(a,b\right);\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{_local}\left(u\right);\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}a≔1;\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}b≔2;\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}u≔3\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{end module}:$

Attempting to convert a module with a local variable to a record results in an error.

 > $\mathrm{convert}\left(m,'\mathrm{record}'\right)$
 > $\mathrm{convert}\left(\left[a=1,b=2\right],'\mathrm{record}'\right)$
 ${\mathrm{Record}}{}\left({a}{=}{1}{,}{b}{=}{2}\right)$ (5)
 > $\mathrm{convert}\left(\mathrm{table}\left(\left[a=1,b=2\right]\right),'\mathrm{record}'\right)$
 ${\mathrm{Record}}{}\left({b}{=}{2}{,}{a}{=}{1}\right)$ (6)
 > $\mathrm{convert}\left(\mathrm{table}\left(\left[a=1,b=2\right]\right),'\mathrm{record}'\left['\mathrm{packed}'\right]\right)$
 ${{\mathrm{Record}}}_{{\mathrm{packed}}}{}\left({b}{=}{2}{,}{a}{=}{1}\right)$ (7)
 > $\mathrm{convert}\left(\mathrm{table}\left(\left[a=1,b=\mathrm{table}\left(\left[d=3,e=\mathrm{table}\left(\left[f=5\right]\right)\right]\right)\right]\right),'\mathrm{record}'\right)$
 ${\mathrm{Record}}{}\left({b}{=}{table}{}\left(\left[{e}{=}{table}{}\left(\left[{f}{=}{5}\right]\right){,}{d}{=}{3}\right]\right){,}{a}{=}{1}\right)$ (8)

Compatibility

 • The convert/record command was updated in Maple 2020.
 • The deep option was introduced in Maple 2020.