olix / Mycel / Rust developers
in development

Mycel for Rust developers

fn, immutable let, enum with payloads, match, and Result with ? are all here. Mycel is a much smaller language than Rust, and each Rust spelling that differs gets an error that names it.

Try Mycel in your browser →

Same

What is the same

fn f(x: Int) -> Int { }, let (immutable by default), match, enum and struct, Result and ?, if let x = y { }, and for i in 0..n all have the same shape.

quarter.mycResult and ? work like you expect · open in playground
fn half(n: Int) -> Result<Int, String> {
  if n % 2 != 0 { return Err(f"{n} is odd") }
  return Ok(n.div(2))
}

fn quarter(n: Int) -> Result<Int, String> {
  let h = half(n)?
  return half(h)
}

print(quarter(8))
print(quarter(6))
output
Ok(2)
Err("3 is odd")
Different

What is different

  • var count = 0 replaces let mut count = 0; x = 1 creates a local variable without let where natural.
  • print(x) replaces println!("{}", x), and f-strings interpolate: f"a {x}".
  • A missing value is nil with an optional type like Int?, and if let x = y { } unwraps it.
  • Whole numbers are Int and decimals are Float: no i32, u64, f64 or usize. Numbers mix like Python: 7 / 2 is 3.5, whole-number division is 7.div(2).
  • Methods go inside the class, or in extend Foo { ... }, not impl Foo { }. Paths use . rather than ::.
  • [1, 2] replaces vec![1, 2]; while true { } replaces loop { }; text is String without lifetimes or borrow checker ceremony.
habit_two.myctwo Rust habits in two lines; the first is reported · open in playground
let mut count = 0
println!("{}", count)
compiler says
error [E0101]: `let mut` is Rust — Mycel writes `var`
  --> habit_two.myc:1:5
  |
1 | let mut count = 0
  |     ^^^
  why: `let` is fixed once set; `var` can change
  fix: write `var count = ...`

1 error, 0 warnings
Habit fix-its

Every Rust habit and what Mycel says

Mycel's compiler recognises words and symbols from other languages. Instead of a generic syntax error you get the language it came from and the Mycel spelling. The full list for Rust is below; rows marked works are valid Mycel as you already write them.

You writeMycel says
fn f(x: Int) -> Int { }works: the same shape
let x = 5 (immutable by default)works: the same
match x { A => .. }works: the same
enum and structworks: the same
Result and ?works: the same
for i in 0..nworks: the same
if let Some(x) = yworks: if let x = y { }
let mut x = 5let mut` is Rust — Mycel writes `var x = 5`
println!("{}", x)println! is Rust — Mycel writes print(x)
NoneNone is Python/Rust — Mycel writes nil
i32 / u64 / f64 / usizei32 is Rust — Mycel's whole-number type is Int
impl Foo { }impl is Rust — Mycel puts methods inside the class, or extend Foo { ... }
vec![1, 2]vec! is Rust — Mycel writes [1, 2]
Type::method:: is Rust — Mycel writes .
loop { }loop is Rust — Mycel writes while true { ... }
let x: &strno references: Mycel's text type is String

Every row is tested in the compiler, and mycel help habits prints the same list. See also the overview on the Mycel page.

Packages

Using Rust packages: planned (coming in Phase D)

A compatibility engine so a Mycel program can use Rust packages is planned, and the package manager ply already recognises the install flags. The planned flag is --cargo (or --rust). Installing packages from other languages is marked as coming until Phase B lands, and Mycel itself is not released: there is nothing to download yet. The playground runs the real compiler in your browser with no packages.

Try it

Run the first example yourself

The Mycel playground opens in your browser. It runs the real compiler in a sandbox with no file, network or storage access, and nothing is sent to a server. For a guided walk through the language, read Learn Mycel.

More

Other starting points

Mycel is written so a program reads the same whichever language you learned first. Pick the guide closest to yours, or take the full tour.