Not sure what value this is, but...

Post Reply
User avatar
sarossell
Posts: 195
Joined: Sat Nov 05, 2016 6:31 pm
My devices: iPad Mini 2, iPhone 5, MacBook Air, MacBook Pro
Flag: United States of America
Contact:

Not sure what value this is, but...

Post by sarossell »

You can apparently define a function using the underscore character. Weird, huh?

I was looking for a way to shorthand multiple PRINT statements and Mr. K turned me on to the idea of creating a function P() to do so. I didn't care for the P, so I tried a bunch of other symbols. Nothing else worked - even emojis, but the underscore (_) did. In hindsight it makes sense since it can be part of a function name like "My_Function()". Another weird option is using a period and underscore "._()" as a function name. Crazy huh? :D

Code: Select all

PRINT "Line 1"!_(5)!PRINT "Line 2"  'Notice the function "_(5)"
def _(x)
	FOR n = 1 to x
		PRINT
	NEXT n
ENDDEF
smart BASIC Rocks!

- Scott : San Diego, California

User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

Re: Not sure what value this is, but...

Post by GeorgeMcGinn »

If you start any variable with a period, it becomes similar to a global variable. It's part of the scoped variables.

I've never thought of using an underscore in front of functions, or even variables.

Interesting...

George.
sarossell wrote:You can apparently define a function using the underscore character. Weird, huh?

I was looking for a way to shorthand multiple PRINT statements and Mr. K turned me on to the idea of creating a function P() to do so. I didn't care for the P, so I tried a bunch of other symbols. Nothing else worked - even emojis, but the underscore (_) did. In hindsight it makes sense since it can be part of a function name like "My_Function()". Another weird option is using a period and underscore "._()" as a function name. Crazy huh? :D

Code: Select all

PRINT "Line 1"!_(5)!PRINT "Line 2"  'Notice the function "_(5)"
def _(x)
	FOR n = 1 to x
		PRINT
	NEXT n
ENDDEF
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

User avatar
sarossell
Posts: 195
Joined: Sat Nov 05, 2016 6:31 pm
My devices: iPad Mini 2, iPhone 5, MacBook Air, MacBook Pro
Flag: United States of America
Contact:

Re: Not sure what value this is, but...

Post by sarossell »

Yeah, you can even make it a one-off:

Code: Select all

print "Hello"!_!_!_!print "There"
Def _!Print!Enddef
smart BASIC Rocks!

- Scott : San Diego, California

Post Reply