How to write this shorter?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
SL5
Posts: 879
Joined: 12 May 2015, 02:10
Contact:

How to write this shorter?

10 Nov 2018, 06:44

How to write this shorter?

Code: Select all

if(commandTypeObj.is_multiline_rr)
	commandTypeObj.is_r := false
idears:

Code: Select all

with commandTypeObj{
if(.is_multiline_rr)
	.is_r := false
}}

Code: Select all

it := ByRef commandTypeObj ; 
if(it.is_multiline_rr)
	it.is_r := false
}
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: How to write this shorter?

10 Nov 2018, 07:23

Another, (it := commandTypeObj).is_multiline_rr && it.is_r := false.

Cheers.
User avatar
SL5
Posts: 879
Joined: 12 May 2015, 02:10
Contact:

Re: How to write this shorter?

10 Nov 2018, 07:26

is there a way to copy not the values

not

Code: Select all

it := commandTypeObj
mor like:

Code: Select all

it := ByRef commandTypeObj
?
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: How to write this shorter?

10 Nov 2018, 07:46

You only copy reference, if that is what worries you.

You can do,

Code: Select all

f(it) {
	it.is_multiline_rr && it.is_r := false
}
f(commandTypeObj)
to avoid extra references / variables.

in v2 you can do,

Code: Select all

f(it) => it.is_multiline_rr && it.is_r := false.
f commandTypeObj
and f can be nested in an other function too :thumbup:.

Cheers.
User avatar
SL5
Posts: 879
Joined: 12 May 2015, 02:10
Contact:

Re: How to write this shorter?

10 Nov 2018, 08:08

Helgef wrote:
10 Nov 2018, 07:46
You only copy reference, if that is what worries you.
...
great not to copy the values.

I think it's time that I have a bit more context with.

I wanted to outsource a large part from a function in order to make it easier to read it.

I suspect now is everything as it should be. No big values only references are copied

Code: Select all

; If you want to return extra results from a fnction, you may also use ByRef:
;  The IsByRef() function can be used to determine whether the caller supplied a variable for a given ByRef parameter.
setCommandTypeS(ByRef lineObj, ByRef commandTypeObj, ByRef collectionObj, ByRef do, ByRef is_IndexedAhkBlock ){
In this function, some variable but just too long for me

Actually I use the following at the end of this function:

Code: Select all

; now plausibility checks. proof of programer does Bullshit or was lazy 10.11.2018 09:47
	o := commandTypeObj ; <=============== trie if it work
	if(commandTypeObj.is_multiline_rr)
		commandTypeObj.is_r := false
	else if(commandTypeObj.is_multiline_r)
		commandTypeObj.is_rr := false
	else if(!commandTypeObj.is_r && !commandTypeObj.is_rr && !commandTypeObj.is_multiline_r &&  !commandTypeObj.is_multiline_rr )
		o.is_str := true ; <=============== trie if it work
	else if(commandTypeObj.is_str){
		commandTypeObj.is_r := false
		commandTypeObj.is_rr := false
	} 
	return

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: How to write this shorter?

10 Nov 2018, 11:35

An other approach would be to use properties for your object, consider this example,

Code: Select all

class commandTypeObj {
	a {
		set {
			this._b := this._c := !value
			return this._a := value 
		}
		get {
			return this._a
		}
	}
	b {
		set {
			this._a := this._c := !value
			return this._b := value 
		}
		get {
			return this._b
		}
	}
	c {
		set {
			this._a := this._b := !value
			return this._c := value 
		}
		get {
			return this._c
		}
	}
}
c := new commandTypeObj
c.a := true
msgbox % c.a "`n" c.b "`n" c.c
c.b := true
msgbox % c.a "`n" c.b "`n" c.c
c.c := true
msgbox % c.a "`n" c.b "`n" c.c
c.a := false
msgbox % c.a "`n" c.b "`n" c.c
In short, you implement, eg, the is_multiline_rr property to ensure that is_r is set to false whenever is_multiline_rr is set to true.

Cheers.
User avatar
SL5
Posts: 879
Joined: 12 May 2015, 02:10
Contact:

Re: How to write this shorter?

10 Nov 2018, 14:32

Helgef wrote:
10 Nov 2018, 11:35
... properties for your object, ...

Code: Select all

class commandTypeObj {
	a {
		set {
			this._b := this._c := !value
			return this._a := value 
		}
		...
Yes, this looks very pretty and practical.
Maybe for the version 2.0 (means not today , may tomorrow ;) )
I'm actually already done with the objects and these are only changed at one place.
actually i need maybe a deep copy of my string object. maybe with https://autohotkey.com/board/topic/6132 ... on-object/
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: How to write this shorter?

10 Nov 2018, 21:18

SL5 wrote:
10 Nov 2018, 06:44
How to write this shorter?

Code: Select all

if(commandTypeObj.is_multiline_rr)
	commandTypeObj.is_r := false
This likely won’t work but thought I’d mention it.

Code: Select all

commandTypeObj.is_r := !commandTypeObj.is_multiline_rr
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: How to write this shorter?

15 Nov 2018, 04:09

Very good kczx3 :thumbup:

Cheers.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, Lamron750, Rohwedder and 227 guests