Maps

< Types & Converters Operators >

How can I instantiate a map?

terp supports maps as literals. Map literals have the same syntax as list literals (elements surrounded by curly braces), but in the map case the elements are name-value pairs. Name-value pairs are a label followed by a colon followed by the value. An example illustrates this most easily:

C:\terp\bin>terp -e "{name:'Alex', date:now, value:3.4}"
Mon May 23 14:35:32 EDT 2016Alex3.4

The string representation is a concatenation of the element values. As the iteration order in maps is relatively unpredictable, this string representation is only of limited practical use.

Maps are very useful to hold settings or properties that need to be referenced by name. In the following examples we will assume that the map used in the example above has been bound to the variable named m, for example by invoking terp with the -Em={name:"Alex", date:now, value:3.4} option.

C:\terp\bin>terp -e m.name
Alex
C:\terp\bin>terp -e m.value+3
6.4

 


Copyright 2006-2016 by Codemesh, Inc., ALL RIGHTS RESERVED

:
terp expressions
codemesh.com home expressions templates ant about us contact us download   

Commandline