Go! (programming language): Difference between revisions

Content deleted Content added
Reverted to revision 659165662 by Codename Lisa (talk): Need to use syntaxhightlighting or source. (TW)
Example: manual syntax highlighting of operators and primitive datatypes
Line 35:
The following example illustrates the "ontology-oriented" type and declarations style of Go!:<ref name=applied />
 
Gender '''::=''' male | female.
<syntaxhighlight lang="go">
Gender'''::=''' male | female.
person '''<˜''' {dayOfBirth:[] '''=>''' ''day''.
age:[] '''=>''' ''integer''.
gender:[] '''=>''' Gender.
name:[] '''=>''' ''string''.
home:[] '''=>''' ''string''.
lives:[''string'']{}}.
person:[''string'', ''day'', Gender, ''string''] '''$=''' person.
person(Nm, Born, Sx, Hm)..{
dayOfBirth() '''=>''' Born.
age() '''=>''' yearsBetween(now(), Born).
gender() '''=>''' Sx.
name() '''=>''' Nm.
home() '''=>''' Hm.
lives(Pl) ''':-''' Pl '''=''' home().
yearsBetween:[''integer'', ''day''] '''=>''' integer.
yearsBetween(...) '''=>''' ..
}.
newPerson:[''string'', ''day'', Gender, ''string''] '''=>''' person.
newPerson(Nm, Born, Sx, Hm) '''=>''' $person(Nm, Born, Sx, Hm).
</syntaxhighlight>
 
The <code>::=</code> rule defines a new [[algebraic data type]], a [[data type]] with only data constructors.