<?xml version="1.0" encoding="utf-8" ?> <!-- for emacs: -*- coding: utf-8 -*- --> <!-- Apache may like this line in the file .htaccess: AddCharset utf-8 .html --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg-flat.dtd" > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head><title>OptionTable >> Function -- attaching options to a function</title> <link rel="stylesheet" type="text/css" href="../../../../Macaulay2/Style/doc.css"/> </head> <body> <table class="buttons"> <tr> <td><div><a href="___Order.html">next</a> | <a href="___Option__Table_sp_pl_pl_sp__Option__Table.html">previous</a> | <a href="___Order.html">forward</a> | <a href="___Option__Table_sp_pl_pl_sp__Option__Table.html">backward</a> | up | <a href="index.html">top</a> | <a href="master.html">index</a> | <a href="toc.html">toc</a> | <a href="http://www.math.uiuc.edu/Macaulay2/">Macaulay2 web site</a></div> </td> </tr> </table> <hr/> <div><h1>OptionTable >> Function -- attaching options to a function</h1> <div class="single"><h2>Synopsis</h2> <ul><li><div class="list"><dl class="element"><dt class="heading">Usage: </dt><dd class="value"><div><tt>g = defs >> fun</tt></div> </dd></dl> </div> </li> <li><span>Operator: <a href="__gt_gt.html" title="a binary operator, uses include bit shifting, or attaching optional inputs to functions">>></a></span></li> <li><div class="single">Inputs:<ul><li><span><tt>defs</tt>, <span>an <a href="___Option__Table.html">option table</a></span>, (or <span>a <a href="___List.html">list</a></span> of option pairs), whose keys are the names of the optional arguments, and whose values are the corresponding default values. Alternatively, if <tt>defs</tt> is <a href="_true.html" title="">true</a>, then all optional arguments are accepted and no defaults are provided.</span></li> <li><span><tt>fun</tt>, <span>a <a href="___Function.html">function</a></span>, a function that expects optional arguments</span></li> </ul> </div> </li> <li><div class="single">Outputs:<ul><li><span><tt>g</tt>, <span>a <a href="___Function.html">function</a></span>, a new function that pre-processes the optional arguments and then calls <tt>fun</tt></span></li> </ul> </div> </li> </ul> </div> <div class="single"><h2>Description</h2> <div><p>The new function <tt>g</tt> works as follows. The value of <tt>g args</tt>, say, is obtained by evaluation of <tt>(fun opts)(args')</tt>, where <tt>args'</tt> is obtained from <tt>args</tt> by removing the options of the form <tt>X=>A</tt> (where <tt>X</tt> is a name of an optional argument), and <tt>opts</tt> is a hash table of the same form as <tt>defs</tt> in which the default values have been replaced by the user-supplied values, e.g., the value stored under the key <tt>X</tt> has been replaced by <tt>A</tt>.</p> <p>Remark: <tt>defs</tt> can also be simply a list of options.</p> <p>In the following example we use a simple definition for <tt>fun</tt> so we can see everything that <tt>fun</tt> receives.</p> <table class="examples"><tr><td><pre>i1 : g = {a=>1, b=>2} >> opts -> args -> {args, opts} o1 = g o1 : FunctionClosure</pre> </td></tr> <tr><td><pre>i2 : g x o2 = {x, OptionTable{a => 1}} b => 2 o2 : List</pre> </td></tr> <tr><td><pre>i3 : g(x,y,b=>66) o3 = {(x, y), OptionTable{a => 1 }} b => 66 o3 : List</pre> </td></tr> <tr><td><pre>i4 : g(t,u,a=>44,b=>77) o4 = {(t, u), OptionTable{a => 44}} b => 77 o4 : List</pre> </td></tr> <tr><td><pre>i5 : h = true >> opts -> args -> {args, opts} o5 = h o5 : FunctionClosure</pre> </td></tr> <tr><td><pre>i6 : h(t,u,c=>55) o6 = {(t, u), OptionTable{c => 55}} o6 : List</pre> </td></tr> </table> </div> </div> <div class="single"><h2>See also</h2> <ul><li><span><a href="_making_spnew_spfunctions_spwith_spoptional_sparguments.html" title="">making new functions with optional arguments</a></span></li> <li><span><a href="___Option__Table.html" title="the class of hash tables for optional arguments">OptionTable</a> -- the class of hash tables for optional arguments</span></li> <li><span><a href="___Option.html" title="the class of all pairs x => y">Option</a> -- the class of all pairs x => y</span></li> <li><span><a href="__eq_gt.html" title="produce an Option">=></a> -- produce an Option</span></li> </ul> </div> </div> </body> </html>