The io module provides basic input/output functionality for printing to stdout and reading from stdin.
import "conjure/io"Functions
println
Prints a string to stdout followed by a newline.
io.println("Hello, World!")
var name = "Conjure"
io.println("Welcome to #{name}!")Signature:
func println(s string)Prints a string to stdout without a trailing newline. Use this when you want to output multiple values on the same line.
io.print("Loading")
io.print("...")
io.println(" done!")
// Output: Loading... done!Signature:
func print(s string)readLine
Reads a line from stdin (blocking). Returns the line without the trailing newline character. Returns an empty string on EOF or error.
io.print("Enter your name: ")
var name = io.readLine()
io.println("Hello, #{name}!")Signature:
func readLine() stringString Interpolation
The io module works seamlessly with Conjure’s string interpolation. Use #{} to embed expressions directly in strings.
var x = 42
var y = 3.14
io.println("Integer: #{x}")
io.println("Float: #{y}")
io.println("Expression: #{x * 2}")Example: Simple Calculator
import "conjure/io"
func main() {
io.println("Simple Calculator")
io.println("-----------------")
io.print("Enter first number: ")
var a = i32(io.readLine())
io.print("Enter second number: ")
var b = i32(io.readLine())
io.println("#{a} + #{b} = #{a + b}")
io.println("#{a} - #{b} = #{a - b}")
io.println("#{a} * #{b} = #{a * b}")
io.println("#{a} / #{b} = #{a / b}")
}