- Subject: Re: optional arguments
- From: Günter Milde <milde@xxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 11 Jun 2003 10:32:23 +0200
On Fri, Jun 06, 2003 at 08:54:32PM +0000, Joerg Sommer wrote:
> Hi,
>
> in slang.txt section "4.1.5 Null_Type" is an example given, that show,
> how to use NULL for functions with optional arguments. But this example
> doesn't work if I call add_numbers() and what's my problem, I don't see
> how to use this with functions with one argument.
There is, however a way for optional arguments: use the variable _NARGS,
that is set to the number of arguments given with the function call.
Example:
define foo()
{
vmessage("%d", _NARGS);
_pop_n(_NARGS);
}
Now foo() shows 0, foo("s") shows 1, and foo(,5) shows 2.
However, 1; foo() would show 0 and leave 1 on stack.
Something more usefull: Arguments with default
% Hide/unhide the whole buffer
public define set_buffer_hidden() % (hide=1)
{
variable hide = 1;
if (_NARGS)
hide = ();
push_spot();
!if (is_visible_mark())
mark_buffer();
set_region_hidden(hide);
pop_spot();
}
Unfortunately, menu_append_item doesnot set _NARGS right, when calling a
function with the 4th argument as argument. So use with caution.
Günter
--
Milde at ife.et.tu-dresden.de
--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.
[2003 date index]
[2003 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]