Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FUNCTIONS again
#1
If you compile the following code 

FUNCTION A(text as STRING)

Print B("Test")

RETURN 0
END FUNCTION


FUNCTION C(text as STRING)
Print B("Test")
RETURN 0
END FUNCTION

FUNCTION B(text as STRING)
Print ("Test")
RETURN 0
END FUNCTION


you will get
inputmud.bas:137: error: 'B' is neither an array nor a function.
inputmud.bas:135: warning: [W150] Parameter 'text' is never used
inputmud.bas:144: warning: [W100] Using default implicit type 'float' for 'C'
inputmud.bas:144: error: 'B' is neither an array nor a function.
inputmud.bas:143: warning: [W150] Parameter 'text' is never used
inputmud.bas:149: warning: [W100] Using default implicit type 'float' for 'B'
inputmud.bas:148: warning: [W150] Parameter 'text' is never used


but moving function B above like below compiles okay

So I guess it's a TOP Down design where the functions in the same .BAS should be ordered

FUNCTION B(text as STRING)
Print ("Test")
RETURN 0
END FUNCTION
FUNCTION A(text as STRING)

Print B("Test")

RETURN 0
END FUNCTION


FUNCTION C(text as STRING)
Print B("Test")
RETURN 0
END FUNCTION



Great tool

Thanks
Ken
Reply
#2
(02-27-2021, 12:15 PM)RandomiserUsr Wrote: If you compile the following code 

FUNCTION A(text as STRING)

Print B("Test")

RETURN 0
END FUNCTION


FUNCTION C(text as STRING)
Print B("Test")
RETURN 0
END FUNCTION

FUNCTION B(text as STRING)
Print ("Test")
RETURN 0
END FUNCTION


you will get
inputmud.bas:137: error: 'B' is neither an array nor a function.
inputmud.bas:135: warning: [W150] Parameter 'text' is never used
inputmud.bas:144: warning: [W100] Using default implicit type 'float' for 'C'
inputmud.bas:144: error: 'B' is neither an array nor a function.
inputmud.bas:143: warning: [W150] Parameter 'text' is never used
inputmud.bas:149: warning: [W100] Using default implicit type 'float' for 'B'
inputmud.bas:148: warning: [W150] Parameter 'text' is never used


but moving function B above like below compiles okay

So I guess it's a TOP Down design where the functions in the same .BAS should be ordered

FUNCTION B(text as STRING)
Print ("Test")
RETURN 0
END FUNCTION
FUNCTION A(text as STRING)

Print B("Test")

RETURN 0
END FUNCTION


FUNCTION C(text as STRING)
Print B("Test")
RETURN 0
END FUNCTION



Great tool

Thanks
Ken

That is. If you want to reference a function before being declare, use DECLARE:
https://zxbasic.readthedocs.io/en/docs/declare/
Reply
#3
(02-28-2021, 05:31 PM)boriel Wrote:
(02-27-2021, 12:15 PM)RandomiserUsr Wrote: If you compile the following code 

FUNCTION A(text as STRING)

Print B("Test")

RETURN 0
END FUNCTION


FUNCTION C(text as STRING)
Print B("Test")
RETURN 0
END FUNCTION

FUNCTION B(text as STRING)
Print ("Test")
RETURN 0
END FUNCTION


you will get
inputmud.bas:137: error: 'B' is neither an array nor a function.
inputmud.bas:135: warning: [W150] Parameter 'text' is never used
inputmud.bas:144: warning: [W100] Using default implicit type 'float' for 'C'
inputmud.bas:144: error: 'B' is neither an array nor a function.
inputmud.bas:143: warning: [W150] Parameter 'text' is never used
inputmud.bas:149: warning: [W100] Using default implicit type 'float' for 'B'
inputmud.bas:148: warning: [W150] Parameter 'text' is never used


but moving function B above like below compiles okay

So I guess it's a TOP Down design where the functions in the same .BAS should be ordered

FUNCTION B(text as STRING)
Print ("Test")
RETURN 0
END FUNCTION
FUNCTION A(text as STRING)

Print B("Test")

RETURN 0
END FUNCTION


FUNCTION C(text as STRING)
Print B("Test")
RETURN 0
END FUNCTION



Great tool

Thanks
Ken

That is. If you want to reference a function before being declare, use DECLARE:
https://zxbasic.readthedocs.io/en/docs/declare/

Palm Face moment!
I even read that earlier this week! 
Sorry for the spam :-)

thanks again
Ken
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)