-
Notifications
You must be signed in to change notification settings - Fork 17
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
Improved behaviour of LEFT (instruction) #1061
Comments
Hi @poppichicken and thank you for your kind bug report! First of all, I apologize for the confusion, caused by a typo. Indeed, the To clarify better, let's see this example:
The The correction in the manual has been made, and will be made available with the next USER MANUAL revision. Thank you again! |
Thanks Marco. However, the manual still contains mixed up information. In the below, we have this sentence: This doesn't quite seem to be consistent with what the LEFT$ function is doing, unless you mean that x is the substring, and "TEST" is the string in the example below. And in the manual for LEFT (instruction), the paragraph about the second parameter seems to be talking about how the LEFT (function) works, rather than the LEFT (instruction). |
Hi @poppichicken , thank you for the feedback!
Yes, you are absolutely right, that sentence on
Ok, in this case we are talking about a shortcoming of mine. In the sense that this functionality of replacing the (left part of a) string with another string took on very interesting nuances when it came to borderline situations, such as those in which the string to be replaced is longer than the indicated length, or other things of the sort. There is a topic on the forum that delves into the consequences, and the opinions of the developers. Honestly, and if you agree, we should draw up some sort of specification of operation. For example, these could be the edge cases and default behaviours without pragmas (let
I will re-implement it following this guide line and, since it changes the behaviour a bit, I will implement it on the beta branch using this ticket. For this reason, I turn the ticket into an improvement. |
Hmmm... it all seems very complicated. Assuming len = length of original string, and exp = length of replacement expression...
If pos >= length of original string, it doesn't make any sense to me to perform any sort of insert or replace, except maybe to append the expression string to the end of the original string?
This is confusing, if my assumptions about what LEN and EXP refer to are correct. For example, if we have: But if we have: Here, the length of the replacement expression is indeed >= pos, but pos should not be changed to 3. I also find the last 2 cases confusing.
Similar to my examples above, it doesn't seem correct to compare pos to exp. I understand what you are trying to do. Would it make more sense just to have a REPLACE command? For example, if we have "abc123abc123", and we want to replace only the first "abc" with "xyz", a traditional REPLACE command would likely replace both "abc" with "xyz", creating "xyz123xyz123". If your desire is to replace a number of characters (determined by LEN(expression)) at pos, perhaps it's ok to write any number of characters into the original string at pos, overwriting what was there. But maybe limiting the replacement so that it doesn't make the original string longer. LEFT("musical",3)="elephant" would then ideally create "mueleph", where the length of the original string is maintained, but as much as possible of the replacement expression overwrites the original string from position pos. If this is indeed your desired result, perhaps the maximum length of the "writable" part of the original string can be used to grab the leftmost number of characters from the replacement expression, and put those in at pos. So, in "musical", from position 3, we have a maximum of 5 characters that can be written. Also, if pos=0 OR pos > length of original string, then nothing will be done. I hope that made sense. |
Hi @poppichicken , thank you for the feedback!
Take this example: As an analogy, the result seems valid to me. In a nutshell, if
Take this example:
It should become
It should become
Let me know if the graphic example works for you.
The BASIC version of
Granted that a similar command might be useful, what should it do if the length of the string to be searched for is different from the length of the string to be replaced? This is a dilemma of all algorithms that deal with strings. I found myself in this impasse precisely because the concept of "search and replace" is a much more complex concept than it seems. BASIC solves the problem by using a combined arrangement of
In this case, we should obatin
I hope too! :) Thank you again! |
Ah yes, that all makes sense. I have been thinking more about this command. So we have I think these are the rules that need to be considered: However... if rule (F) is valid, then there is no need for n. So only rules A,C,E are needed, and b$ will simply overwrite characters of a$ (from the start of a$), based on the length of b$. [EDIT] Actually, now that I think about it, I can see why you would want to keep the n parameter.
This replaces the first 2 characters with "x", which could certainly prove useful. |
Hi @poppichicken , and thank you for your feedback! This last comment of yours, actually, makes me think that the directive whether the Coming to the rules:
I agree with this point, in fact it is already the current behavior of ugBASIC.
I agree with this rule too, and it is also the current behavior of ugBASIC.
Exactly, as above (it is the current behavior).
I confirm, it is the current behavior.
Exactly, as above (it is the current behavior).
No, this rule is not correct, IMHO: in fact, if Thank you again! |
I understand, thanks Marco. |
hi Marco.
The LEFT instruction and function descriptions seem to have got mixed up, possible from copy/pasting to the incorrect pages.
On page 570:
The description of the function seems to change and become the description for the LEFT (instruction).
And on page 571:
The description of the function seems to change and become the description for the LEFT (function).
As a result of this, it isn't clear how to use the LEFT (instruction).
The text was updated successfully, but these errors were encountered: