Feature requests « Thread Started on Nov 14, 2010, 10:54am »
I am new to BaCon. These are some thoughts on extra features that would be nice...
BREAK [number] Just like in Bash, an optional integer number to break up any level when in nested loops.
CONTINUE [number] Some BASICs have this, Bash has it, well, lots of languages have it. Goes to the start of the current loop. Again, I suggest an optional integer argument.
Note, I just looked at freeBASIC, they have gone their own way on the above, for example, this is the equivalent of 'BREAK 2':
For i = 1 To 10 For j = 1 To 10 Exit For, For Next j Print "I will never be shown" Next i
...not as simple.
COMMAND To get the commandline parameters passed to the application.
EXEC on steroids It would be very useful if you could extend one of these with extra keywords to support stdin and stdout and the return-value. For example, here is some C code that executes a shell to find out how many instances of application 'pupmem' are running:
Joined: Apr 2010 Gender: Male Posts: 938 Location: The Hague, The Netherlands Karma: 9
Re: Feature requests « Reply #2 on Nov 14, 2010, 12:27pm »
Hi Barry,
The BREAK and CONTINUE requests will be quite hard to implement but I'll look at it. Currently there is no CONTINUE at all so that one can be added anyway.
For EXEC, what do you mean with 'returnvalue'? Probably the returnvalue of the actual command, right? (In BASH shell scripting this is denoted with $? - I guess you refer to this?)
If you mean this returnvalue, what would be the returnvalue of a string like: EXEC("ls -l; cd /tmp; rm *.*") ? Would we see the returnvalue of the 'rm' as this one is executed last?
EXEC it is a function so the syntax will be something like this: EXEC("command", [stdin [, returnvalue]]). So the last two will be optional.
Re: Feature requests « Reply #3 on Nov 15, 2010, 12:32am »
Peter, Yes, this would be great:
EXEC("command", [stdin [, returnvalue]])
Yes, by return value I mean the integer numeric return status when an application exits, which in Bash you get with $?.
But you are mostly likely to need returnvalue, so this would perhaps be better:
EXEC("command" [,returnvalue [,stdin]])
Adding both of these to EXEC would make it so powerful.
The stdin gives us a mechanism to feed some value into the shell from the BaCon application.
Another thing that would be nice, but this is probably asking too much, is if the "command" string could be made to recognise BaCon variables. For example:
EXEC("demoapp ${variable1}")
where variable1 is an actual variable in BaCon.
...maybe that is too hard though, as it might require run-time evaluation of the command string. Well, I suppose BaCon could be made to recognise the special syntax "${variable1}" and perform a runtime substitution.
The reason that I request all of these enhancements to EXEC is that I am so familiar with Bash/Ash and when coding in a high-level language I can often see how to solve a particular task very quickly in one line of Bash, whereas it is not so easy for me in that high-level language.
So, all the enhancements requested above would make the insertion of shell code into the BaCon program very powerful.
Re: Feature requests « Reply #4 on Nov 15, 2010, 12:38am »
If you mean this returnvalue, what would be the returnvalue of a string like: EXEC("ls -l; cd /tmp; rm *.*") ? Would we see the returnvalue of the 'rm' as this one is executed last?
Yes, exactly as if you did it in Bash:
ls -l; cd /tmp; rm *.* echo $?
...whatever return-value the command string finishes with.
Joined: Apr 2010 Gender: Male Posts: 938 Location: The Hague, The Netherlands Karma: 9
Re: Feature requests « Reply #5 on Nov 15, 2010, 1:38am »
Thanks Barry, understood it all now.
Currently I have a prototype running for the BREAK [x] request, but I want to do more testing before uploading it to the BETA directory.
If this works then CONTINUE [x] will be easy.
(BTW I only know these commands with argument from Shell scripting, none of the BASIC's I have worked with in the past supports them, as far as I remember. But they are handy for sure!)
The EXEC$ argument order can of course change to first STDIN and then returnvalue.
Not as convenient as you are suggesting, but I use it all the time and it works nicely.
The BREAK/CONTINUE and stdin/returncode business for EXEC$ do appear to be useful. Peter has knack for being able to implement the seemingly impossible!
Re: Feature requests « Reply #7 on Nov 16, 2010, 8:47am »
(BTW I only know these commands with argument from Shell scripting, none of the BASIC's I have worked with in the past supports them, as far as I remember. But they are handy for sure!)
...I mentioned freeBASIC, but they do it with their own unusual syntax.
There is one other I know of that does it exactly as in Bash: PureBasic:
Joined: Apr 2010 Gender: Male Posts: 938 Location: The Hague, The Netherlands Karma: 9
Re: Feature requests « Reply #10 on Nov 18, 2010, 7:58am »
So EXEC$ is on its way - the STDIN part is ready, it took a little bit more time than I expected.
The returnvalue of a child process is still not there because one simply cannot pass a variablename as argument to a function, as C does not do runtime conversion of memory buffers.
Therefore, I was thinking of assigning a reserved variable for the returnvalue of the last command which was executed (both by SYSTEM or EXEC$), similarly to BASH. For example, simply the variable RV, or something like that.
Anyway, now EXEC$ has an optional second argument which can be the feed to STDIN of the command executed in the shell. So for now the syntax is:
a$ = EXEC$("command" [, "stdin"])
I have tested this with the 'bc' calculator language, as follows: