buggy(?) UNTIL and documentation comments (SOLVED)
Jun 5, 2024 23:49:08 GMT 1
Post by clamzonprozac on Jun 5, 2024 23:49:08 GMT 1
Here's something that doesn't work as expected: the UNTIL in this code example gives two differing results depending on the order of
the conditionals. As a sanity check I've included a corresponding IF that gives a correct (expected) result.
REM---------------------------------------------------------------------------------------------
GLOBAL test_table$ = "|aa,bb,cc,dd|ee,ff,gg|hh,ii|"
GLOBAL i, test_table_len TYPE int
test_table_len = LEN(test_table$)
FUNCTION until_test$()
LOCAL c$,s$
s$ = ""
REPEAT
c$ = MID$(test_table$,i,1)
s$ = s$ + c$
INCR i
UNTIL (c$ = ",") OR (c$ = "|") OR (i = test_table_len -1 ) : 'swap the "," and "|" to see what I mean
RETURN s$
END FUNCTION
FUNCTION if_test$()
LOCAL c$,s$
s$ = ""
LABEL repeat_me :
c$ = MID$(test_table$,i,1)
s$ = s$ + c$
INCR i
IF (c$ = ",") OR (c$ = "|") OR (i = test_table_len -1 ) THEN
RETURN s$
ELSE
GOTO repeat_me
END IF
END FUNCTION
i=2
PRINT until_test$()
i=2
PRINT if_test$()
REM----------------------------------------
However, instinctively, I've used three OR'd conditionals with UNTIL where as the documentation only tells of an equation being specified, and that seems a counter-intuitive restriction. Maybe I'm doing something horribly wrong?
I also notice that REPEAT has an entry in the BaCon documentation but its partner, UNTIL, doesn't.
Speaking of documentation, it would be nice if more words were thrown at the ADDRESS keyword. As in explaining more about its scope. Only GLOBAL variables, or can it temporarily reference a variable on the stack? Any tricks one might want to know?
Thanks for the read, BR!
-Roger M.
the conditionals. As a sanity check I've included a corresponding IF that gives a correct (expected) result.
REM---------------------------------------------------------------------------------------------
GLOBAL test_table$ = "|aa,bb,cc,dd|ee,ff,gg|hh,ii|"
GLOBAL i, test_table_len TYPE int
test_table_len = LEN(test_table$)
FUNCTION until_test$()
LOCAL c$,s$
s$ = ""
REPEAT
c$ = MID$(test_table$,i,1)
s$ = s$ + c$
INCR i
UNTIL (c$ = ",") OR (c$ = "|") OR (i = test_table_len -1 ) : 'swap the "," and "|" to see what I mean
RETURN s$
END FUNCTION
FUNCTION if_test$()
LOCAL c$,s$
s$ = ""
LABEL repeat_me :
c$ = MID$(test_table$,i,1)
s$ = s$ + c$
INCR i
IF (c$ = ",") OR (c$ = "|") OR (i = test_table_len -1 ) THEN
RETURN s$
ELSE
GOTO repeat_me
END IF
END FUNCTION
i=2
PRINT until_test$()
i=2
PRINT if_test$()
REM----------------------------------------
However, instinctively, I've used three OR'd conditionals with UNTIL where as the documentation only tells of an equation being specified, and that seems a counter-intuitive restriction. Maybe I'm doing something horribly wrong?
I also notice that REPEAT has an entry in the BaCon documentation but its partner, UNTIL, doesn't.
Speaking of documentation, it would be nice if more words were thrown at the ADDRESS keyword. As in explaining more about its scope. Only GLOBAL variables, or can it temporarily reference a variable on the stack? Any tricks one might want to know?
Thanks for the read, BR!
-Roger M.