|
Post by rikky on Oct 9, 2021 11:15:15 GMT 1
Hello. I'm using the latest bacon 4.4 a program : string$ = "one two three"
FOR word$ IN string$ PRINT 'PRINT word$ 'PRINT word$ , " ::: " 'PRINT word$ & " ::: " PRINT word$ , " ::: " , "bla" PRINT word$ & " ::: " & "bla" PRINT word$ , " ::: " & "bla" PRINT word$ & " ::: " , "bla" PRINT word$ & " ::: " & CHOP$(EXEC$("echo bla")) PRINT word$ , " ::: " , CHOP$(EXEC$("echo bla")) PRINT word$ , " ::: " & CHOP$(EXEC$("echo bla")) PRINT word$ & " ::: " , CHOP$(EXEC$("echo bla")) NEXT word$ Theoretically we have a word, either one, two or three on the first position. three double points on the second position. And "bla" on the third position. EVERYWHERE. But as soon as there is a comma as a separator AND an EXEC$ we get weird results. result: one ::: bla
one ::: bla
one ::: bla
one ::: bla
one ::: bla
one ::: one ::: bla
oneone ::: bla
one ::: one ::: bla
two ::: bla
two ::: bla
two ::: bla
two ::: bla
two ::: bla
two ::: two ::: bla
twotwo ::: bla
two ::: two ::: bla
three ::: bla
three ::: bla
three ::: bla
three ::: bla
three ::: bla
three ::: three ::: bla
threethree ::: bla
three ::: three ::: bla
Rik.
|
|
|
Post by Pjot on Oct 9, 2021 13:32:54 GMT 1
Hi rik, That's interesting. Looking at the generated source code, all seems to be OK. So you probably do not believe me when I say that technically this isn't a bug, but... it isn't a bug What happens is that the kernel buffering is playing tricks on us here. Your code is correct, and the generated C code is correct, however, the Linux output buffer is not flushed as fast as we would like to see. You can test this yourself by setting the output buffer to 0 on the command line using the ' stdbuf' utility, and then run the program: # stdbuf -o0 ./debug_rick_code
Now your output is as expected, right? I am not sure what to do about this. Of course I can work around it by adding "fflush(stdout)" in the generated C source code, but this will cause a lot of delay and has negative impact on the overall performance of BaCon. If you have a suggestion then please do not hesitate to let me know. BR Peter
|
|
|
Post by rikky on Oct 9, 2021 14:13:05 GMT 1
Well, I think that since this only happens when using EXEC$, the solution is NOT to use comma's but an ampersand '&' in such cases. Maybe this could be mentioned in the docu somewhere. But where? .... The chapter about CONCAT$ maybe Since that chapter appears to be the only one about concatenating strings, as far as I can see.
|
|
|
Post by Pjot on Oct 9, 2021 18:07:00 GMT 1
Thanks rikky, I'll make a notice in the docs. Alternatively, you can switch off buffering in your program: CALL setbuf(stdout, NULL)
HTH Peter
|
|