Re: problem with optional argument

From: Andy Vaught (andy_at_firstinter.net)
Date: 05/24/04


Date: Sun, 23 May 2004 23:48:30 -0700

On Thu, 20 May 2004, Christoph Arns wrote:

> Hi all,
>
> below is a little program snipped, which so far I always could use
> successfully in a similar form. Now I got
>
> Error: intfc_test.f90, line 36: Ambiguous specific names PF_INIT_3D and
> PF_INIT_2D in generic PF_INIT
> Errors in declarations, no further processing for INTFC
> Error: intfc_test.f90, line 39: USE of module INTFC which has errors
> Errors in declarations, no further processing for INTFC_TEST
> [f95 error termination]
>
> on an Opteron/NAG/Fedora platform:
>
> NAGWare Fortran 95 Release 5.0
> Linux rsphylc 2.6.5 #1 SMP Fri Apr 16 15:57:37 EST 2004 x86_64 x86_64
> x86_64 GNU/Linux

  [...]
 
> my question: is this a bug, or am I not understanding optional arguments
> in combination with generic interfaces correctly?

  G95 craps out on this too but the NAG compiler is good company to be
wrong with. From what I can tell, the bug is in the standard.

  When building a list of interfaces, the compiler has to make sure
that they aren't ambiguous. That is, that there does not exist an
actual argument list that could match any two formal interfaces.

  There are two main rules used to do this. If either is satisfied,
the interfaces are unambiguous. The first rule involves counting the
number of arguments of a particular type. This rule is used to
account for optional arguments which may or may not be present in the
actual argument list.

  The second rule deals with nonoptional arguments and has three parts
that must all be satisfied for it to be true. First, there has to be
a pair of arguments that correspond by position and disagree on type,
rank or kind (or doesn't exist). Second, there has to exist a keyword
(formal argument) name that disagrees by type, rank or kind or doesn't
exist. Last, the argument disagreeing by position has to precede or
be the same as the argument that disambiguates by keyword.

  In your example, the first argument that disagrees by position is
the fourth. The *only* keyword that differs is the third argument,
'nz' of the 'pf_init_3d' interface. This precedes the positional
difference so the test fails and the interfaces are ruled ambiguous.
As people have pointed out, the interfaces are not ambiguous at all,
so something is wrong with the rules.

  The error appears to be in the third clause, where the sense of the
test should be reversed.

  The confusion in this rule probably came from the fact that positional
arguments have to precede keyword arguments in an actual argument list.
But the *disambiguating* keyword argument has to precede the
*disambiguating* positional argument.

  If an actual argument list has enough positional arguments to get to
the positionally disambiguating argument, all is well. Otherwise,
there have to be keywords prior to this and they have to disambiguate
the interfaces.

  I checked the language in f2003, and it appears that although it
differs from f95 a bit, the problem still exists. If no one cares to
poke a hole in this reasoning, I will see about writing a J3 paper
tomorrow night.

  I've fixed this problem in g95 and uploaded it to the usual place at
http://www.g95.org.

  Thanks,
    Andy

(and thanks to Doug Cox for trying this with g95).



Relevant Pages

  • Re: Poster boy for optional and keyword args together?
    ... &OPTIONAL and &KEY in the same lambda list; again, the keyword ... In a way, this is vaguely similar to Java's interfaces, whereby ... So if key args were passed in a ... In CL's optionals, ...
    (comp.lang.lisp)
  • Re: Poster boy for optional and keyword args together?
    ... with the keyword args as afterthoughts and importantly a ... &OPTIONAL and &KEY in the same lambda list; again, the keyword ... this is the best explanation I've ever seen of this. ... In a way, this is vaguely similar to Java's interfaces, whereby ...
    (comp.lang.lisp)
  • Re: Java "interface" vs. OO interface
    ... > I think Java uses interfaces instead of classes because the designers ... To think that the designers of Java and .NET couldn't figure out a good ... Enough for a language to adopt a new keyword ...
    (comp.object)
  • Re: Determine if a string is a vb.net keyword
    ... The System.Reflection namespace contains classes and interfaces that ... ability to dynamically create and invoke types. ... with the type definition in the assembly but not the compilication issue. ... It should be the Compiler's job to recognize the keyword and do ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Translate IPFW rules to PF rules
    ... I already saw some references to the "self" keyword, ... find anything about it in the documentation. ... pfctl -t SELF -T delete old.self.ip.addr ... all your interfaces you needn't worry about this, ...
    (comp.unix.bsd.freebsd.misc)