User:Leland McInnes/Pseudocode examples

From Wikipedia, the free encyclopedia

The following represent some suggested examples of pseudocode in the style suggested by Wikipedia:WikiProject Computer science/Manual of style (computer science) for various idiomatic constructs. This does not represent an authoritative source, nor rules, nor even guidelines for how to express these constructs in pseudocode on Wikipedia. Rather it offers suggestions for possible methods of expression consistent with the standard style for those who are uncertain as to how to proceed.

  • Datatype declaration
type type_name is description
where "description" is any reasonable description of the type, such as Integer, Non-negative number, Array of graph nodes etc.
  • Algebraic datatype declaration
type color is red | green | blue
  • Typed variable declaration
variable_name : type_name
  • Pattern matched function
function function_name
   | pattern1 is code block
     ...
   | patternn is code block
end function
  • Class declaration
class class_name is

    property property1
    property property2
     ...

    method method1 is
        code block
    end method

    method method2 is
        code block
    end method

     ...

end class
where property and method keywords are any reasonable keyword such as attribute, variable, etc. and operation, procedure, etc.