Variable size/Set: Difference between revisions

Added Wren
m (Phix/mpfr)
(Added Wren)
Line 725:
 
1.00000000000000000000000000000000000000000000000000000E0</lang>
 
=={{header|Wren}}==
In Wren, variables are always exactly 8 bytes in size. They either store their value directly (Num, Bool or Null) or a reference (a 64 bit pointer) to where an object is stored in memory.
 
Technically, a variable always contains an 8 byte double precision floating point value but uses a technique known as 'NaN tagging' to store bools, nulls or pointers as well as numbers.
 
So there is no such thing as a minimum size for a variable or scalar type; the size of the former is always 8 bytes and of the latter however many 8 byte values are needed to store its fields.
 
Wren has four built-in collection types: String, Range, Map and List. The size of the first two is determined by their currently assigned value which is immutable but the size of the last two can change dynamically as elements are added or removed.
Of course, a variable which has been assigned values of these types is always exactly 8 bytes in size and holds a reference to where the actual object is stored on the heap,
 
The programmer cannot specify a minimum size for a Map but can specify a minimum size for a List - in effect the amount of heap storage required to store its elements. This can still be increased dynamically by adding futher elements to the List. Here's an example.
<lang ecmascript>// create a list with 10 elements all initialized to zero
var l = List.filled(10, 0)
// give them different values and print them
for (i in 0..9) l[i] = i
System.print(l)
// add another element to the list dynamically and print it again
l.add(10)
System.print(l)</lang>
 
{{out}}
<pre>
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
</pre>
 
=={{header|XPL0}}==
9,490

edits