Page 1 of 1

Not sure what value this is, but...

Posted: Sun Jan 01, 2017 7:32 am
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

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

Posted: Tue Jan 03, 2017 2:23 am
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

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

Posted: Tue Jan 03, 2017 2:33 am
by sarossell
Yeah, you can even make it a one-off:

Code: Select all

print "Hello"!_!_!_!print "There"
Def _!Print!Enddef