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

#### DSMan195276

• Hero Member
• Posts: 1978
• Yes
##### Re: DEF FNname (GWBASIC-style functions)
« Reply #30 on: January 15, 2012, 11:12:44 AM »
Quote from: Clippy 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...

Sorry, bad grammar on my part, it should have said:
Quote
Now what would make DEF FN worth wild to use is if a one-line DEF FN could be added directly into the code for some optimization.

QBasic made a big deal out of them but it really didn't need to. I imagine it did that just to keep people from being confused from what is a DEF FN and what is a variable starting with FN.

And I don't think you understand what I meant by optimize, take this example:

Code: [Select]
`DEF FNcalc(x) = x ^ 2 + 2m = 4PRINT FNcalc(m);end`
Basically the idea is that 'm' is some variable that is going to change, or IE can't be hard-coded in. And FNcalc does some calculation that you might want to change at some point. The code would then be converted into:

Code: [Select]
`m = 4PRINT m ^ 2 + 2;end`
And by doing that it takes away the overhead of calling the function, but you still have the flexibility of being able to change it if you need.

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 >>>
##### Re: DEF FNname (GWBASIC-style functions)
« Reply #31 on: January 15, 2012, 11:28:18 AM »
Well the whole point of supporting DEF FN is for old Qbasic programs. I would not encourage people to use it in new code, but they could. I'm not crazy about GOSUB either but I've used it at times when I was lazy...

There is an innate problem when you use sub-procedures that don't require parameters. ANY variable value can be used in any procedure and name duplication must be avoided. The same thing can happen when you use SHARED for everything. You can make more errors that are harder to find.
« Last Edit: January 15, 2012, 11:40:09 AM by Clippy »
QB64 WIKI: Main Page

#### DeeBee

• Sr. Member
• Posts: 491
##### Re: DEF FNname (GWBASIC-style functions)
« Reply #32 on: January 15, 2012, 06:25:53 PM »
Unless I'm missing something, you do not need DEF FN.

The ONLY reason there is a DEF FN is because it was implemented before
there were SUB and FUNCTION statements.
(and it is an old (almost 'original', but not quite) BASIC legacy implementation)

ANYTHING that can be done using DEF FN can be used with FUNCTION now.

And it's not even a difficult mod to make. (it's what I've always done, even when
DEF FN was implemented, because, imo, DEF FN is deprecated (or should be), along with GO/TO/SUB)

I guess if Galleon wanted to get 'fancy', he could just wrap any DEF FN statements
into their FUNCTION equivalent, and I don't think anyone would notice any difference.

#### SkyCharger001

• Hero Member
• Posts: 1594
##### Re: DEF FNname (GWBASIC-style functions)
« Reply #33 on: January 16, 2012, 08:32:05 AM »
from what I've seen DEF FN can be seen as a macro-statement. (a macro-call tells the pre-compiler to replace the call with the code defined by the macro)

#### Clippy

• Hero Member
• Posts: 16431
• I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
##### Re: DEF FNname (GWBASIC-style functions)
« Reply #34 on: January 16, 2012, 08:42:48 AM »
Either way I am hoping that Galleon can just exclude the use of the DEF function FN name as a variable only after it is defined.
QB64 WIKI: Main Page

#### Cyperium

• Hero Member
• Posts: 3285
• Knowledge is good, but understanding is better
##### Re: DEF FNname (GWBASIC-style functions)
« Reply #35 on: February 08, 2012, 05:38:49 AM »
I agree, there's no point in loosing all the FN variables, QB probably didn't loose them either without putting up a fight so if QB64 can keep them then that would be more BASIC than QB could achieve.
Venture - New Prototype, QB64 Editor v1.95b (linux compatible, if you compile the source).

#### Clippy

• Hero Member
• Posts: 16431
• I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
##### Re: DEF FNname (GWBASIC-style functions)
« Reply #36 on: February 08, 2012, 09:54:13 AM »
A fight?

As I recall you couldn't start ANY variable names with FN. Fname\$...for firstname\$ or filename\$

Then it gave you an OBTUSE "Duplicate definition" error that made it EVEN HARDER to figure what was wrong when you used it more than once and tried to run it!
« Last Edit: February 08, 2012, 09:59:35 AM by Clippy »
QB64 WIKI: Main Page

#### codeguy

• Hero Member
• Posts: 3552
• what the h3ll did i name that code?
##### Re: DEF FNname (GWBASIC-style functions)
« Reply #37 on: February 08, 2012, 10:00:20 AM »
i think def fn should be eliminated as there are FAR better function constructs (namely, FUNCTION: http://qb64.net/wiki/index.php?title=FUNCTION) which is the way i'd prefer to see other programmers do this. that way, we get to keep all the FN variable names and avoid conflicts. those too uninspired, lazy or otherwise to change should maybe consider getting a job programming big iron in cobol. edited to include link to FUNCTION
« Last Edit: February 08, 2012, 10:12:20 AM by codeguy »
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 >>>
##### Re: DEF FNname (GWBASIC-style functions)
« Reply #38 on: February 08, 2012, 10:15:43 AM »
Yeah, but QB64 is SUPPOSED to be compatible with QB4.5. That shouldn't be hard to do!
QB64 WIKI: Main Page

#### codeguy

• Hero Member
• Posts: 3552
• what the h3ll did i name that code?
##### Re: DEF FNname (GWBASIC-style functions)
« Reply #39 on: February 08, 2012, 10:21:54 AM »
yes, all it would involve is expanding the FN macro (which is what it really is) into a c++ function and maybe a bit of smart analysis to see if it really is a function or just simply an FN variable. not too difficult but then i say that from a point of inexperience. or perhaps just removing fn and changing it to a c macro. (modified to include last statement)
« Last Edit: February 08, 2012, 10:52:55 AM by codeguy »
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 >>>
##### Re: DEF FNname (GWBASIC-style functions)
« Reply #40 on: February 08, 2012, 10:32:04 AM »
ONE THING FOR SURE! OLD code won't have ANY variable names with FN  at the beginning!
QB64 WIKI: Main Page

#### Aramis

• Newbie
• Posts: 27
##### Re: DEF FNname (GWBASIC-style functions)
« Reply #41 on: September 26, 2012, 11:53:33 AM »
Y'know, it could be set with a start of code flag...

_\$DEFFN enabling the classic DEF FN mode... but only when needed.

#### Clippy

• Hero Member
• Posts: 16431
• I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
##### Re: DEF FNname (GWBASIC-style functions)
« Reply #42 on: September 26, 2012, 04:07:11 PM »
No, then it wouldn't be compatible with old code! That's the ONLY reason to use it anyhow unless you're really lazy...
QB64 WIKI: Main Page

#### Aramis

• Newbie
• Posts: 27
##### Re: DEF FNname (GWBASIC-style functions)
« Reply #43 on: September 26, 2012, 05:52:44 PM »
Quote from: Clippy on September 26, 2012, 04:07:11 PM
No, then it wouldn't be compatible with old code! That's the ONLY reason to use it anyhow unless you're really lazy...
You can't go a day without insulting people?

One of the best reasons for backward compatibility is the surfeit of old source that can be torn apart by newbs. A top-of code flag is far easier than newbs having to learn to revise the code first.

And easier on grogs who can easily set the top-of-code flag, and get it to compile without revision of the rest of the code.

#### Johny B.

• Sr. Member
• Posts: 486
##### Re: DEF FNname (GWBASIC-style functions)
« Reply #44 on: September 26, 2012, 07:11:01 PM »
Unless I'm missing something here, there isn't any reason to prevent the program using variables that start with fn. After it is defined, why can't the name just be treated as another user-created identifier?
"Time is an illusion; Lunchtime doubly so." - Douglas Adams