Notifications
Clear all

[Closed] I like structs! calling private functions

It’s surely something basic, but I’ve found it by my own and I like it:


	myFunctions =
	(
		struct myFunctions
		(
			private
			fn kkk = (print "kkk"),
			fn ppp = (print "ppp"),
			fn qqq = (print "qqq"),
			
			public
			fn myFunction id= 
			(
				case id of
				(
				1:	kkk()
				2:	ppp()
				3:	qqq()
				)
			)
		)
		myFunctions()
	)
	
	for id = 1 to 3 do (myFunctions.myfunction id)
			
2 Replies

And if private functions have parameters:


	myFunctions =
	(
		struct myFunctions
		(
			private
			fn kkk a d = (print (a+d)),
			fn ppp b = (print b),
			fn qqq c = (print c),
			
			public
			fn myFunction id a: b: c: d: = 
			(
				case id of
				(
				1:	kkk a d
				2:	ppp b
				3:	qqq c
				)
			)
		)
		myFunctions()
	)
	
	for id = 1 to 3 do (myFunctions.myfunction id a:"aa" d:"dd")

And similar for functions with default values.

DenisT was talking about that long time ago also. Really useful things