MoonBit
Created
April 11, 2026 01:40
-
-
Save HiroNakamura/f39cea367fe3f223677f9064800e8f9f to your computer and use it in GitHub Desktop.
Programando en Moon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn main{ | |
| println("\t Condicionales en MoonBit.") | |
| let mut bandera: Bool = 23 > 22 | |
| if bandera{ | |
| println("Fue verdadero.") | |
| bandera = false | |
| } | |
| if bandera{ | |
| println("Esto no se vera en pantalla.") | |
| }else{ | |
| println("Esto si se vera en pantalla.") | |
| } | |
| let resultado = if "A" == "A"{ | |
| "Esto fue verdadero." | |
| }else{ | |
| "Esto fue falso." | |
| } | |
| println(resultado) | |
| println(fibonacci(5)) | |
| } | |
| // Aqui usamos algo similar a switch | |
| fn fibonacci(n : Int) -> Int { | |
| match n { | |
| 0 => 0 | |
| 1 | 2 => 1 | |
| _ => fibonacci(n - 1) + fibonacci(n - 2) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct Persona { | |
| nombre : String | |
| apellidos: String | |
| edad : Int | |
| } | |
| struct Punto{ | |
| x:Int | |
| y:Int | |
| } | |
| fn main{ | |
| println("\t Estructuras en MoonBit.") | |
| let thomas = Persona::{ nombre: "Thomas", apellidos: "Muller", edad: 30 } | |
| let p: Punto = {x: 23, y:43} | |
| println(thomas.nombre) | |
| println(thomas.apellidos) | |
| println(thomas.edad) | |
| println(" --------------- ") | |
| println(p.x) | |
| println(p.y) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn main{ | |
| println("\t Funciones en MoonBit.") | |
| let a: Int = 3 | |
| let b: Int = 2 | |
| println(suma(a, b)) | |
| println(resta(a, b)) | |
| println(producto(a, b)) | |
| println(division(a, b)) | |
| } | |
| fn suma(x: Int, y: Int)-> Int { | |
| x + y | |
| } | |
| fn resta(x: Int, y: Int)-> Int { | |
| x - y | |
| } | |
| fn producto(x: Int, y: Int)-> Int { | |
| x * y | |
| } | |
| fn division(x: Int, y: Int)-> Int { | |
| x / y | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn main { | |
| println("Hola, mundo.") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn main{ | |
| println("\t Sumar los primeros 100 números pares en MoonBit.") | |
| let suma = for i = 1, acc = 0; i <= 100; i = i + 1 { | |
| if i % 2 == 0 { | |
| continue i + 1, acc + i | |
| } | |
| } else { | |
| acc | |
| } | |
| println(suma) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn main{ | |
| let int : Int = 42 | |
| let uint : UInt = 42 | |
| let int64 : Int64 = 42 | |
| let double : Double = 42 | |
| let float : Float = 42 | |
| let bigint : BigInt = 42 | |
| let cadena : String = "FERROCARRIL" | |
| let c : Char = 'A' | |
| let verdadero : Bool = true | |
| println("\t Tipos de datos en MoonBit.") | |
| println(int) | |
| println(uint) | |
| println(int64) | |
| println(double) | |
| println(float) | |
| println(bigint) | |
| println(cadena) | |
| println(c) | |
| println(verdadero) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment