enso.nim: Next time don't get confused

This commit is contained in:
buckwheat
2025-12-26 17:36:30 -08:00
parent f3bdece63b
commit 996c115a1c
2 changed files with 23 additions and 24 deletions

View File

@ -1,5 +1,5 @@
import enso
import std/[strformat, sugar]
import std/[os, strformat, sugar]
proc unsafe_void(str: string) =
echo str
@ -8,7 +8,12 @@ proc unsafe_int(str: string): int =
echo str
result = 1
func add_two(x: int): int = x + 2
func check_file(name: string): IO[string] =
proc(): string =
if fileExists(name):
result = readFile(name)
else:
result = "Not found"
func main() =
run strput("Hello from Enso!")
@ -20,15 +25,20 @@ func main() =
out_void()
run strput(fmt"{out_int()}")
let get_filename: IO[string] =
proc(): string =
let name: IO[string] = readstr(STDIN)
echo "Enter the file name:"
name()
let
num_list: IO[seq[int]] = to_IO @[1, 2, 3, 4, 5]
list_added: IO[seq[int]] = num_list.map(add_two)
nested: IO[IO[string]] = get_filename.map(check_file)
joined: IO[string] = nested.join
run strput(fmt"{list_added()}")
run strput(joined())
run strput("Enter a string")
let read: IO[string] = readstr(STDIN)
run strput(read())
let flat: IO[string] = get_filename.flatmap(check_file)
run strput(flat())
when isMainModule:
main()