Skip to content

Instantly share code, notes, and snippets.

@MarkCLewis
Last active December 18, 2021 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarkCLewis/c90da4a0baa5ecedd4f449634a5be7e1 to your computer and use it in GitHub Desktop.
Save MarkCLewis/c90da4a0baa5ecedd4f449634a5be7e1 to your computer and use it in GitHub Desktop.
File Reading Comparison (dnamic vs. static)
def readData(filename):
f = open(filename, 'r')
v1 = int(f.readline())
v2 = f.readline()
v3 = f.readline()
f.close()
return (v1, v2, v3)
def mult(x, y):
print(x, y) # Added for debugging
return x * y
def useData(x, y, desc):
# Imagine this has more too it
print(f'{mult(x, y)} {desc}')
(x, y, desc) = readData('data.txt')
useData(x, y, desc)
def readData(filename: String): (Int, Int, String) =
val f = io.Source.fromFile(filename)
val lines = f.getLines
val v1 = lines.next().toInt
val v2 = lines.next()
val v3 = lines.next()
f.close()
(v1, v2, v3)
def mult(x: Int, y: Int): Int = x * y
def useData(x: Int, y: Int, desc: String) =
// Imagine this has more too it
println(s"${mult(x, y)} $desc")
@main def start =
val (x, y, desc) = readData("data.txt")
useData(x, y, desc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment