After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 537706 - Recursive lambdas do not work properly
Recursive lambdas do not work properly
Status: RESOLVED DUPLICATE of bug 554781
Product: vala
Classification: Core
Component: general
0.3.x
Other All
: Normal normal
: ---
Assigned To: Jürg Billeter
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2008-06-11 02:01 UTC by Samuel Cormier-Iijima
Modified: 2008-12-16 00:25 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Samuel Cormier-Iijima 2008-06-11 02:01:54 UTC
For example:

using GLib;

public class Test : Object {
	delegate int Accumulates(int x, int acc);

	public void run() {
		Accumulates fac;

		fac = (x, acc) => {
			if (x <= 1)
				return acc;
			else
				return fac(x - 1, x * acc);
		};

		stdout.printf("Result is: %d\n", fac(5, 1));
	}

	public static void main(string[] args) {
		new Test().run();
	}
}

Vala compiles this fine, but the generated code has errors.

Although Vala probably won't support full closures, recursive lambdas probably shouldn't be too hard to do (in __lambda0 in the generated code, just replace fac_target -> self and fac -> ___lambda0_test_accumulates). I'll see if I can make a patch for this...
Comment 1 Samuel Cormier-Iijima 2008-06-11 02:06:11 UTC
Also, note that if "Accumulates fac;" in the example above is made a member of the Test class as opposed to a local variable in run(), the example compiles and runs as expected.
Comment 2 Jürg Billeter 2008-06-15 21:44:05 UTC
Confirming, it's currently not possible to access any method variable from the body of the lambda method. However, we actually want full closure support, at least to the extent possible.
Comment 3 Jürg Billeter 2008-12-16 00:25:24 UTC
Thanks for the bug report. This particular bug has already been reported into our bug tracking system, but please feel free to report any further bugs you find.


*** This bug has been marked as a duplicate of 554781 ***