RosettaCodeData/Task/Associative-array-Creation/Lasso/associative-array-creation.lasso

39 lines
841 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
// In Lasso associative arrays are called maps
// Define an empty map
local(mymap = map)
// Define a map with content
local(mymap = map(
2026-04-30 12:34:36 -04:00
'one' = 'Monday',
'2' = 'Tuesday',
3 = 'Wednesday'
2023-07-01 11:58:00 -04:00
))
// add elements to an existing map
#mymap -> insert('fourth' = 'Thursday')
// retrieve a value from a map
#mymap -> find('2') // Tuesday
'<br />'
#mymap -> find(3) // Wednesday, found by the key not the position
'<br />'
// Get all keys from a map
#mymap -> keys // staticarray(2, fourth, one, 3)
'<br />'
// Iterate thru a map and get values
with v in #mymap do {^
2026-04-30 12:34:36 -04:00
#v
'<br />'
2023-07-01 11:58:00 -04:00
^}
// Tuesday<br />Thursday<br />Monday<br />Wednesday<br />
// Perform actions on each value of a map
#mymap -> foreach => {
2026-04-30 12:34:36 -04:00
#1 -> uppercase
#1 -> reverse
2023-07-01 11:58:00 -04:00
}
#mymap // map(2 = YADSEUT, fourth = YADSRUHT, one = YADNOM, 3 = YADSENDEW)