Pure Programmer
Blue Matrix


Cluster Map

Lists

L1

This page is under construction. Please come back later.

Lists1.swift
#!/usr/bin/env swift;
import Foundation
import Utils

// Begin Main
let NUM_SQUARES:Int = 5
var squares:[Int] = []
// Put the squares into the list
for i:Int in 0..<NUM_SQUARES {
	squares.append(i * i)
}
// Print out the squares from the list
for i:Int in 0..<squares.count {
	print(Utils.format("{0:d}^2 = {1:d}", i, squares[i]))
}

print(Utils.listToString(squares))

exit(EXIT_SUCCESS)

Output
$ swiftc Lists1.swift -I . -L . -lUtils error: link command failed with exit code 1 (use -v to see invocation) ld: library not found for -lUtils clang: error: linker command failed with exit code 1 (use -v to see invocation)
Lists2.swift
#!/usr/bin/env swift;
import Foundation
import Utils

// Begin Main
var squares:[Int] = [0, 1, 4, 9, 16, 25]

// Print out the squares from the list
for i:Int in 0..<squares.count {
	print(Utils.format("{0:d}^2 = {1:d}", i, squares[i]))
}

exit(EXIT_SUCCESS)

Output
$ swiftc Lists2.swift -I . -L . -lUtils error: link command failed with exit code 1 (use -v to see invocation) ld: library not found for -lUtils clang: error: linker command failed with exit code 1 (use -v to see invocation)
Lists3.swift
#!/usr/bin/env swift;
import Foundation

// Begin Main
var names:[String] = ["Fred", "Wilma", "Barney", "Betty"]

for name in names {
	print("Hello, " + name + "!")
}

names = ["Harry", "Ron", "Hermione"]
for name in names {
	print("Hello, " + name + "!")
}

exit(EXIT_SUCCESS)

Output
$ swiftc Lists3.swift -I . -L . -lUtils error: link command failed with exit code 1 (use -v to see invocation) ld: library not found for -lUtils clang: error: linker command failed with exit code 1 (use -v to see invocation)
Lists4.swift
#!/usr/bin/env swift;
import Foundation
import Utils

// Begin Main
// Print out the command line arguments
for i:Int in 1...(CommandLine.arguments.count - 1) {
	print(String(i) + ":" + CommandLine.arguments[i])
}

exit(EXIT_SUCCESS)

Output
$ swiftc Lists4.swift -I . -L . -lUtils error: link command failed with exit code 1 (use -v to see invocation) ld: library not found for -lUtils clang: error: linker command failed with exit code 1 (use -v to see invocation) $ swiftc Lists4.swift -I . -L . -lUtils error: link command failed with exit code 1 (use -v to see invocation) ld: library not found for -lUtils clang: error: linker command failed with exit code 1 (use -v to see invocation)
Lists5.swift
#!/usr/bin/env swift;
import Foundation
import Utils

// Begin Main
var names:[String] = ["Fred", "Wilma", "Barney", "Betty"]

// Print out the name based on command line argument 1-4
for i:Int in 1...(CommandLine.arguments.count - 1) {
	let x:Int = Int(CommandLine.arguments[i]) ?? 0
	print(String(i) + ":" + names[x - 1])
}

exit(EXIT_SUCCESS)

Output
$ swiftc Lists5.swift -I . -L . -lUtils error: link command failed with exit code 1 (use -v to see invocation) ld: library not found for -lUtils clang: error: linker command failed with exit code 1 (use -v to see invocation) $ swiftc Lists5.swift -I . -L . -lUtils error: link command failed with exit code 1 (use -v to see invocation) ld: library not found for -lUtils clang: error: linker command failed with exit code 1 (use -v to see invocation) $ swiftc Lists5.swift -I . -L . -lUtils error: link command failed with exit code 1 (use -v to see invocation) ld: library not found for -lUtils clang: error: linker command failed with exit code 1 (use -v to see invocation)

Questions

Projects

More ★'s indicate higher difficulty level.

References