-
Notifications
You must be signed in to change notification settings - Fork 8
Tuples
Abe Pralle edited this page Sep 7, 2022
·
3 revisions
# Anonymous tuple with Int32 and String values
local ranking = (1,"first")
println ranking._1 # 1
println ranking._2 # first
# Named tuple
local other_ranking = (rank:2,name:"second")
println other_ranking.rank # 2
println other_ranking.name # second
# Rogue automatically converts between tuple types as long as
# the element count and element types match.
other_ranking = ranking
println other_ranking.rank # 1
println other_ranking.name # first
# A tuple type can be specified by grouping types rather than values
routine print_ranking( r:(rank:Int32,name:String) )
# 'r' could also be anonymous type (Int32,String)
println "$/$"(r.rank,r.name)
endRoutine
print_ranking( ranking ) # 1/first
# Declare locals with a destructuring assignment from a tuple
local (r,name) = ranking
println "$/$"(r,name) # 1/first
# Destructuring assignment into existing variables
(r,name) = other_ranking