Specs, patterns, whatever you call them (the official name is specs) are something that baffles people learning about OSPL.
They're a strange system, I know, but this document should clear it up for you!
Sometimes not even Oscar himself understands them (I know... trust me!)
Specs are lists of subspecs, they tell various things how to match patterns and stuff.
The most common place you'll see specs is function arguments, in fact the whole system is built around that.
A list of valid subspecs by internal name is displayed below. Each subspec "takes" one value
Bind(ID)
BindRef(ID)
BindTyped(ID, Type)
Destruct(Spec)
LiteralRequirement(Value)
Ignore
ThisRef(ID)
Bind
simple enough, it binds a name (ID) to a value. It copies the data given. If you don't need a copy of the data, pass in a reference to data or use BindRef if applicable.
written like: ID
BindRef
instead of copying the data given, it creates a reference to it.
The existence of this has created two sides, people who prefer bindref and people who prefer to use bind + passing in refs.
Either way is valid, just communicate with your team about it!
written like: $ID
BindTyped
Same as Bind but enforces the type
written like: ID: Type
BindRefTyped
Same as BindRef but enforces the type
written like: $ID: Type
Destruct
Destructs the data given further
This is the cool part about all this, everything else is boring without this!
written like: (...spec...)
LiteralRequirement
The destruction will fail if the value given does not equal the literal value.
This mostly exists because of check/select statements (yeah those use specs too!)
written like: ANY_LITERAL
Ignore
Does nothing
written like: _
Thisref
Gives a reference to the last thing you preformed a property access on. It's called thisref because typically, the last thing you property accessed is the thing you're calling it on.
The syntax looks quite deciving.
x.y.z.do_thing("hello"); # thisref here is a reference to z
In the interpreter's eyes, the last thing you accessed is z not do_thing for reasons too complicated and uselessly specific to explain here.