Post Reply 
How much memory may a HPPL program use on a G2?
09-21-2023, 04:07 AM
Post: #82
RE: How much memory may a HPPL program use on a G2?
(09-18-2023 07:37 PM)komame Wrote:  
(09-18-2023 08:27 AM)jte Wrote:  
one possible result of it would be to change REPLACE so that lists (in the strings case) could be given as the second and third arguments, to enact multiple replacements with a single PPL call. (e.g., allow “replace(str,accents,latin);” to be used in CROSSWORDS’ convAccents(-) instead of the looped call to REPLACE that is currently being done.)
I think using a list as the second and third parameter here won’t make much difference.

Yes… in general. My immediate thought was to have REPLACE check for cases where optimized kernels could be employed — the relevant one here being a list of single-character replacement rules.

Quote:Notice that you have to perform the replacement sequentially; you can’t replace all found values at once in a single iteration over the text string because they may overlap.

This is connected to my second thought — what, exactly, would the semantics be for this more general REPLACE use? I was thinking that, whatever the general semantics would be, they could simplify down to the same meaning for when a list of single-character replacement rules is presented.

That still doesn’t directly lead to an exact definition in the more general case. The on-the-face-of-it definition (for a more general REPLACE) would be to quickly fall back to the current REPLACE rule for strings: have the meaning of REPLACE(string,{a,b,…},{A,B,…}) be to invoke REPLACE with a->A, b->B, … (each in turn, each starting with the result of the previous) This would still allow a list of single-character replacement rules to be identified and more efficiently enacted.

It is certainly possible different semantics might be better (useful in other cases). Just off the top of my head:
  • scanning from front to back and using the earliest match (of the list) is another possibility (i.e., see if match 1 applies starting from position 1, then match 2 and position 1, … — and skipping past a replacement once it is performed) or
  • have later matches only trigger on portions of the string unmatched by earlier rules.
I haven’t thought much at all about possible more-general semantics…

There are two aspects to keep in mind for a more general REPLACE: one being to allow for faster execution, another being to allow for shorter / simpler / more natural code.

Quote:
It would only make sense for 1-character elements, but I guess you won’t impose a limitation that only 1-character elements can be provided in the list, right? The iteration itself in ‘accentConv(-)’, excluding REPLACE, only takes 1ms, and that’s the only time you can save. To illustrate this: imagine someone uses REPLACE like this: replace(“AABBABAB”,{”AB”,”BA”},{”BA”,”AB”}).

This sort of example popped right into my mind too, but mine was nowhere near as compact! Big Grin

And, again, we seem to be in agreement on the nature of interpreters! Big Grin (Well, interpreter overhead — in this sort of case, to be more precise.)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: How much memory may a HPPL program use on a G2? - jte - 09-21-2023 04:07 AM



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