Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Recursive interfaces #126

Open
stefjoosten opened this issue May 10, 2023 · 4 comments
Open

Feature request: Recursive interfaces #126

stefjoosten opened this issue May 10, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@stefjoosten
Copy link
Contributor

stefjoosten commented May 10, 2023

What happened

I wrote the following recursive interface, which is a fragment of a more extensive program:

INTERFACE "Routes" : "_SESSION";V[SESSION*Route] BOX
   [ Id : I                                     cRud
   , Berichttype : berichttype                  cRud
   , van : van[Route*Applicatie]  INTERFACE Recursive
   ]

INTERFACE Recursive : I[Applicatie] cRud BOX <TABLE noHeader hideOnNoRecords>
   [ " " : I 
   , "connecties" : connectie  LINKTO INTERFACE Recursive
   ]

This aims to get an easy way to drill down recursively in all connections from a given application.

When running this program, I got an unexpected error:
image

I got the following error:

Error/Exception
Type: Ampersand\Exception\AccessDeniedException
Message: Specified interface 'Recursive/connecties/Recursive' is not accessible
File: /var/www/src/Ampersand/Interfacing/InterfaceExprObjectRef.php
Line: 168

What I expected

I expected this to work. This is what I would have liked to see:
image
I got this screenshot by building the following "poor man's recursion":

INTERFACE "Routes" : "_SESSION";V[SESSION*End2End] BOX
   [ Id : I                                     cRud
   , Berichttype : berichttype                  cRud
   , van : vanEnd  INTERFACE Recursive0
   ]

INTERFACE Recursive0 : I[Applicatie] cRud BOX <TABLE noHeader hideOnNoRecords noRootTitle>
   [ " " : I  LINKTO INTERFACE Applicatie
   , "connecties" : connectie  INTERFACE Recursive1
   ]

INTERFACE Recursive1 : I[Applicatie] cRud BOX <TABLE noHeader hideOnNoRecords noRootTitle>
   [ " " : I  LINKTO INTERFACE Applicatie
   , "connecties" : connectie  INTERFACE Recursive2
   ]

INTERFACE Recursive2 : I[Applicatie] cRud BOX <TABLE noHeader hideOnNoRecords noRootTitle>
   [ " " : I  LINKTO INTERFACE Applicatie
   , "connecties" : connectie  INTERFACE Recursive3
   ]

INTERFACE Recursive3 : I[Applicatie] cRud BOX <TABLE noHeader hideOnNoRecords noRootTitle>
   [ " " : I  LINKTO INTERFACE Applicatie
   , "connecties" : connectie  INTERFACE Recursive4
   ]

INTERFACE Recursive4 : I[Applicatie] cRud BOX <TABLE noHeader hideOnNoRecords noRootTitle>
   [ " " : I  LINKTO INTERFACE Applicatie
   , "connecties" : connectie  LINKTO INTERFACE Recursive0
   ]

This example proves that the system can do this if only we allow this recursion. Since we don't want to inhibit any behavior unnecessarily, I have categorized this as a bug.

Version of Ampersand that was used

ampersandtarski/prototype-framework:v1.16

@stefjoosten stefjoosten added bug Something isn't working enhancement New feature or request and removed enhancement New feature or request labels May 10, 2023
@stefjoosten
Copy link
Contributor Author

stefjoosten commented May 10, 2023

Analysis

  1. A recursive interface without LINKTO is prohibited by the compiler. Lifting this restriction yields a risk of generating an unlimited depth of interfaces at runtime. I don't think that should be a problem, for the same reason as you want to allow infinite loops. @hanjoosten thinks there is a problem with just lifting the restriction because the compiler cannot generate code to expand an interface dynamically. This is work, which enhances the functionality. For this reason, I relabeled this issue as enhancement.

  2. A recursive interface with LINKTO is allowed by the compiler, but yields the bug as shown. It is not quite clear how this bug can be explained. Further analysis is needed.

@hanjoosten
Copy link
Member

Currently, there are already two distinct ways to use an INTERFACE within an INTERFACE. The distinction is made by using the LINKTO keyword or by leaving it out. If you use the LINKTO keyword, a link to another page is being generated by the compiler.
If you omit the LINKTO keyword, the INTERFACE is rendered in place in the current page. That is done recursively, exactly the way you intended it in this case. And indeed, termination of the expansion is a risk that has to be dealt with by the Ampersand modeller. Like in Haskell, the compiler cannot do this.

Unfortunately you run into this bug. The red text that is shown is caused by an AccessDeniedException. I suppose this might have something to do with ROLES in your model? I do not think this has anything to do with te recursiveness of your script.

Then there is something in your script, that will not work the way you intend:

INTERFACE Recursive : I[Applicatie] cRud BOX <TABLE noHeader hideOnNoRecords>
   [ " " : I 
   , "connecties" : connectie  LINKTO INTERFACE Recursive
   ]

I would think you do not want the LINKTO keyword here.

@stefjoosten stefjoosten added the enhancement New feature or request label May 10, 2023
@stefjoosten stefjoosten transferred this issue from AmpersandTarski/Ampersand May 12, 2023
@stefjoosten stefjoosten added enhancement New feature or request and removed enhancement New feature or request bug Something isn't working labels May 12, 2023
@stefjoosten
Copy link
Contributor Author

I moved this issue and turned it in a feature request for the new front-end.

@stefjoosten stefjoosten changed the title Recursive interfaces produce PHP-error Feature request: Recursive interfaces May 12, 2023
@hanjoosten
Copy link
Member

As soon as the new front-end is able to handle recursion, we can lift the restriction in the compiler.

@LiWeiYeh LiWeiYeh transferred this issue from AmpersandTarski/prototype-frontend Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

4 participants