Notifications
Clear all

[Closed] Function in struct calls another function in same struct

Hi all,

I’ve been wondering, is there a way for a function in a struct to call another function in the same struct without instancing the struct?

6 Replies
struct exampleStruct
(
 fn a = ( print "a" ),
 fn b = ( exampleStruct.a() )
)

exampleStruct.b()

:banghead: So obvious. Thanks !

some tricks with struct functions:


struct testStruct 
(
	a = 2, b = 3, ac, bc, 
	fn cc = ac()+bc(),
	fn aa = a*a,
	fn ab = aa()+b,
	fn bb = aa()*b,
	on create do
	(
		ac = aa
		bc = ab
	)
)
theStruct = testStruct()
theStruct.ab()
theStruct.cc()
theStruct.a = 4
theStruct.b = 5
theStruct.cc()
theStruct.ac = theStruct.bb
theStruct.cc()


I don’t understand the on create part. Is aa a variable, or a function ? Where does it come from ?

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

aa is a function, ac is a variable… function cc defined before aa but after ac… so assigning aa to ac makes possible to run aa function from cc

I think I got it. That’s tricky indeed