User Tools

Site Tools


harlowe:datatype

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
harlowe:datatype [2019/04/16 04:02]
l created
harlowe:datatype [2019/04/16 04:03]
l
Line 5: Line 5:
 All of the datatypes are as follows. All of the datatypes are as follows.
  
-| Value | Data type| +**Value** **Data type**|
-|---+
 | ''​%%number%%'',​ ''​%%num%%''​ | [[harlowe:​number|Numbers]]| | ''​%%number%%'',​ ''​%%num%%''​ | [[harlowe:​number|Numbers]]|
 | ''​%%string%%'',​ ''​%%str%%''​ | [[harlowe:​string|Strings]]| | ''​%%string%%'',​ ''​%%str%%''​ | [[harlowe:​string|Strings]]|
Line 19: 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 aoperator, there is a `matchesoperator which is useful when you're dealing with data structures like [[harlowe:​array|arrays]] or [[harlowe:​datamap|datamaps]]. ​`$pos is a arraychecks 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 `matchesis 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:
  
-| Operator | Purpose | Example| +|**Operator** **Purpose** **Example**|
-|---+
 | ''​%%matches%%''​ | Evaluates to [[harlowe:​boolean|boolean]] true if the data on the left matches the pattern on the right. | ''​%%(a:​2,​3) matches (a: num, num)%%''​| | ''​%%matches%%''​ | Evaluates to [[harlowe:​boolean|boolean]] true if the data on the left matches the pattern on the right. | ''​%%(a:​2,​3) matches (a: num, num)%%''​|
 | ''​%%is a%%'',​ ''​%%is an%%''​ | Similar to matches, but requires the right side to be just a type name. | ''​%%(a:​2,​3) is an array%%'',​ ''​%%4.1 is a number%%''​| | ''​%%is a%%'',​ ''​%%is an%%''​ | Similar to matches, but requires the right side to be just a type name. | ''​%%(a:​2,​3) is an array%%'',​ ''​%%4.1 is a number%%''​|
harlowe/datatype.txt · Last modified: 2019/04/16 04:03 by l