function arguments and consistency

one of oh-lang's primary goals is consistency, although developer ergonomics also plays a role. however, some annoyances from other languages that oh-lang tries to improve upon:

python: assignment (=) and commas have different precedence inside function arguments than outside.
def my_function(a, b):
  a, b = b, a    # this is a swap, equivalent to (a, b) = (b, a)
  print("a = %s, b = %s" % (a, b))

my_function(a=3, b=4)

Rust: declarations look different inside function arguments than outside.
fn my_function(a: f32) -> f32 {
    a * 3.0
}

let a: f32 = 42.0;

this is mostly the let keyword. similarly, class methods introduce some nice syntax for arguments to get a reference to the class instance &self (const reference) and &mut self (mutable reference), but these don't generalize to other arguments. e.g., &mut x: i32 is invalid; x: &mut i32 is required.

in oh-lang, we always declare variables with :,† inside or outside of functions. braces are optional for indents, but recommended for long blocks.
my_function(a: #f32): #f32
     a * 3.0

a: #f32 = 42.0

†: technically, we use : for readonly declarations and ; for writable. this avoids introducing another keyword like mut, but it also gives us the power to make "const template" functions. Rust requires a lot of boilerplate to make const and mutable accessors like fn my_i32(&self) -> &i32 { &self.my_i32 } and fn my_i32_mut(&mut self) -> &mut i32 { &mut self.my_i32 } , which in oh-lang can be written as :;my_i32(): #(i32:;) { m my_i32 }.

Comments