olix / Mycel / Java developers
in development

Mycel for Java developers

Classes, interfaces, if/while and try/catch look the way you expect, without the ceremony around them. No public static void main, no new, no semicolons required.

Try Mycel in your browser →

Same

What is the same

A class Foo { } has the same shape. if (x) { } else { } works, and the parentheses are optional. while (x) { }, && || ! and try { } catch e { } all work.

Counter.myca class and a while loop, no main method · open in playground
class Counter {
  var count = 0
  fn bump() -> Int {
    self.count += 1
    return self.count
  }
}

c = Counter()
while c.bump() < 3 {
  print("looping")
}
print(f"count is {c.count}")
output
looping
looping
count is 3
Different

What is different

  • No boilerplate: write statements directly at the top level, or define fn main() { ... }.
  • First assignment creates variables (x = 5); types follow the name: let x: Int = 5, or inferred let x = 5. Decimals are Float, not double.
  • System.out.println(x) is print(x); null is nil; no new: write Foo().
  • Methods are fn f() { ... }; there is no void keyword, and return types are inferred when omitted.
  • for (int i = 0; ...; i++) becomes for i in 0..3 { ... } and i++ becomes i += 1.
  • Inheritance is class B: A { ... }, not extends / implements. public is spelled pub.
  • A value that may be missing is typed Int? and the compiler makes you handle it before use.
find.mycan Int? instead of a null you might forget about · open in playground
fn find(names: [String], wanted: String) -> Int? {
  for i, n in names {
    if n == wanted { return i }
  }
  return nil
}

names = ["ana", "bo", "chen"]
print(find(names, "bo"))
print(find(names, "zed"))
output
1
nil
Habit fix-its

Every Java 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 Java is below; rows marked works are valid Mycel as you already write them.

habit.myca Java habit gets a fix, not a puzzle · open in playground
public static void main(String[] args) {
  System.out.println("hi")
}
compiler says
error [E0101]: `public` is Java — Mycel writes `pub` (and no `static void main` is needed: just write statements)
  --> habit.myc:1:1
  |
1 | public static void main(String[] args) {
  | ^^^^^^
  why: this word comes from another language
  fix: see `mycel help habits`

1 error, 0 warnings
You writeMycel says
System.out.println(x)System.out.println is Java — Mycel writes print(x)
public static void mainno boilerplate: write statements directly, or fn main() { ... }
int x = 5;types follow the name: let x: Int = 5 (or just let x = 5)
String / double / boolean as typesdouble is Java — Mycel's decimal type is Float
new Foo()new is JavaScript/Java — Mycel writes Foo()
void f()void is Java — Mycel writes fn f() { ... } (no return type needed)
nullnull is JavaScript/Java — Mycel writes nil
i++x++ — Mycel writes x += 1
for (int i = 0; ...; i++)Mycel writes for i in 0..3 { ... }
extends / implementsextends is Java — Mycel writes class B: A { ... }
class Foo { }works: the same shape
if (x) { } else { }works: the same (parentheses are optional)
&& || !works: the same
while (x) { }works: the same
try { } catch (e) { }works: catch e { ... }

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 Java packages: planned (coming in Phase C)

A compatibility engine so a Mycel program can use Java packages is planned, and the package manager ply already recognises the install flags. The planned form is ply install --java com.google.code.gson:gson:2.11.0. 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.