BaCon CALL documentation error?
BaCon CALL documentation error?
According to http://www.basic-converter.org/documentation.html#CALL
CALL
"...calls a subroutine if the sub is defined at the end of the program."
I found this to be incorrect - it only seems to work if the SUB is defined at the start of the program (and it does not seem to be required in that case anyway).
Just in case anyone else is banging their head against a wall with this as I've just done for an hour (the compiler log message wasn't very helpful in my case).
Paul
CALL
"...calls a subroutine if the sub is defined at the end of the program."
I found this to be incorrect - it only seems to work if the SUB is defined at the start of the program (and it does not seem to be required in that case anyway).
Just in case anyone else is banging their head against a wall with this as I've just done for an hour (the compiler log message wasn't very helpful in my case).
Paul
Dear Paul,
CALL is used if an invocation is made prior to the definition of the SUB. For all practical purposes, you should program like in Pascal, defining your global vars, doing imports, writing your SUBs and FUNCTIONs and then calling a "MAIN". It will make life easier and the code much more readable after, say, three months.
With kind regards,
vovchik
PS. And then very little need for CALL. Sometimes yes, but mostly no.
CALL is used if an invocation is made prior to the definition of the SUB. For all practical purposes, you should program like in Pascal, defining your global vars, doing imports, writing your SUBs and FUNCTIONs and then calling a "MAIN". It will make life easier and the code much more readable after, say, three months.
With kind regards,
vovchik
PS. And then very little need for CALL. Sometimes yes, but mostly no.
PaulR; Everything you type is checked to be sure it lines up with what it does.
The program has to read the SUB/FUNCTION first or the main code calling it has nothing to call.
Even Bash throws an error if you call a function before the function is read.
You get an error if a string variable is used without setting it first.
A string variable does not default to "", it equals "null" ( not the same ).
So set new strings you are going to use "empty": NewStr$ = ""
Integers default to 0, which is nice as you don`t need to set them first to use them.
And I think all the number types default to 0, but I have not checked this out... vovchik.?
.
The program has to read the SUB/FUNCTION first or the main code calling it has nothing to call.
Even Bash throws an error if you call a function before the function is read.
You get an error if a string variable is used without setting it first.
A string variable does not default to "", it equals "null" ( not the same ).
So set new strings you are going to use "empty": NewStr$ = ""
Integers default to 0, which is nice as you don`t need to set them first to use them.
And I think all the number types default to 0, but I have not checked this out... vovchik.?
.
vovchik; A Q if I could.
I`m writing a general purpose GUI maker.
It reads a file for commands to make the GUI.
It then needs another file for the click events.
My problem is you can`t use variables to specify include files.
For the GUI maker to be truly useful it has to be like GtkDialog and be reusable.
So different GUI files need event files named for that GUI file.
/path/FileName.gui
/path/FileName.clk
The other problem is that you can`t use text read from a file for BaCon code.
Here`s the GUI file, very simple and quick to write ( unlike GtkDialog ):
# So no including a dynamically named file, and text can`t be used for code.
I think you see the problem. If you really want to see the code just say so.
.
I`m writing a general purpose GUI maker.
It reads a file for commands to make the GUI.
It then needs another file for the click events.
My problem is you can`t use variables to specify include files.
For the GUI maker to be truly useful it has to be like GtkDialog and be reusable.
So different GUI files need event files named for that GUI file.
/path/FileName.gui
/path/FileName.clk
The other problem is that you can`t use text read from a file for BaCon code.
Here`s the GUI file, very simple and quick to write ( unlike GtkDialog ):
Code: Select all
win mkDlgs Demo.
lbl This is a demo. of mkDlgs
lbl Look at the file mkDlgs.gui
lbl It has the GUI instructions.
sepLine
cmbOptions
btnCombo Which Combo Item is Selected?
sepLine
chkTest This is a Check Box.
btnCheck Is Check Box on or off?
entText This is a text Entry Box.
btnEntry Print Contents of Entry Box.
btnEnd Close
I think you see the problem. If you really want to see the code just say so.
.
Last edited by sunburnt on Fri 05 Apr 2013, 08:37, edited 2 times in total.
Dear Terry,
I have also thought that it would be convenient to do this:
and have a little program generate the code. I would pass the ascii gui text and the actions files on the command line as two arguments and have the gui designer then spit out the code. Food for thought...
With kind regards,
vovchik
PS. Or one ascii text file containing the mockup in ascci plus the actions, suitably marked.
I have also thought that it would be convenient to do this:
Code: Select all
+-----------+
|bla bla bla|
|bla bla bla|
|..[[ OK ]].|
+-----------+
With kind regards,
vovchik
PS. Or one ascii text file containing the mockup in ascci plus the actions, suitably marked.
I thought of that too, but text could only call a predetermined set of actions.
IF the line is XXX THEN call SUB.
How can text be made to be usable commands to Bacon?
The very best would be able to include the event file.
So then all of the the events would have to be in one file, not the best setup.
Or one included file could include many different event files, only all of them.
Bash has many capabilities that Basic doesn`t even come close to.
It`s horribly limiting... Almost a stunted language.
vovchik; If I`ve missed something that solves this, please give me an example.
IF the line is XXX THEN call SUB.
How can text be made to be usable commands to Bacon?
The very best would be able to include the event file.
So then all of the the events would have to be in one file, not the best setup.
Or one included file could include many different event files, only all of them.
Bash has many capabilities that Basic doesn`t even come close to.
It`s horribly limiting... Almost a stunted language.
vovchik; If I`ve missed something that solves this, please give me an example.
Sorry to bring this back on topic
Here's the original problem. Main code followed including a CALL to the SUB defined after the main code, which according to the docs should work as I first posted:
CALL - "...calls a subroutine if the sub is defined at the end of the program."
The compiler complains:
Which I don't understand. Is there some other error in my program or are the docs wrong? In any event, re-arranging the code as I would in C or Pascal such that the functions etc come first everything works ok
Paul
Here's the original problem. Main code followed including a CALL to the SUB defined after the main code, which according to the docs should work as I first posted:
CALL - "...calls a subroutine if the sub is defined at the end of the program."
Code: Select all
OPEN "." FOR DIRECTORY AS mydir
REPEAT
GETFILE myfile$ FROM mydir
IF myfile$ != "." AND myfile$ != ".." THEN
IF RIGHT$(myfile$, 4) = ".txt" THEN
CALL parseFile(myfile$)
ENDIF
END IF
UNTIL ISFALSE(LEN(myfile$))
CLOSE DIRECTORY mydir
END
SUB parseFile(STRING fileName$)
'code here
ENDSUB
Code: Select all
/usr/lib/gcc/i486-slackware-linux/4.7.1/../../../../i486-slackware-linux/bin/ld:./read_files_dirs.bac.parseFile.tmp: file format not recognized; treating as linker script
/usr/lib/gcc/i486-slackware-linux/4.7.1/../../../../i486-slackware-linux/bin/ld:./read_files_dirs.bac.parseFile.tmp:3: syntax error
collect2: error: ld returned 1 exit status
Paul
Dear Paul,
The following works for me (try adding a newline to the end of your code), although the STANDARD BaCon way would be to put the SUB first and then the main:
BaCon could be coughing because of something in your SUB code.
With kind regards,
vovchik
The following works for me (try adding a newline to the end of your code), although the STANDARD BaCon way would be to put the SUB first and then the main:
Code: Select all
OPEN "." FOR DIRECTORY AS mydir
REPEAT
GETFILE myfile$ FROM mydir
IF myfile$ != "." AND myfile$ != ".." THEN
IF RIGHT$(myfile$, 4) = ".plx" THEN
CALL parseFile(myfile$)
END IF
END IF
UNTIL ISFALSE(LEN(myfile$))
CLOSE DIRECTORY mydir
END
SUB parseFile(STRING fileName$)
'code here
PRINT fileName$
END SUB
With kind regards,
vovchik
Hi vovchik
Very odd. I added a newline to my code and the compiler falls over as before. I copy/pasted your example and it had the same problem. I added a newline to your code an it compiles fine!
I'll stick to the conventional layout in future
At least I know I wasn't banging my head against the wall because of a mistake I'd made (for a change!).
Best regards
Paul[/b]
Very odd. I added a newline to my code and the compiler falls over as before. I copy/pasted your example and it had the same problem. I added a newline to your code an it compiles fine!
I'll stick to the conventional layout in future
At least I know I wasn't banging my head against the wall because of a mistake I'd made (for a change!).
Best regards
Paul[/b]
- L18L
- Posts: 3479
- Joined: Sat 19 Jun 2010, 18:56
- Location: www.eussenheim.de/
BaCon CALL documentation error?
http://murga-linux.com/puppy/viewtopic. ... &start=477PaulR wrote:....I added a newline to your code an it compiles fine!....
BaCon NEW LINE documentation error
Dear Paul,
I use Geany, and it shows most of those weird chars as squares with some numbers inside. Save the code back as UNICODE-UTF8 and with Unix line endings (under the Document menu in Geany). Or cat the code to a terminal and copy from there. I have often seen weird chars in code coming from the DOS/M$ world. Usually, that stuff just needs to be removed/obliterated via search and replace.
With kind regards,
vovchik
I use Geany, and it shows most of those weird chars as squares with some numbers inside. Save the code back as UNICODE-UTF8 and with Unix line endings (under the Document menu in Geany). Or cat the code to a terminal and copy from there. I have often seen weird chars in code coming from the DOS/M$ world. Usually, that stuff just needs to be removed/obliterated via search and replace.
With kind regards,
vovchik
sunburnt, I'm not sure if this would help but here goes:
You could put your commands in a plain text file, parse that file and write it out in BaCon source form then invoke Bacon to compile it.
For example, command.txt containing this line
label Type of cheese
is parsed and written into the file myprog.bac as
label123=MARK("Type of cheese"), 50, 100)
where '123', '50' and '100' are either included in the command.txt or calculated in the parser. (If you're including them in the source you might as well just write the program though I suppose!).
You could then execute 'bacon myprog.bac' - you'd end up with an executable built from a simple text only command file.
You could expand the technique to add your event handlers so a line in command.txt like;
button OK, confirmAction
would create the button, attach the sub confirmAction and copy/paste the confirmAction section from your click.txt file into myprog.bac.
Paul
You could put your commands in a plain text file, parse that file and write it out in BaCon source form then invoke Bacon to compile it.
For example, command.txt containing this line
label Type of cheese
is parsed and written into the file myprog.bac as
label123=MARK("Type of cheese"), 50, 100)
where '123', '50' and '100' are either included in the command.txt or calculated in the parser. (If you're including them in the source you might as well just write the program though I suppose!).
You could then execute 'bacon myprog.bac' - you'd end up with an executable built from a simple text only command file.
You could expand the technique to add your event handlers so a line in command.txt like;
button OK, confirmAction
would create the button, attach the sub confirmAction and copy/paste the confirmAction section from your click.txt file into myprog.bac.
Paul
Thanks Paul; But you can`t use a variable for a callback like this:
All Bacon commands, callbacks, and array dimensions have to be literals.
Where as in Bash you can use a variable for just about anything.
And you can`t make the event code into an exec. file either.
It may need to manipulate the controls in the main GUI.
Both the GUI and event files need to be simple text files.
Code: Select all
CALLBACK(widgetID_, callSUB$)
Where as in Bash you can use a variable for just about anything.
And you can`t make the event code into an exec. file either.
It may need to manipulate the controls in the main GUI.
Both the GUI and event files need to be simple text files.