##- # Author: Brian Tiffin # Dedicated to the public domain # # Date: September 2016 # Modified: 2016-11-23/20:30-0500 ##+ # # list-operations.icn, some simple List examples # link fullimag procedure main() local L1, L2 # L1 is 5 elements of 0 L1 := list(5, 0) L2 := ["a", "b", "c", "c", 1, 1.0, ["sublist"]] # lists are ordered, mutable structures write(fullimage(L1), " size of L1: ", *L1) write(fullimage(L2), " size of L2: ", *L2) # Indexing write("\nL2[3]: ", L2[3]) write("L2[1:3]: ", fullimage(L2[1:3])) # Concatenation write("\nL1 ||| L2") write(fullimage(L1 ||| L2)) # Membership if member(L1 ||| L2, "d") then write("\nd is in the list") # Insertion write("\nInsertion") write(fullimage(insert(L2, 1, "first"))) # List comprehensions write("\nComprehension with [: 1 to 10 :]") write(fullimage([: 1 to 10 :])) write("Comprehension with [: 1 to (1 to 5) :]") write(fullimage([: 1 to (1 to 5) :])) end