Post Reply 
Custom Text Formatting (Previously: Getting long results in a program)
04-06-2024, 09:27 PM (This post was last modified: 04-06-2024 10:41 PM by komame.)
Post: #44
RE: Getting long results in Program
(04-06-2024 04:01 PM)Tyann Wrote:  I think we've hit the nail on the head when it comes to the structure of the function.
Here's a 'little code' that seems to do the job, I've done 2 or 3 tests.
Marking the string in a string: ""string",..." doesn't seem to be a problem for EXPR().
I'm sure there's room for improvement: the function can be made externally, I think.

It looks good, but a few minor corrections are required.

1. You used:
f:=SUPPRESS(f,"{}");
however, this won't work for cases where you want to display text containing curly braces because they will be removed. That's why I suggested using MID earlier. If you still insist on using SUPPRESS, it's also possible, but it needs to be implemented using slightly different syntax:
f:=SUPPRESS(f,{1,SIZE(f)}).

2. The condition:
5<d<8 OR (d==8 AND t==8)
can be simplified to
5<d<9
because the two subsequent conditions already exclude t=8 and d=8 respectively, and in conjunction with 5<d<9, they will behave the same way.
This, in turn, allows us to change
d>7
to
d>8
And then the following condition can be removed:
IF d==8 THEN
  l:=INSERT(l,2,G0);
END;


3. Missing protection against too many parameters. A "Syntax error" should be triggered when more than 9 parameters are provided. Currently, providing 10 or more parameters does not trigger an error.

4. And one minor oversight: you need to add closing parentheses in the EXPR expressions.

Here is the code after all these corrections:
Code:
EXPORT ATEXTOUT_P(...l)
BEGIN
 LOCAL d:=SIZE(l),t:=TYPE(l(2)),i,f;
 CASE
  if 2<d<6  OR (d==6  AND t==8) then
   f:="TEXTOUT_P("+STRING(l)+")";
   f:=SUPPRESS(f,{1,SIZE(f)});
   //EXPR(f);
  end;
  if 5<d<9 then  
   IF t≠8 THEN 
    l:=INSERT(l,2,G0);
   END;
   IF d<8 THEN
    l(0):=GET(TEXTSIZE(l(1),l(5)),1);
   END;
   f:="atextout_p("+STRING(l)+")";
   f:=SUPPRESS(f,{1,SIZE(f)}); 
   //EXPR(f);
  end;
  if d==9 then
   f:="atextout_p("+STRING(l)+")";
   f:=SUPPRESS(f,{1,SIZE(f)});
   //EXPR(f);
  end;
  default
   //RETURN "Erreur de syntaxe";
   f:="Erreur de syntaxe";
 END;
 f;
END;

It's a pity that in PPL there's no capability to throw errors. Simply returning the string "Syntax Error" doesn't effectively address the issue, as it fails to trigger an error within the program, allowing it to continue execution. I propose using the EXPR("Syntax error"), which raises an "Syntax error" and terminates program execution. I know it's just a workaround, but at the moment, I don't know of a better solution.
It would be beneficial to have a built-in mechanism in PPL where any error can be raised on demand.

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Getting long results in Program - komame - 04-06-2024 09:27 PM
RE: Custom Text Formatting - Tyann - 04-15-2024, 06:55 PM
RE: Custom Text Formatting - komame - 04-15-2024, 07:42 PM
RE: Custom Text Formatting - Tyann - 04-16-2024, 04:38 AM
RE: Custom Text Formatting - komame - 04-16-2024, 06:02 AM



User(s) browsing this thread: 66 Guest(s)