Recherche Google
OpenMusic 6 – User ManualVisual Programming > Boxes and Patch Components > Function Boxes > Methods
previous pagenext page

Methods

In theory, standard Lisp functions are not typed explicitly : their arguments are not predefined, and they are supposed to accept any type of argument. However, internal errors may still occur if the input data is not of the expected type.

On the contrary, most OM functions actually refer to what is known as generic functions1. In CLOS2, a generic function is a kind of "meta" function that applies to several distinct types of arguments3 via several methods4. Each method is specialized to adapt the behaviour of the function – the way it operates – to the type of argument it is assigned. Hence, the input data is "filtered" before computation starts and the relevant method is applied to it.

For instance, a generic function "add" could be considered a set of two different methods.

  • The first method can add a number with another.
  • The second method can add a number to a list of numbers.

Generic Function Editor

The OM+ generic function comprises four internal methods. The accepted types of arguments for this function are: list+list, list+number, number+list and number+number.
The OM+ generic function comprises four internal methods. The accepted types of arguments for this function are: list+list, list+number, number+list and number+number.

Double click on the icon of a function to open the generic function editor.

This window provides :

  • the list of methods which compose a generic function,
  • information about the arguments accept by the method.

The universal type, which means "any type", or "T" for "true" in Lisp is represented by this icon : . This means that the method accepts any type of argument.

For a Review of the Symbols Found in Function Editors :
Adding Methods to a Generic Function

The applications of a generic function can be extended by user-defined methods , so that it can accept new types of input arguments.

Adding Methods to a Function

Calling Methods

In a patch, "calling" – using – a generic function with the wrong types of arguments, triggers an error message of the type : "No method is defined for this type of box ...".

For instance, this can occur if a function is connected to a data type it cannot accept.

Example : Calling OM+ with a Chord and a Number

Here is a widespread error when using object boxes :

In this case, we want to transpose a chord. To execute an operation, a function must apply to the right argument : the relevant output must be connected to the function.

No method is defined, for, as seen previously, the chord + number method is not part of the om+ generic function.

The wrong output, "self" is connected to om+ . The "pitch" output should be connected to it.

Object Box Inputs and Outputs

Compiled Functions and Methods

The "compiled function" or "compiled method" messages appear when clicking on a Lisp function box or in a method icon within a generic function editor. This means the function is protected. It is internally defined in OM and cannot be modified through the graphic interface.

However, user-defined methods can be open in method editors.

Lisp functions cannot be open in the OM graphic interface.
Lisp functions cannot be open in the OM graphic interface.
Creating Generic Functions and Methods
  1. Generic Function

    In object oriented programming, a generic function is a collection of methods – elementary specialized functions – with the same name and argument structure, but with arguments typed differently.

    See also : Method

  2. CLOS – Common Lisp Object System –

    CLOS is an object-oriented programming protocol defined in the Common Lisp language specification. It is based on classes, instances of classes, generic functions and methods to be used in Lisp programs.

    See also : Class, Function, Generic Function, Method, Instance.

  3. Argument

    An argument represents a parameter upon which a function operates. For instance, the (om+ x y) function has two arguments : x and y.

  4. Method

    An elementary function or part of a generic function defining rules for its behaviour depending on a type of argument. Defining a generic function amounts to defining at least one method.

    For instance, the OM+ function is made of four methods : 1. number + list / 2. list + number / 3. number + number / 4. list + list

previous pagenext page
About...(c) Ircam - Centre PompidouMade with Scenari