Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Sleep sort of vectors by length example*/
- //functional programming
- sleepSort([i32] arr) =
- result = []
- threadsArr = map(arr, (elem, index) => (
- sleepFunc =
- sleep(elem)
- printfn("threadsArr[%i32] have slept for %i32", index, elem)
- thread(sleepFunc)
- ))
- runAsyncAndWait(threadsArr)
- result
- //object orientated and generic programming
- type vec3<T : INumeric> =
- record
- T x
- T y
- T z
- vec3<T>(xi, yi, zi) =
- x = xi
- y = yi
- z = zi
- normalize() =
- len = math.sqrt(x*x + y*y + z*z)
- vec3<T>(x/len, y/len, z/len)
- print() =
- printfn("vector: x: %s y: %s z: %s", str(x), str(y), str(z))
- read() =
- //semicolons are compulsory when write code in one line
- xs = ""; ys = ""; zs = "";
- scanf("vector: x: %s y: %s z: %s", xs, ys, zs, () => (print("Scanf error")))
- x = T(xs); y = T(ys); z = T(zs)
- operator implicit int():
- return floor(
- len = f32(math.sqrt(x*x + y*y + z*z))
- len
- )
- main(argc, argv) =
- vectorCount = ""
- scanf("%i32", vectorCount)
- arr = [vec3<T>(0, 0, 0)] * vectorCount
- for vector in arr:
- vector.read()
- for vector in sleepSort(arr):
- vector.print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement