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

sub-data sections #113

Closed
arielf212 opened this issue Jun 9, 2019 · 4 comments · Fixed by #124
Closed

sub-data sections #113

arielf212 opened this issue Jun 9, 2019 · 4 comments · Fixed by #124
Labels
feature request Please add this to the language!

Comments

@arielf212
Copy link
Contributor

I have been toying with LDPL for a while now, and one of the things that irks me the most is the sheer amount of variables you need to create in order to hold stuff and not override the data of one of the other methods.

my proposed solution to this is SUB-DATA sections. I am proposing that before every SUB-PROCEDURE you will be able to declare an optional SUB-DATA section. all variables declared inside a SUB-DATA section act like local variables. they are only usable inside a SUB-PROCEDURE and (optionally) are not reset after every call to the SUB-PROCEDURE (in order to be compatible with the whole "variables are persistent between scopes thing the language has going on already) . they also should not have any naming conflicts with other internal variables (of other sub-procedures).

example:

DATA:
    i is number
PROCEDURE:
    SUB-DATA:
        x is number
    SUB-PROCEDURE foo
       incr x
       display x " "
end SUB-PROCEDURE
while is less than 10 do
    call foo
repeat
#stdout should be: 0 1 2 3 4 5 6 7 8 9 

tl;dr: persistent local variables

@Lartu
Copy link
Owner

Lartu commented Jun 11, 2019

Hi there! This is something we considered at one point, but I can't remember why we didn't go through with it. @dvkt, @dgarroDC what do you think about this?

@Lartu
Copy link
Owner

Lartu commented Jun 11, 2019

I was thinking that this could be maybe coupled with a way of passing parameters to sub-procedures, something like:

SUB PROCEDURE foo
    PARAMETERS:
      myNumber IS NUMBER
      otherNumber IS NUMBER
    LOCAL DATA:
      bar IS NUMBER
    PROCEDURE:
      ACCEPT bar
      ADD bar AND myNumber IN bar
      DIVIDE bar BY otherNumber IN bar
      DISPLAY bar CRLF
END SUB-PROCEDURE

CALL foo WITH 17 -8

What do you all think?

@Lartu
Copy link
Owner

Lartu commented Jun 11, 2019

I was thinking that maybe this would lead to easier to implement libraries than the COBOL based model we previously proposed, @dvkt. We could just write a "library writing standard" and state that is good practice to name the global libraries inside a library as <libname>.<variablename> and create an IMPORT statement.

@dgarroDC
Copy link
Collaborator

I was thinking that this could be maybe coupled with a way of passing parameters to sub-procedures, something like:

SUB PROCEDURE foo
    PARAMETERS:
      myNumber IS NUMBER
      otherNumber IS NUMBER
    LOCAL DATA:
      bar IS NUMBER
    PROCEDURE:
      ACCEPT bar
      ADD bar AND myNumber IN bar
      DIVIDE bar BY otherNumber IN bar
      DISPLAY bar CRLF
END SUB-PROCEDURE

CALL foo WITH 17 -8

What do you all think?

I think this would be a great addition to the language!

@Lartu Lartu added the feature request Please add this to the language! label Jun 17, 2019
@Lartu Lartu closed this as completed Jun 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Please add this to the language!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants