olix / Mycel / Go developers
in development

Mycel for Go developers

Plain if/else, nil, // comments and struct will feel at home. Declarations and printing are spelled differently, and each Go spelling that doesn't fit gets an error naming it.

Try Mycel in your browser →

Same

What is the same

if x { } else { }, nil, // comments and the struct Foo { } shape work as in Go. for i in 0..3 { } and for x in items { } cover what for ... range does.

point.myca struct, a range loop and a plain if · open in playground
struct Point {
  let x: Int
  let y: Int
}

p = Point(x: 1, y: 2)
for i in 0..3 {
  print(i)
}
if p.x < p.y {
  print("x is smaller")
}
output
0
1
2
x is smaller
Different

What is different

  • First assignment creates variables (x = 5) or let x = 5 replaces x := 5; a type follows a colon: var x: Int = 1. The decimal type is Float, not float64.
  • fn instead of func; print(x) instead of fmt.Println(x); match x { 1 => ... } instead of switch; x += 1 instead of x++.
  • go f() is spawn f(). defer is replaced by try { } finally { }.
  • A Mycel file is a module, so there is no package line.
  • Structs are immutable value types: their fields are let, and the compiler says so if you write var (shown below). Use a class for mutable state.
structs.mycstruct fields are fixed once set · open in playground
struct Point {
  var x: Int
}
compiler says
error [E0227]: struct field `x` cannot be `var`
  --> structs.myc:2:3
  |
2 |   var x: Int
  |   ^^^^^^^^^^
  why: structs are immutable value types; this keeps copies and equality predictable
  fix: declare it `let x`, or make Point a class if it needs mutable state

1 error, 0 warnings
Habit fix-its

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

habit.myca Go habit gets a fix, not a puzzle · open in playground
fmt.Println("hi")
compiler says
error [E0101]: `fmt.Println` is Go — Mycel writes `print(...)`
  --> habit.myc:1:1
  |
1 | fmt.Println("hi")
  | ^^^
  why: this word comes from another language
  fix: see `mycel help habits`

1 error, 0 warnings
You writeMycel says
if x { } else { }works: the same
nilworks: the same
// commentsworks: the same
struct Foo { }works: the same shape
for i := range / for ... rangeworks: for i in 0..3 { } (and for x in items)
x := 5:= is Go — Mycel writes let x = 5
func f() {}func is Go/Swift — Mycel writes fn f() { ... }
fmt.Println(x)fmt.Println is Go — Mycel writes print(x)
var x inttypes follow a colon: var x: Int = 1
switch x { case 1: }switch — Mycel writes match x { 1 => ... }
x++x++ — Mycel writes x += 1
go f()go is Go — Mycel writes spawn f()
defer f()defer is Go/Swift — put cleanup in try { } finally { }
package mainpackage is Go/Java — a Mycel file is a module; no package line
int / string / float64 / bool typesfloat64 is Go — Mycel's decimal type is Float

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

A compatibility engine so a Mycel program can use Go packages is planned, and the package manager ply already recognises the install flags. The planned flag is --go. 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.