How to set the default argument value of a function.



Just for completeness,

(%i1) f1(a,[b]):= (if length(b)=0 then b:[1,2]

                     else if length(b)=1 then

                            b:endcons(2,b),

                            a+b[1]+b[2])$

(%i2) f1(7);

(%o2)                           10

(%i3) f1(8,9);

(%o3)                           19


Regards,
Jaime

On 01-12-2013 17:12, Stavros Macrakis wrote:
> There is no built-in functionality for this, but you can program it 
> yourself easily enough:
>
>     f1(a,[b]) := ( if b=[] then b:[1,2],
>                    ...rest of function...)
>
> or
>
>       f1(a,[b]) := ( if length(b)=0 then b:[1,2],
>  ...rest of function...)
>
>
>
> On Sun, Dec 1, 2013 at 7:01 AM, - <mleoking at gmail.com 
> <mailto:mleoking at gmail.com>> wrote:
>
...
>
>     For example,
>
>     f1(a,[b]):=(a+b[1]+b[2]);
>
>     f1(3);
>
>     I want b[1] and b[2] to be equal to 1 and 2 by default when they
>     are omitted when calling f1.
>
>