[SUGGEST] Object callable property Topic is solved

Discuss the future of the AutoHotkey language
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

[SUGGEST] Object callable property

22 Mar 2020, 08:51

Due to no simple way in AHKv2.0 to be created object method I suggest Object to have mechanism to direct call "callable properties" (properties contain reference to function).
Explain: Let Object have property that contain reference to functions
  • Get - return value
  • Set - set value
  • Call - return result from calling reference
And in code example:

Code: Select all

class proto { ;test class =====================================================
	__Call(name, para) { ;call callable property ------------------------------
		try return this.%name%.call(this, para*)
		catch
			throw { message: '<' this.__Class '> has no method or callable property <' name '>' }
	} ;------------------------------------------------------------------------
	me_0(a) => A_ThisFunc ': ' a
	pr_0[a:=''] {
		get => A_ThisFunc ': ' a		  ;callable prop [parameters] 
		set => ''						  ;callable prop (no returun result)
	}
	pr_1:= (this, a) => A_ThisFunc ': ' a ;callable prop (ref)
} ;============================================================================

b:= proto.new()						;tests -------------
MsgBox(b.me_0(123))					;123			(ok)
try b.pr_0							;proto.__Call	(ok)
catch e
	MsgBox(e.message)
;:= <identificator>	;get
;<identificator> :=	;set
;<identificator>	;call
MsgBox(b.pr_0[234])					;.get			(ok)
MsgBox(b.pr_0:=345)					;.set			(ok)
MsgBox(b.pr_1(456))					;.call			(ok) <<< suggest
In short - let property have extra feature to be called (.get|.set|.call)
AHKv2.0 alpha forever.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: [SUGGEST] Object callable property  Topic is solved

22 Mar 2020, 09:39

This would be a step backwards, back to conflation between methods and properties, which we've finally got rid off. A better, and more logical, solution would be to allow simpler syntax for defining methods. I think lexikos said somewhere he might add something like { m() => expr }, I also think that local classes have been mentioned. In particular the latter would great.

In the mean time, the current situation is still very workable, either use definemethod or %expr%(), eg, %obj.prop%().

Cheers.
Spoiler

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: No registered users and 20 guests