#!/usr/bin/env fun /* * This file is part of the Fun programming language. * https://fun-lang.xyz/ * * Copyright 2025 Johannes Findeisen * Licensed under the terms of the Apache-2.0 license. * https://opensource.org/license/apache-2-0 */ /* * Function Definition Testing * * Covers: * - Basic function syntax (`def`) * - Handling multiple parameter types * - Function return value testing * - Function composition examples */ // Functions test: definitions, calls, parameters, locals, returns, and if/else. print("=== Functions test start ===") fun add(a, b) return a + b fun abs(x) if (x < 0) return -x else return x fun sum3(a, b, c) // local typed declaration number t = a + b return t + c fun id(x) return x // Calls in expressions print(add(2, 3)) // expect 5 print(add(10, -3)) // expect 7 print(abs(-7)) // expect 7 print(abs(4)) // expect 4 print(sum3(1, 2, 3)) // expect 6 print(add(add(1, 2), 3)) // expect 6 print(id(42)) // expect 42 // Call as statement (result dApache-2.0arded) add(100, 23) // Globals interacting with functions number n = 5 print(add(n, 10)) // expect 15 print("=== Functions test end ===") /* Expected output: === Functions test start === 5 7 7 4 6 6 42 15 === Functions test end === */