This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
harlowe:datatype [2019/04/16 04:02] l |
harlowe:datatype [2019/04/16 04:03] l |
||
---|---|---|---|
Line 18: | Line 18: | ||
Note that data that can't be stored in a variable doesn't have a corresponding datatype name, because you won't need to compare things to it. | Note that data that can't be stored in a variable doesn't have a corresponding datatype name, because you won't need to compare things to it. | ||
- | Additionally, along with the `is a` operator, there is a `matches` operator which is useful when you're dealing with data structures like [[harlowe:array|arrays]] or [[harlowe:datamap|datamaps]]. `$pos is a array` checks if $pos is an array, but that may not be precise enough for you. `$pos matches (a: number, number)` checks to see if $pos is an array containing only two numbers in a row. A data structure with datatype names in various positions inside it is called a **pattern**, and `matches` is used to compare data values and patterns. | + | Additionally, along with the ''%%is a%%'' operator, there is a ''%%matches%%'' operator which is useful when you're dealing with data structures like [[harlowe:array|arrays]] or [[harlowe:datamap|datamaps]]. ''%%$pos is a array%%'' checks if $pos is an array, but that may not be precise enough for you. ''%%$pos matches (a: number, number)%%'' checks to see if $pos is an array containing only two numbers in a row. A data structure with datatype names in various positions inside it is called a **pattern**, and ''%%matches%%'' is used to compare data values and patterns. |
Some more pattern-matching examples: | Some more pattern-matching examples: | ||
- | * `(datamap:'a',2,'b',4) matches (datamap:'b',num,'a',num))` is true. | + | * ''%%(datamap:'a',2,'b',4) matches (datamap:'b',num,'a',num))%%'' is true. |
- | * `(a: 2, 3, 4) matches (a: 2, num, num)` is true. (Patterns can have exact values in them, which must be equal in the matching data). | + | * ''%%(a: 2, 3, 4) matches (a: 2, num, num)%%'' is true. (Patterns can have exact values in them, which must be equal in the matching data). |
- | * `(a: (a: 2), (a: 4)) matches (a: (a: num), (a: num))` is true. | + | * ''%%(a: (a: 2), (a: 4)) matches (a: (a: num), (a: num))%%'' is true. |
To summarise, the two datatype-checking operators are: | To summarise, the two datatype-checking operators are: |