Author Topic: DEF FNname (GWBASIC-style functions)  (Read 5448 times)

Pete

  • Moderator
  • Hero Member
  • *****
  • Posts: 6240
  • Cuz I sez so varmint!
Re: DEF FNname (GWBASIC-style functions)
« Reply #15 on: June 12, 2010, 11:52:20 AM »
What I see is a gap between people who have already "moved on" and people who have quit programming or who are end users who discover this project in the hopes their old software will rise from the grave. So either there is insufficient interest to convert old programs, or there is a lack of ability to try and convert them with faith in an eventual outcome.

What I think this project needs is a expanded core of users who still wish to program in BASIC or want to learn BASIC. Where to find those people should be the main focus of the project. This is why I agree with the addition of the new keywords, to get new users, instead of just old ones. The addition of new features will make QB64 a coding choice, rather than just a way to run old programs on new machines.

I try to meet Galleon half way, when I can. I converted all my multi-modular programs and DEF Fn statements. That probably took 100 hours of work to do, not so bad, especially when considering DEF FN is not yet implemented, and multi-modular support is not even a topic anymore. I'm fine with that, as DEF FN was fairly easy to convert, and I made and posted a method to convert multi-modular programs, while I was converting mine. I also know there would be very few QB programmers that use multi-modular programming, anyway and statements like ON KEY and LPRINT would be more pressing. I an thankful for the LOCK, UNLOCK work. I do think that and TCP/IP support are needed for the future, as all devices are being geared to accessing each other, that, and "cloud" computing. And what I really appreciate about Rob is that he does try to accommodate our requests for features we need to keep converting our programs.

I'm still in the FTC mindset though and  I wish once per quarter a new release would contain the next prioritized statement from this sub-forum menu, until all the compiler compatibility work is done, but those are just my feelings, which are void of responsibility. I worry about Galleon, that one day he might end up in an asylum with his nails bit down to the quick and muttering things like, "The compiler, no, the IDE, no, the new keywords, the WIKI, the forum, ahhhhhh!"

DEF FNitely something to consider,

Pete

It's only rocket science; it's not Linux!

Clippy

  • Hero Member
  • *****
  • Posts: 16431
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: DEF FNname (GWBASIC-style functions)
« Reply #16 on: June 17, 2010, 02:09:41 PM »
What we need are more complainers. I think I hounded Galleon about CHAIN until it was done. That worked. You got RUN going!

Unfortunately, many people keep quiet and just observe. I wish they would get more involved. We could use some more suggestions from users.

I'm hoping to get PRINT USING expanded for new formatting options like VB has.

Ted
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

toml_12953

  • Jr. Member
  • **
  • Posts: 86
    • Email
Re: DEF FNname (GWBASIC-style functions)
« Reply #17 on: August 13, 2010, 07:51:41 AM »
Quote from: Pete on June 12, 2010, 11:52:20 AM
What I see is a gap between people who have already "moved on" and people who have quit programming or who are end users who discover this project in the hopes their old software will rise from the grave. So either there is insufficient interest to convert old programs, or there is a lack of ability to try and convert them with faith in an eventual outcome.
Pete

One "feature" of DEF FN:  Any variable not in the parameter list is GLOBAL! 

DEF FNA(X) = B * X
B=3
PRINT FNA(5)

will print 15 in QBasic.  Just something to keep in mind when implementing it.

Tom L

codeguy

  • Hero Member
  • *****
  • Posts: 3552
  • what the h3ll did i name that code?
    • stuff at dkm
    • Email
Re: DEF FNname (GWBASIC-style functions)
« Reply #18 on: August 13, 2010, 08:38:20 AM »
but then that means making ALL variables global or handing them in a special way when it comes to FN, which i think is a disastrous thing indeed (i smell code bloat again for a questionably (imho, of course) marginal benefit). some variables i intend to be global (by dim shared or const) and others i strictly prefer them to be and remain local. maybe if FN comes up against a variable it doesn't recognize, it can just use the ones not declared by DIM SHARED (that is in MAIN program data segment).
http://denteddisk.forums-free.com/make-an-appointment-with-the-resident-code-guru-f34.html

Clippy

  • Hero Member
  • *****
  • Posts: 16431
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: DEF FNname (GWBASIC-style functions)
« Reply #19 on: August 13, 2010, 12:49:52 PM »
DEF Fn is made for lazy one line functions. It has few redeeming qualities as it can not be used recursively. Might as well make a real function.
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

Pete

  • Moderator
  • Hero Member
  • *****
  • Posts: 6240
  • Cuz I sez so varmint!
Re: DEF FNname (GWBASIC-style functions)
« Reply #20 on: August 13, 2010, 06:44:46 PM »

Serious QB coders use DEF FN to save precious code space. Lazy QB programmers use CHAIN.  ;D

Pete
It's only rocket science; it's not Linux!

DarthWho

  • Hero Member
  • *****
  • Posts: 3853
  • Timelord of the Sith
Re: DEF FNname (GWBASIC-style functions)
« Reply #21 on: December 05, 2010, 01:35:41 PM »
thanks for getting rid of the bot galleon ;D
« Last Edit: December 07, 2010, 11:29:48 AM by DarthWho »
Rassilon: My lord Doctor; My lord Master; My lord DarthWho
The Doctor and the master at the same time :WHAT!?!?!

FastMath 1.1.0 released: http://dl.dropbox.com/u/12359848/fastmath.h

Clippy

  • Hero Member
  • *****
  • Posts: 16431
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: DEF FNname (GWBASIC-style functions)
« Reply #22 on: September 14, 2011, 03:28:48 PM »
Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.


I CAN'T MAKE a new topic! AFLAC!  ;D

Quote from: Pete on August 13, 2010, 06:44:46 PM

Serious QB coders use DEF FN to save precious code space. Lazy QB programmers use CHAIN.  ;D

Pete

PRECIOUS CODE SPACE! And LOSE HUNDREDS of FN variable names! I hope Galleon takes that into consideration! You only need a FEW extra keywords

FUNCTION   instead of DEF FN

END FUNCTION

That IS NOT worth losing hundreds of variable names FOREVER! Hundreds of QB64 programs will start SPEWING ERRORS! What I would do is make it so that FN variable names can be used that are NOT defined in a DEF FN statement. That would solve the problem!        

Besides, QB64 should NEVER CRY about space... :'(      
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

Barrykgerdes

  • Full Member
  • ***
  • Posts: 249
    • Email
Re: DEF FNname (GWBASIC-style functions)
« Reply #23 on: September 20, 2011, 02:29:35 PM »
DEF Fn is a handy way of reducing code size when programming in Basic/Qbasic, particularly  complex mathmatical routines. However it is not an insurmountable problem in making Qbasic code compatible with Qb64 code and is only needed in Qb64 for compatability problems.

With complex Functions you can quite easily replace the call with the complete routine or a sub routine.
With simple functions eg DEF FNM(w) = w* .01745329252  the conversion of degrees to radians.
Delete the DEF and do a change all "FNM* to "FNM * " and make the Variable FNM=.01745329252  The problem here is that FNM is OK as a variable in QB64 but is a reserved word in Qbasic so you do another change all and make FNM into something else. Of course this could have been done at the first "change all"

Barry

Clippy

  • Hero Member
  • *****
  • Posts: 16431
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: DEF FNname (GWBASIC-style functions)
« Reply #24 on: September 20, 2011, 02:38:34 PM »
QB64 "could" RESERVE function names defined in DEF FN statements and allow those FN names when they are not defined. Qbasic reserved ALL variable names beginning with FN. QB64 shouldn't have to!
« Last Edit: September 20, 2011, 02:46:52 PM by Clippy »
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

kidfrommars

  • Full Member
  • ***
  • Posts: 215
    • C & Fortran Polyglot
Re: DEF FNname (GWBASIC-style functions)
« Reply #25 on: September 20, 2011, 03:51:41 PM »
Quote from: Clippy on September 20, 2011, 02:38:34 PM
QB64 "could" RESERVE function names defined in DEF FN statements and allow those FN names when they are not defined. Qbasic reserved ALL variable names beginning with FN. QB64 shouldn't have to!

I agree.

desA

  • Newbie
  • *
  • Posts: 2
Re: DEF FNname (GWBASIC-style functions)
« Reply #26 on: January 15, 2012, 05:23:09 AM »
Not overly sure what all the fuss is about. (New fogie on the block)

DEF FNW(A)=blah*A ...

Becomes

Code placed at end of program - using insert Function command. Also declare global variables required upfront.

FUNCTION W(A) : W = blah*A ... : END FUNCTION

After this, use W(A) as required... A tad longer to declare the function, but less hassle within the code calling the function.

Just converted a 23-year old QBASIC 4.0 program last evening. Seems to work a treat, thus far. I'm most grateful for QB64, I must say.

Clippy

  • Hero Member
  • *****
  • Posts: 16431
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: DEF FNname (GWBASIC-style functions)
« Reply #27 on: January 15, 2012, 08:32:17 AM »
The "fuss" is that old programs use DEF FN often. Fortunately most were GW Basic programs.

LOSING FN variable names would be a KILLER at this point in QB64's progress.
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

DSMan195276

  • Hero Member
  • *****
  • Posts: 1978
  • Yes
    • Email
Re: DEF FNname (GWBASIC-style functions)
« Reply #28 on: January 15, 2012, 09:51:39 AM »
Quote from: Clippy on January 15, 2012, 08:32:17 AM
The "fuss" is that old programs use DEF FN often. Fortunately most were GW Basic programs.

LOSING FN variable names would be a KILLER at this point in QB64's progress.

I don't see why we'd have to lose FN variable names. I mean, we can have FN functions and FN variables, I don't see why DEF FN would mess that up (Especially if it just gets converted to a proper function).

Now what would make DEF FN worth wild for using is if a one-line DEF FN could be added directly into the code for some optimization. Not sure how much overhead is caused by calling a FUNCTION, but if you could do something like this:

Code: [Select]
DEF FNnum(x) = sin(x * 2) + 4 'random function

print FNnum(21);
end
A normal function would be converted into something like this(Very crude example, but it gets the point across):
Code: [Select]
#include <stdio.h>
#include <math.h>
using namespace std;
int main(){
  cout << FNnum(21);
  cout << "\n Press any key to continue...";
  cin.get();
  return 0;
}
double FNnum(int x){
  return sin(x * 2) + 4;
}
But the DEF FN could be converted something like this:
Code: [Select]
#include <stdio.h>
#include <math.h>
using namespace std;
int main(){
  cout << sin(21 * 2) + 4;
  cout << "\n Press any key to continue...";
  cin.get();
  return 0;
}

Having DEF FN do some optimization like that could help speed things up since DEF FN functions were pretty almost always related to math. If I remember right there were multiple line DEF FN statements, but that's no big deal since if it goes into multiple lines then you can just treat it like a normal FUNCTION.

Matt
"Cast your cares on the Lord and he will sustain you; he will never let the righteous be shaken" -- Psalm 55:22
QB64 Linux Installer

Clippy

  • Hero Member
  • *****
  • Posts: 16431
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: DEF FNname (GWBASIC-style functions)
« Reply #29 on: January 15, 2012, 10:38:04 AM »
Quote
Now what would make DEF FN worth wild for using is if a one-line DEF FN could be added directly into the code for some optimization.

worth while...?

Anyhow, Qbasic made a big deal out of FN variable names. We shouldn't have that problem if QB64 can work around that. I would NEVER use FN to "optimize" anything! Calculate the stuff if you only use it once. Otherwise use a FUNCTION. Then it is optimized for multiple uses.

Apparently FN has been put on hold...

QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip