Skip to content

A parameterless function used as an expression is not called #7

@bg-hub2

Description

@bg-hub2

This bug report demonstrates a problem with parameterless functions.

The following piece of code

#lang algol60
begin
  integer procedure getvalue;
     getvalue := 4;

  integer i;
  i := getvalue;
  printnln(i)
end

fails with this message:
bad value: expected a number, got #<procedure:getvalue>
In my understanding, the problem is that in

i := getvalue;

the function getvalue is not called. Instead, the generated code attempts to assign a function to an integer, which of course fails.
The following modified example works:

#lang algol60
begin
  integer procedure getvalue(arg);
     Boolean arg;
     getvalue := 4;
  integer i;
  i := getvalue(true);
  printnln(i)
end

This works because the call of a function with parameters is unambiguous.

To further clarify the more tricky aspects of parameterless functions, consider the following example:

#lang algol60

begin
  real procedure r;
  begin
    r := 5.0;
  end;

  real procedure p1(rv, rp);
    real rv;
    real procedure rp;
  begin
    p1 := rv + rp
  end;
  printnln(p1(r, r))
end

In Racket Algol 60 this does not work. Note that in the expression
p1(r, r)
the first occurance of r is a function call, while the second isn't. For some reason, Racket Algol 60 does not see the difference because r is parameterless.

Again, the introduction of a dummy parameter (to function r) disambiguates a function call from a reference to a function:

#lang algol60
begin
  real procedure r(x);
    Boolean x;
  begin
    r := 5.0;
  end;

  real procedure p1(rv, rp);
    real rv;
    real procedure rp;
  begin
    p1 := rv + rp(true)
  end;

  printnln(p1(r(true), r))
end

Now a function call requires a syntax that is different from a function reference and everything is fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions