Checking arguments for null in Nemerle

An impossible thing in languages like C# and F#:

public macro not_null(obj)
syntax ("not_null", obj)
{
def var_name = $"$obj";
<[
when ($obj == null)
throw System.ArgumentNullException($var_name);
$obj;
]>
}
class Person
{
public Name: string;
public this(name: string)
{
Name = not_null name;
}
}
// causes ArgumentNullException exception with argument name set to "name"!
def person = Person(null);
view raw gistfile1.n hosted with ❤ by GitHub

Comments

Popular posts from this blog

Regular expressions: Rust vs F# vs Scala

Hash maps: Rust, F#, D, Go, Scala

Haskell: performance