Experiment: Internal sub procedures
- No files found.
Created by: dvkt
I have been thinking about this for a while and am not sure if there's any point, but seeing 25ed0ab5 made me think of it again.
This branch allows you to define LDPL sub-procedures in C++ from within LDPL. It's similar to STORE QUOTE
where it just dumps everything you give it into the compiled code, except it looks for {$varname}
or {$subname}()
and replaces them with LDPL variables for convenience.
I'm not sure it's worth making the compiler more complicated but I needed to see this working to satisfy my curiosity. :^ ) If this isn't a fit we don't have to add it. It's probably easier to just write a .cpp
file and include it directly with -i=
.
Here's what it looks like:
DATA:
x is number
y is number
sum is number
PROCEDURE:
internal sub-procedure fast-add
{$sum} = {$x} + {$y};
end sub-procedure
display "X value: "
accept x
display "Y value: "
accept y
call sub-procedure fast-add
display "Sum is " sum crlf
Or like this:
DATA:
name is text
PROCEDURE:
sub-procedure prompt
display "Enter your name: "
accept name
end sub-procedure
internal sub-procedure greet
if({$name}.empty()){
{$prompt}();
}
cout << "Hi there, " << {$name} << "!!" << endl;
end sub-procedure
call sub-procedure greet
- You're only seeing other activity in the feed. To add a comment, switch to one of the following options.
Please register or sign in to reply