v2.0-a049 + Built-in Object functions changes

Discuss the future of the AutoHotkey language
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
Contact:

v2.0-a049 + Built-in Object functions changes

28 Jul 2014, 10:24

Due to the latest (as of 07/28/2014) changes in the built-in object functions, I thought I'd share my understanding of how they're used and their counterpart for v1.1 as reference.
Remarks: obj, arr and stack are simply objects

Code: Select all

v2.0-a049                                 v1.1
obj.Remove(Key)                           obj.Remove(Key) / obj.Remove(IntKey, "")
arr.RemoveAt(Index)                       arr.Remove(Index)
obj.Remove(FirstKey, Lastkey)             obj.Remove(FirstKey, Lastkey)
arr.RemoveAt(Index, vCount)               arr.Remove(LowIndex, HighIndex)
stack.Push(Value1, ...)                   stack.Insert(Value1, ...)
stack.Pop()                               stack.Remove()
arr.InsertAt(Index, Value1, ...)          arr.Insert(1, Value1, ...)
Remove / RemoveAt -- for single key
v1.1

Code: Select all

arr := ["A", "B", "C"]
arr.Remove(2)          ;// arr becomes ["A", "C"]
arr.Remove(2, "")      ;// arr becomes {1:"A", 3:"C"}
v2.0-a049

Code: Select all

arr := ["A", "B", "C"]
arr.Remove(2)          ;// arr becomes {1:"A", 3:"C"}
arr.RemoveAt(2)        ;// arr becomes ["A", "C"]
Remove / RemoveAt -- for range of keys
v1.1

Code: Select all

arr := ["A", "B", "C", "D", "E"]
arr.Remove(2, 4)       ;// arr becomes ["A", "E"]
v2.0-a049

Code: Select all

arr := ["A", "B", "C", "D", "E"]
arr.Remove(2, 4)       ;// arr becomes {1:"A", 4:"D", 5:"E"}
;// To replicate the behavior in v1.1, use .RemoveAt()
arr.RemoveAt(2, 3)     ;// arr becomes ["A", "E"]
Insert / Push
v1.1

Code: Select all

arr := ["A", "B", "C"]
arr.Insert("D")        ;// arr becomes ["A", "B", "C", "D"]
v2.0-a049

Code: Select all

arr := ["A", "B", "C"]
arr.Push("D")          ;// arr becomes ["A", "B", "C", "D"]
Remove / Pop
v1.1

Code: Select all

arr := ["A", "B", "C", "D"]
arr.Remove()           ;// arr becomes ["A", "B", "C"]
v2.0-a049

Code: Select all

arr := ["A", "B", "C", "D"]
arr.Pop()              ;// arr becomes ["A", "B", "C"]
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: v2.0-a049 + Built-in Object functions changes

28 Jul 2014, 12:12

Regarding push/pop examples above. I assume the insert/remove methods still work in v2 but push/pop are just shortcuts for lifo stack.

Is there a shortcut for fifo stack?
ciao
toralf
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: v2.0-a049 + Built-in Object functions changes

28 Jul 2014, 13:13

excellent summary, thank you

User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: v2.0-a049 + Built-in Object functions changes

28 Jul 2014, 13:50

Is there a shortcut for fifo stack?
I guess not.
The fastest I could think of would be:

Code: Select all

fifo.remove(1)
fifo.insert(Val)
Recommends AHK Studio
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: v2.0-a049 + Built-in Object functions changes

28 Jul 2014, 15:49

I guess this would work too

Code: Select all

fifo.push(val)
fifo.remove(1)
Are the words push/pop used in other languages? They do not seem to have any "link" to other ahk commands. Append/get/set/add/choose/check are more common
ciao
toralf
User avatar
fincs
Posts: 527
Joined: 30 Sep 2013, 14:17
Location: Seville, Spain
Contact:

Re: v2.0-a049 + Built-in Object functions changes

28 Jul 2014, 18:04

"fifo stack" is a contradiction. The term you're looking for is 'queue'. And it can be implemented: Push(value) and RemoveAt(1,1).
fincs
Windows 11 Pro (Version 22H2) | AMD Ryzen 7 3700X with 32 GB of RAM | AutoHotkey v2.0.0 + v1.1.36.02
Get SciTE4AutoHotkey v3.1.0 - [My project list]
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: v2.0-a049 + Built-in Object functions changes

28 Jul 2014, 18:23

I dont get what you want to say.
You either want to say that Push and Pop functions are more common in a different way, or you just wanted to say something.
Recommends AHK Studio
lexikos
Posts: 9621
Joined: 30 Sep 2013, 04:07
Contact:

Re: v2.0-a049 + Built-in Object functions changes

28 Jul 2014, 18:47

Do you see the conflict between stack.Insert(Value1, ...) and arr.Insert(1, Value1, ...)? There is no way to "push" multiple values simultaneously in v1 without specifying the index. So: stack.Insert(val) and stack.Insert(Round(stack.MaxIndex())+1, val1, val2, ...).
toralf wrote:I assume the insert/remove methods still work in v2
No. They were commonly misunderstood. You may refer to v2-changes or Object for clarification.
Are the words push/pop used in other languages?
Not just other languages, but programming theory in general. They go hand in hand with the term "stack".
They do not seem to have any "link" to other ahk commands.
Do half the other method names have any link to other commands? What they're doing is unique to objects.
Append/get/set/add/choose/check are more common
I chose "Push" rather than "Append" for symmetry with "Pop". As far as I can tell, none of those other names have anything to do with Push/Pop. I'm not aware of any other term for removing and returning the last element of an array/stack.
fincs wrote:RemoveAt(1,1)
That will return 0 or 1 depending on whether it removed something. You want val := queue.RemoveAt(1).

There is no shortcut for it because it is already quite short and does not require any calculations. By contrast, Push would require something like what I showed at the top of this post.
nnnik wrote:I dont get what you want to say.
joedf was answering toralf's question by listing the languages, implying "Yes".
User avatar
RobertL
Posts: 546
Joined: 18 Jan 2014, 01:14
Location: China

Re: v2.0-a049 + Built-in Object functions changes

06 Aug 2014, 09:40

At used on Array (which key is index), would change index related.
Stack with pop/push used on a special array, would only change the last/max index.
Object is a common basic data struct with any/general key without changing other keys (even a adjoining numerical key).
我为人人,人人为己?

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: No registered users and 18 guests