A Programming Language with Extended Static Checking
Whiley provides anonymous tuples, similar to those found in [[Python]]. The following example illustrates:
define Square as { int lx, int by, int rx, int ty}
(int,int) dimensions(Square sq):
return (sq.rx - sq.lx, sq.ty - sq.by)
void ::main(System.Console console):
Square sq1 = {lx: 1, by: 1, rx: 10, ty: 12}
(w,h) = dimensions(sq1)
...
Here, we see an anoymous tuple being used to return multiple values from the dimensions() function. As in Python, we can use tuple assignment to declare variables and assign to them. In other words, after the assignment to (w,h) variables w and h have type int and are available for use.
dimensions()
(w,h)
w
h
int
Copyright © 2017 David J. Pearce - All Rights ReservedPowered by WordPress & the Atahualpa Theme by BytesForAll. Discuss on our WP Forum
50 queries. 0.416 seconds.