Added user input support and many fixes. (0.16.5)
This commit is contained in:
parent
2b82a01fb5
commit
37abd5d6d3
11 changed files with 216 additions and 15 deletions
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
// Demonstrates local include:
|
||||
// This resolves relative to the current working directory where 'fun' is executed.
|
||||
#include "include_local_util.fun"
|
||||
#include "examples/include_local_util.fun"
|
||||
|
||||
print("== include local demo ==")
|
||||
greet("Fun")
|
||||
|
|
|
|||
47
examples/input_example.fun
Executable file
47
examples/input_example.fun
Executable file
|
|
@ -0,0 +1,47 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://hanez.org/project/fun/
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*
|
||||
* Added: 2025-10-02
|
||||
*/
|
||||
|
||||
/*
|
||||
* Interactive input example using input() and Console wrapper.
|
||||
*/
|
||||
|
||||
#include <io/console.fun>
|
||||
|
||||
print("=== input() builtin ===")
|
||||
name = input("Enter your name: ")
|
||||
print(join(["Hello, ", name, "!"], ""))
|
||||
|
||||
print("=== Console class ===")
|
||||
c = Console()
|
||||
city = c.ask("Your city")
|
||||
print(join(["Nice to meet you from ", city], ""))
|
||||
|
||||
yn = c.ask_yes_no("Do you like Fun?")
|
||||
if yn
|
||||
print("Great! 🎉")
|
||||
else
|
||||
print("Give it a try, it grows on you.")
|
||||
|
||||
/* Input given:
|
||||
Enter your name: Hanez
|
||||
Your city: Universe
|
||||
Do you like Fun? [y/n]: y
|
||||
*/
|
||||
|
||||
/* Expected output:
|
||||
=== input() builtin ===
|
||||
Hello, Hanez!
|
||||
=== Console class ===
|
||||
Nice to meet you from Universe
|
||||
Great! 🎉
|
||||
*/
|
||||
|
|
@ -52,3 +52,39 @@ bytes = [0x48,0x65,0x6c,0x6c,0x6f] // "Hello"
|
|||
b64 = b64_encode_bytes(bytes)
|
||||
print(b64) // "SGVsbG8="
|
||||
print(join(b64_decode_to_bytes(b64), ",")) // "72,101,108,108,111"
|
||||
|
||||
/* Expected output:
|
||||
=== Arrays ===
|
||||
2,2,3
|
||||
4,3,2,2,1
|
||||
3
|
||||
0
|
||||
1,2,3,4
|
||||
1,2,3,4,5
|
||||
=== Strings ===
|
||||
[Hello World]
|
||||
1
|
||||
1
|
||||
a|b|c
|
||||
baNANA
|
||||
fun
|
||||
FUN
|
||||
hahaha
|
||||
=== Math ===
|
||||
5
|
||||
10
|
||||
6
|
||||
42
|
||||
243
|
||||
2
|
||||
9
|
||||
1
|
||||
3
|
||||
=== Range ===
|
||||
0,1,2,3,4
|
||||
3,4,5,6,7
|
||||
10,7,4,1
|
||||
=== Base64 ===
|
||||
SGVsbG8=
|
||||
72,101,108,108,111
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue