Modify

Opened 5 years ago

Last modified 5 years ago

#3004 new Feature Request

Anonymous Maps

Reported by: jaberwacky Owned by:
Milestone: Component: AutoIt
Version: Severity: None
Keywords: Cc:

Description

So I have an idea which I think will make coding a little easier in that a descriptive variable name need not be thought of in every case. I spend a bit of time in the outer regions thinking of hair brained ideas which are often shot down (rightfully so). However, I think I have a good idea, so I present to you and respectfully request the following:

Func _rect_from_points(Const $a1, Const $a2, Const $b1, Const $b2)      
	With []         
		.Left = ($a1 < $b1) ? $a1 : $b1         
		.Top = ($a2 < $b2) ? $a2 : $b2         
		.Width = ($b1 > $a1) ? ($b1 - .Left) : ($a1 - .Left)         
		.Height = ($b2 > $a2) ? ($b2 - .Top) : ($a2 - .Top)                 
	
		Return . ; or 
		; Return [] or 
		; Return .[] ??     
	EndWith
EndFunc

Attachments (0)

Change History (10)

comment:1 Changed 5 years ago by anonymous

This actually contains three proposals:

  1. Allow maps as expressions in a "With" statement.

Example:

Local $map[]
$map.a = 1
With $map
    .b = .a
    .a = 2
EndWith

Maps and "Object-type variables" have the same syntax. That extension is only natural.

  1. Create a shortcut for the expression in a With statement.

Example:

With $object
    Local $copy = .
    UseObject (.)
    . = Duplicate ($copy)
EndWith

What about ..element?
Saves at most one line, not intuitive, easy to miss, will confuse programmers and tools, strange semantics, might encourage overuse – probably a bad idea, but absolutely possible.
[] is a bad idea, see point 3. .[] is really strange, probably hard to implement and makes you assume that $object is a map, althrough it may be an "Object-type variable".
Maybe with an additional keyword or constant (@WithExpression).

  1. Make [] the empty map.

Example:

Local $emptyMap[]
UseEmptyMap ($emptyMap)

$emptyMap = []
Local $emptyMap2 = ([])
UseEmptyMap ($emptyMap)
UseEmptyMap ($emptyMap2)

Note that the parentheses in the third-last line are a necessary syntactic disambiguation. Without them, it would be a broken array initialization (see #2845), or ambiguous. The same is true for 2d array initializations.
Again, this may save at most one line. It will confuse any programmer coming from any language where that is an expression for an empty array (JS, PHP, ...): they will use it thinking that it is an empty array, and will be legitimately surprised when their program breaks.
Definitely a bad idea.
Maybe with braces ({})?

comment:2 Changed 5 years ago by jaberwacky

As far as I know AutoIt isn't trying to mimic or make it easy for JS, PHP, etc programmers. I'm sure all languages have their syntax differences that all people new to the language would have to learn. If someone coming to AutoIt from another language tries to use AutoIt the same way they used their previous language, that is an operator error.

comment:3 follow-up: Changed 5 years ago by jaberwacky

As far as I know AutoIt isn't trying to mimic or make it easy for JS, PHP, etc programmers. I'm sure all languages have their syntax differences that all people new to the language would have to learn. If someone coming to AutoIt from another language tries to use AutoIt the same way they used their previous language, that is an operator error.

comment:4 Changed 5 years ago by anonymous

Sorry for the double post.

comment:5 in reply to: ↑ 3 ; follow-up: Changed 5 years ago by anonymous

Replying to jaberwacky:

As far as I know AutoIt isn't trying to mimic or make it easy for JS, PHP, etc programmers. I'm sure all languages have their syntax differences that all people new to the language would have to learn. If someone coming to AutoIt from another language tries to use AutoIt the same way they used their previous language, that is an operator error.

It makes AutoIt inconsistent and is not open for extensions.
Why not @EmptyMap?

comment:6 in reply to: ↑ 5 Changed 5 years ago by jaberwacky

Replying to anonymous:

It makes AutoIt inconsistent and is not open for extensions.
Why not @EmptyMap?

I'm not exactly sure what you're saying with proposal 2 and 3.

Are you saying the idea is good but that the execution is bad?

@EmptyMap

Works for me.

comment:7 follow-up: Changed 5 years ago by anonymous

Rewind...

How does this make the language inconsistent? This only applies to maps and not arrays and not objects. Dot access does not imply object object orientation. I'm actually not trying to subtly sneak anything OO related into the language.

comment:8 in reply to: ↑ 7 Changed 5 years ago by anonymous

Replying to jaberwacky:

I'm not exactly sure what you're saying with proposal 2 and 3.

I'm saying that you're proposing three different things and that they should be considered separately.

Are you saying the idea is good but that the execution is bad?

I think there were some problems and suggested possible refinements. Personally I support all three proposals.

Replying to anonymous:

How does this make the language inconsistent? This only applies to maps and not arrays and not objects. Dot access does not imply object object orientation. I'm actually not trying to subtly sneak anything OO related into the language.

I didn't even think about objects, they're a lost cause. I think that it's a bad idea to use one syntax for two different things: array and map creation.
I don't like the current way to create a map:
Local $map[]
I'd prefer
Local $map = {}
or
Local $map = Map ()
or
Local $map = NewMap ()
or
Local $map = @EmptyMap
because they make it clear what is happening.

But [] does not. Why should
Local $array = [] (array initialization)
and
Local $map = ([]) (empty map expression)
create different things?

comment:9 Changed 5 years ago by anonymous

OK, everything is clear now. Thank you clearing that up. Now that I've reread your posts with my refreshed perspective, I agree with all points.

comment:10 Changed 5 years ago by jaberwacky

OK, it occurred to me just now. Should I create three separate trac tickets for these proposals? I still think these three proposals do not cover my original feature request though. I was hoping to set up an anonymous map using With and then refer to the map accordingly. However, the syntax for the empty map did always seem somewhat wrong though.

With {}
    .Key1 = "Key1"
   
    ConsoleWrite(.Key1 & @CRLF)
EndWith

Is this a better syntax?

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

Modify Ticket

Action
as new The ticket will remain with no owner.
Author


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

 
Note: See TracTickets for help on using tickets.