|
Post by bitvast on Dec 6, 2014 10:27:34 GMT 1
Not sure if the current Beta is 3.03, but anyway...
There are a few bugs in the doc (example programs) which, if the new lower-case option is selected, cause variables to become keywords. e.g., an example under OPEN generates an error because of the "data" variable:
data = MEMORY(500) OPEN data FOR MEMORY AS mem PUTLINE "Hello cruel world" TO mem MEMREWIND mem GETLINE txt$ FROM mem CLOSE MEMORY mem PRINT txt$ There are at least a couple of others, this one in the section "Passing arrays to functions or subs" -
CONST dim = 2 DECLARE series[dim] TYPE NUMBER SUB demo(NUMBER array[dim]) array[0] = 987 array[1] = 654 END SUB series[0] = 123 series[1] = 456 demo(series) FOR x = 0 TO dim - 1 PRINT series[x] NEXT No errors in running this, but "array" is highlighted because ARRAY is a keyword
And under PRINT, the word "current" is a variable but is also a keyword in the SEEK statement.
t = NOW + 300 PRINT HOUR(t), MINUTE(t), SECOND(t) FORMAT "%.2ld%.2ld%.2ld" TO time$ PRINT MONTH$(t) FORMAT "%s" TO current$ SIZE 15
|
|
|
Post by bitvast on Dec 6, 2014 13:53:24 GMT 1
declare x$[] = {"1","2","3"}
x$[1] = "" print x$[1] results in:
*** Error in `/tmp/baconshell': munmap_chunk(): invalid pointer: 0x08048e62 *** ======= Backtrace: ========= /lib/libc.so.6(+0x77d4d)[0xb75bcd4d] /lib/libc.so.6(+0x17ba5)[0xb755cba5] /tmp/baconshell[0x8048b79] /lib/libc.so.6(__libc_start_main+0xf3)[0xb755e7a3] /tmp/baconshell[0x8048701] ======= Memory map: ======== 08048000-0804a000 r-xp 00000000 08:01 24462467 /tmp/baconshell 0804a000-0804b000 rw-p 00001000 08:01 24462467 /tmp/baconshell 0804b000-0804d000 rw-p 00000000 00:00 0 0928f000-092b0000 rw-p 00000000 00:00 0 [heap] b750c000-b7527000 r-xp 00000000 08:01 16867252 /usr/lib/libgcc_s.so.1 b7527000-b7528000 rw-p 0001a000 08:01 16867252 /usr/lib/libgcc_s.so.1 b7543000-b7545000 rw-p 00000000 00:00 0 b7545000-b76ca000 r-xp 00000000 08:01 33818247 /lib/libc-2.17.so b76ca000-b76cc000 r--p 00184000 08:01 33818247 /lib/libc-2.17.so b76cc000-b76cd000 rw-p 00186000 08:01 33818247 /lib/libc-2.17.so b76cd000-b76d0000 rw-p 00000000 00:00 0 b76d0000-b76d3000 r-xp 00000000 08:01 33818250 /lib/libdl-2.17.so b76d3000-b76d4000 r--p 00002000 08:01 33818250 /lib/libdl-2.17.so b76d4000-b76d5000 rw-p 00003000 08:01 33818250 /lib/libdl-2.17.so b76d5000-b7715000 r-xp 00000000 08:01 33818251 /lib/libm-2.17.so b7715000-b7716000 r--p 0003f000 08:01 33818251 /lib/libm-2.17.so b7716000-b7717000 rw-p 00040000 08:01 33818251 /lib/libm-2.17.so b7731000-b7733000 rw-p 00000000 00:00 0 b7733000-b7754000 r-xp 00000000 08:01 33818244 /lib/ld-2.17.so b7754000-b7755000 r--p 00020000 08:01 33818244 /lib/ld-2.17.so b7755000-b7756000 rw-p 00021000 08:01 33818244 /lib/ld-2.17.so bfab0000-bfad1000 rw-p 00000000 00:00 0 [stack] ffffe000-fffff000 r-xp 00000000 00:00 0 [vdso]
The problem only seems to be with strings. This works fine -
declare x[] = {1,2,3}
x[1] = 0 print x[1] 0
|
|
|
Post by vovchik on Dec 6, 2014 15:19:31 GMT 1
Dear all, Yes, bitvast is right - and it also bombs when all is in upper case, so it doesn't look like a direct uc/lc bug. This is also the case with 3.0.2 final and all the betas that I have tried of 3.0.2 and also in 3.0.1. Good catch, bitvast! With kind regards, vovchik
|
|
|
Post by bitvast on Dec 6, 2014 16:57:39 GMT 1
Thanks vovchik, nice to have it confirmed by a God. By the way, thought I'd treat myself to a new avatar.
|
|
|
Post by vovchik on Dec 6, 2014 17:30:03 GMT 1
Dear bitvast and Peter, The problem arises if you try to change the value of an array element. The actual initialization is OK - all values are present, as can be shown by putting it through a loop. The "invalid pointer" in the error message should tell us something. With kind regards, vovchik PS. @ bitvast" Nice and appropriate avatar. I also attached one you might like - just made it and you can use it if you want. And I made bits of yours transparent. Attachments:
|
|
|
Post by Pjot on Dec 6, 2014 18:52:34 GMT 1
Thanks bitvast, (1) for the documentation issue, BaCon upper and lowercase are not 'equal', like in a Windows environment. It is not for nothing that the examples are written in capital letters, and it is not for nothing that BaCon uses uppercase by default, to avoid name clashes. As mentioned earlier, BaCon is a lazy converter, meaning that it passes expressions as-they-are to the C compiler. Because of this, the parser and/or compiler may choke on the usage of certain words when enabling lowercase, like you point out also. Note that it already was possible to use BaCon in lowercase by including lowercase.bac in the source file. This possibility merely has been incorporated as an option, and is not enabled by default. And with reason! Use small letters is something you do at your own risk. Those people who insist on using small letters can do so, but it doesn't go without consequences. (2) this never has worked for string arrays, and technically, we may wonder if this is a bug, though I can see why the result does not meet your expectations. A direct array initialization using pointers will define the array members as pointers to the given strings, e.g. the array members are defined by reference. A subsequent assignment of such an array member to a different value will be treated as an assignment by value, and therefore, the memory cleaning mechanism tries to cleanup a previous value by freeing the memory of the array member. However, it points to a fixed string by reference and therefore, a crash is the result. So I will check if there is a way to get around this... Thanks again! Peter PS I like your new avatar
|
|
|
Post by bitvast on Dec 6, 2014 20:00:30 GMT 1
Hi Peter, Ah, that pesky lazy converter business, it's caught me out before. I've changed all the code on my website to lowercase, maybe I should include a warning about the possible consequences... Re the string arrays, thanks for the explanation. I discovered the error when writing a little program to demo initializing arrays (for the website/tutorial). REM string functions quick quiz
option base 1 const N = 10
'initialize the questions declare qu$[] = {"what is the operator which joins 2 strings together? ", \ "which function gets the numeric value of a string? ", \ "which function converts a number to a string? ", \ "which function converts a string to upper-case? ", \ "which function extracts a sub-string from a string? ", \ "which function calculates the ASCII value of a character? ", \ "which function returns the character belonging to ASCII number x? ", \ "which function removes spaces from either side of a string? ", \ "which function returns x characters from the left of a string? ", \ "which function returns the length of a string? "}
'initialize the answers declare ans$[] = {"&","val","str$","ucase$","mid$","asc","chr$","chop$","left$","len"}
'array to keep track of what's been asked declare track[] = {1,1,1,1,1,1,1,1,1,1}
score = 0
function Sum() local s = 0 for i = 1 to N incr s, track[i] next i return s end function
print "---------------------" print "STRING FUNCTIONS QUIZ" print "---------------------"
while 1 do 'get a random question. Check that not all questions 'have been asked, if they have, quit, otherwise generate 'random numbers until you get one which hasn't already 'been picked. if Sum() = 0 then print "Your score is: ", score end else repeat x = random(N) + 1 until track[x] = 1 end if label again 'print the random question print qu$[x] input "Your answer (or q to quit): ", answer$ answer$ = lcase$(answer$) 'one of 3 things can happen: 1) you choose to quit, 'in which case print the score and END. 2) your 'answer is correct, in which case print a message, 'add 1 to the score, and set the corresponding element 'of the track array to zero so that the same 'question isn't asked again. 3) your answer is 'wrong, in which case print a message, decr the 'score and go back to printing the question and 'prompting for the answer etc. if answer$ = "q" then print "Your score is: ", score end elif answer$ = ans$[x] then print "correct!" incr score 'remove the question if track[x] = 1 then decr track[x] else print "Wrong answer - try again!" decr score goto again end if wend
I tried to remove the questions which had already been asked directly, with qu[x] = "", which is when I got the error. As you say, it doesn't seem unreasonable to expect this to work, but no big deal. @ vovchik, Nice avatar, thanks!
|
|
|
Post by vovchik on Dec 6, 2014 20:29:39 GMT 1
Dear bitvast, I would restore the code to uppercase for the reasons Peter says. Having keywords capped, apart from avoiding countless problems with imported function names and reserved expressions, makes the BaCon code easier to read. CAPS is the default for BaCon keywords and has been for years. And lowercase is fraught with little potential problems that will not be readily understood by beginners. Something will bomb at some point, and they will probably think it is BaCon's fault. It's your site, of course, and your call, but I would, for purposes of illustrating the code, stick with uppercase. With kind regards, vovchik PS. Thanks...avatars are fun. I just added a pseudo-3D version of your original. Attachments:
|
|
|
Post by bitvast on Dec 7, 2014 9:31:20 GMT 1
Hi vovchik, I'm going to take your advice seriously. I switched to lowercase because the code font was too large and I wasn't able to change it, so I thought lowercase would look better. A possible alternative can be found here. Font size can be changed and there is an option to use line numbers so it will be easier to refer to parts of the code. Thanks for the new version of the avatar. As you can see, I've replace the original with it. Do you do all this graphical work in the Gimp? I always found it not very user friendly.
|
|
|
Post by vovchik on Dec 7, 2014 12:34:36 GMT 1
Dear bitvast,
I'm glad you like the icons. I use my own Pikona to create them, and the process takes about 30 seconds per icon. I have a dir of backgrounds, a dir of objects and a dir of overlays. Pikona can scale the object and put all the images together - and voila! It is really easy to create a complete and uniform icon set if you have the objects you need. Peter posted a version on the BaCon home page, but it might be old. When I switched to Mint, I had to recompile it and remember that I had to change a few vars (global/local conflicts). Also, the MD5 hash stuff for creating thumbnails in the file selector seems not to be working as it should - at least in Mint - but that is no big deal. One day I will fix that. Pikona now uses only GTK and GDK, so there are no unusual external dependencies to speak of. As for GIMP, it is great, but the learning curve is pretty steep.
With kind regards, vovchik
|
|
|
Post by Pjot on Dec 7, 2014 16:30:29 GMT 1
Hi bitvast, Well, you can use small letters, but just make sure the symbols you use do not conflict with existing BaCon symbols. For the directly assigned string arrays, modifying members should be possible now in the latest beta. BR Peter
|
|
|
Post by vovchik on Dec 7, 2014 19:13:18 GMT 1
Dear Peter, Thanks for the feature. I hope it was not too much work. I tested it and it seems to work as you describe, so everybody should be happy. With kind regards, vovchik
|
|
|
Post by bitvast on Dec 7, 2014 21:22:05 GMT 1
Hi Peter, Thanks so much, it works beautifully. Like vovchik, I hope it didn't involve too much effort.
|
|