Modify

Opened 12 years ago

Closed 5 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

Change History (5)

comment:1 Changed 12 years ago by anonymous

ByRef cannot compute

comment:2 Changed 9 years ago by mLipok

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

Version 0, edited 9 years ago by mLipok (next)

comment:3 Changed 9 years ago by anonymous

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 Changed 9 years ago by mLipok

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 Changed 5 years ago by Jpm

  • Resolution set to Rejected
  • Status changed from new to closed

no more info

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.