Modify

Opened 12 years ago

Closed 6 years ago

#2503 closed Feature Request (Rejected)

Reference Definition Keyword

Reported by: Tasiro Owned by:
Milestone: Component: AutoIt
Version: Severity: None
Keywords: reference, ref, byref Cc:

Description

It is possible to create a reference, but only with a complicated syntax:

Local $var = 1
rest ($var)
Func rest (ByRef $var_ref)
    $var = 2 ; $var_ref == 2
    $var_ref = 3 ; $var == 3
EndFunc

Please change the syntax to make the definition of references easier.
The production is something like:
variable-declarationvariable-declaration-specifiers variable-name.
Please change that to:
variable-declarationvariable-declaration-specifiers Refopt variable-name.

Then, it would just be:

Local $var = 1
Local Ref $var_ref = $var ; same rules as for ByRef argument
$var = 2 ; $var_ref == 2
$var_ref = 3 ; $var == 3

Attachments (0)

Change History (5)

comment:1 by anonymous, 12 years ago

ByRef cannot compute

comment:2 by mLipok, 10 years ago

Why do you need the exactly the same content in variable in the same scope but with different variable name ?
To me this seems ridiculous, or at least unnecessary.

Last edited 10 years ago by mLipok (previous) (diff)

comment:3 by anonymous, 10 years ago

Maybe for this:

ref $r = $array [calculateIndex ()]

Or something similar to this:

func getFirstNonArray (ByRef $array, $then)
    ref $r = $array
    while IsArray ($r)
        ref $r = $r [0]
    wend
    $then ($r)
endfunc

func exampleThen (ByRef $part)
    ; modify $part
endfunc

Creating a reference makes iterative variants of otherwise stack overflow generating functions possible.

comment:4 by mLipok, 10 years ago

So I little change you example (now is be more readeble):

Func getFirstNonArray(ByRef $array, $function)
	ref $aTemp = $array
	While IsArray($aTemp)
		ref $aTemp = $aTemp[0]
	WEnd
	$function($aTemp)
EndFunc   ;==>getFirstNonArray

Func exampleThen(ByRef $part)
	; modify $part
EndFunc   ;==>exampleThen


Your example does exactly the same as this:

Func getFirstNonArray(ByRef $array, $function)
	While IsArray($array)
		$array = $array[0]
	WEnd
	$function($array)
EndFunc   ;==>getFirstNonArray

Func exampleThen(ByRef $part)
	; modify $part
EndFunc   ;==>exampleThen


What advantage do you see in your example ?

comment:5 by J-Paul Mesnage, 6 years ago

Resolution: Rejected
Status: newclosed

no more info

Modify Ticket

Action
as closed The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.