user_guide:extend:polymorphic

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revisionBoth sides next revision
reference:polymorphic [2018/09/08 22:26] – [Labels] gawrilowuser_guide:extend:polymorphic [2019/01/25 16:02] – ↷ Page moved from reference:polymorphic to user_guide:extend:polymorphic oroehrig
Line 1: Line 1:
 ====== Polymorphic Functions ====== ====== Polymorphic Functions ======
  
-In the rulefiles you can define polymorphic functions and methods resembling, to some extent, the features of programming languages C++ or Java.  The general syntax is described [[rulefiles#functions|among other rulefile elements]], here we discuss the definition and overload resolution in deeper details.+In the rulefiles you can define polymorphic functions and methods resembling, to some extent, the features of programming languages C++ or Java.  The general syntax is described [[reference:rulefiles#functions|among other rulefile elements]], here we discuss the definition and overload resolution in deeper details.
  
 ===== Definition elements ===== ===== Definition elements =====
Line 8: Line 8:
 category label '':'' name ''<'' type parameters > ''['' typecheck ''] ('' signature '') : '' attributes category label '':'' name ''<'' type parameters > ''['' typecheck ''] ('' signature '') : '' attributes
  
-//category// can be ''method'', ''function'', etc., as described in the [[rulefiles#functions|general syntax rules]].+//category// can be ''method'', ''function'', etc., as described in the [[reference:rulefiles#functions|general syntax rules]].
  
 Name and signature are mandatory, while label, type parameters, and attributes are optional. Name and signature are mandatory, while label, type parameters, and attributes are optional.
Line 34: Line 34:
   :: Denotes arbitrarily many (trailing) arguments of any types.  This element must be the last one among all arguments in the signature.  This is only allowed with functions implemented in perl.  For C++ functions, an appropriate container type (Array, Vector, etc.) must be used.   :: Denotes arbitrarily many (trailing) arguments of any types.  This element must be the last one among all arguments in the signature.  This is only allowed with functions implemented in perl.  For C++ functions, an appropriate container type (Array, Vector, etc.) must be used.
   ? ''%''option_list   ? ''%''option_list
-  :: Refers to an [[rulefiles#functions|option list]] defined in the rulefiles before.  Trailing argument pairs of the form ''%%keyword => value%%'' with keywords matching the keys of the option list are collected together in an anonymous hash map, which is passed to the function body by reference.+  :: Refers to an [[reference:rulefiles#functions|option list]] defined in the rulefiles before.  Trailing argument pairs of the form ''%%keyword => value%%'' with keywords matching the keys of the option list are collected together in an anonymous hash map, which is passed to the function body by reference.
   .. A signature may contain more than one option list reference.  The arguments passed to the function are reorganized to match the keys of each option list; each anonymous hash map is then passed to the function body per separate reference.  If the option lists share some keys, the keyword arguments matching several lists are copied in all corresponding hash maps.   .. A signature may contain more than one option list reference.  The arguments passed to the function are reorganized to match the keys of each option list; each anonymous hash map is then passed to the function body per separate reference.  If the option lists share some keys, the keyword arguments matching several lists are copied in all corresponding hash maps.
   .. If the argument list already contains a reference to a hash map at the position where keyword-value pairs are expected, this reference is passed unchanged and unchecked to the function body; this allows to gradually define families of polymorphic functions delegating work to each other without expensive re-checking and reordering of keyword arguments.   .. If the argument list already contains a reference to a hash map at the position where keyword-value pairs are expected, this reference is passed unchanged and unchecked to the function body; this allows to gradually define families of polymorphic functions delegating work to each other without expensive re-checking and reordering of keyword arguments.
Line 120: Line 120:
   :: Tells that the function returns an object which can be modified by assigning a value to it.  Primarily used with methods giving access to elements of some data container like a matrix or vector.   :: Tells that the function returns an object which can be modified by assigning a value to it.  Primarily used with methods giving access to elements of some data container like a matrix or vector.
   ? ''returns('' type '')''   ? ''returns('' type '')''
-  :: Tells that the function returns an object of the given type.  Usually the return value is automatically recognized by the auto-generated wrapper and hooked under an appropriately "blessed" perl reference.  This attribute should only be used in special cases where the automatic recognition does not work or must be overridden.  In particular, this attribute must be used with [[reference:cpp_type_binding#abstract_property_types|abstract property types]].+  :: Tells that the function returns an object of the given type.  Usually the return value is automatically recognized by the auto-generated wrapper and hooked under an appropriately "blessed" perl reference.  This attribute should only be used in special cases where the automatic recognition does not work or must be overridden.  In particular, this attribute must be used with [[user_guide:extend:cpp_type_binding#abstract_property_types|abstract property types]].
   ? ''returns(@)''   ? ''returns(@)''
   :: Tells that the function returns several values in a list context.  As usual in perl, when called in scalar context, the //last// value from the list will be taken for further processing.   :: Tells that the function returns several values in a list context.  As usual in perl, when called in scalar context, the //last// value from the list will be taken for further processing.
  • user_guide/extend/polymorphic.txt
  • Last modified: 2021/01/12 15:46
  • by gawrilow