1.0.0.1+9.3.0.2

7.4 Defining Annotations🔗ℹ

The annot form defines a new annotation in terms of existing annotations.

annot EvenInt = Int && satisfying(fun (x): x mod 2 == 0)

> 10 :: EvenInt

10

> 9 :: EvenInt

::: value does not satisfy annotation

  value: 9

  annotation: EvenInt

The annot.macro form from rhombus/meta also defines an annotation, but as a macro, in which case it can have argument forms or other syntactic variations. (See Binding and Annotation Macros for more information.) The annot form can only bind an identifier as a shorthand for another annotation, but that other annotation is parsed eagerly and centralizes run-time support for the annotation. Also, annot is provided by rhombus, so rhombus/meta does not need to be imported to use it. Prefer annot to annot.macro.