Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2009-05-01
08:30 • Ticket [1665441fff] Generate an error on default arg followed by non-default arg... artifact: 5ecd1651e6 user: msofer
2007-02-27
19:33 • Ticket [1665441fff]: 4 changes artifact: 2ca2651010 user: lars_h
2007-02-23
19:09 • Ticket [1665441fff]: 4 changes artifact: 11fb1c769f user: pspjuth
02:52 • Ticket [1665441fff]: 4 changes artifact: 09458f1c81 user: msofer
2007-02-22
14:35 • Ticket [1665441fff]: 4 changes artifact: 7693bbf3cb user: pspjuth
00:30 • Ticket [1665441fff]: 2 changes artifact: 0ff6c76582 user: msofer
00:30 • Ticket [1665441fff]: 4 changes artifact: ca4c7f3af5 user: msofer
00:25 • Add attachment tclProc.c to ticket [1665441fff] artifact: 96e7045c28 user: gwlester
00:25 • Ticket [1665441fff] Generate an error on default arg followed by non-default arg... artifact: 52d9345063 user: gwlester
2007-02-21
17:25 • New ticket [1665441fff]. artifact: 52176a7bab user: gwlester

Generate an error on default arg followed by non-default arg

Open1665441fffffffffffffffffffffffffffffffffCreated 20 years agoUpdated 18 years ago
Descriptionplain2007-02-21 17:25:36
The proc command should raise an error if a non-default argument follows a defaulted argument.
gwlesterplain2007-02-22 00:25:37
File Added - 217069: tclProc.c
msoferplain2007-02-22 00:30:13
Logged In: YES 
user_id=148712
Originator: NO

Please submit the patch as patch, not the full file! 'diff -u' is what we prefer ...
msofer Ticket [1665441fff]: 2 changes [History diff]2007-02-22 00:30:53
pspjuthplain2007-02-22 14:35:42
Logged In: YES 
user_id=98900
Originator: NO

While adding such sanity checks, it might be good to check
for duplicate arguments too.
proc a {x x} { puts [info locals] }
is currently allowed but nonsensical.
msoferplain2007-02-23 02:52:39
Logged In: YES 
user_id=148712
Originator: NO

Duplicate arguments is not itself an error; there might even be someone out there (mis)using that (mis)feature?
pspjuthplain2007-02-23 19:09:30
Logged In: YES 
user_id=98900
Originator: NO

I think you are right, I can imagine someone using duplicate args for
dummy args like:
proc a {x _ _ y} {...}
so, consider my request withdrawn.
lars_hplain2007-02-27 19:33:40
Logged In: YES 
user_id=938835
Originator: NO

Has the issue of how this is documented been considered?

The [proc] manpage (8.5 currently on www.tcl.tk) says:
Arguments with default values need not be specified in a procedure invocation. However, there must be enough actual arguments for all the formal arguments that don't have defaults, and there must not be any extra actual arguments.

It does /not/ say arguments with defaults may only be given at the end. Even the error messages seem to agree with this, although an error is thrown:

% info patchlevel
8.5a3
% proc prov {{opt 23} man} {list $opt $man}
% prov 1
wrong # args: should be "prov ?opt? man"
% prov 1 2
1 2
msofer Ticket [1665441fff]: 1 change [History diff]2009-05-01 08:30:08
Log in (anonymous is fine) to add a comment.

Attachments: