Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Allowing duplicate labels


  • Please log in to reply
7 replies to this topic
Tuncay
  • Members
  • 1945 posts
  • Last active: Feb 08 2015 03:49 PM
  • Joined: 07 Nov 2006
My request is simple: Outside of a function, labels should be allowed to be defined multiple times. Before execution, at optimization stage, all these labels could become one label.

This script
OnExit, ExitApp
Return

ExitApp:
  saveData()
Return

ExitApp:
  doSomethingStupid()
Return
could become internally to
OnExit, ExitApp
Return

ExitApp:
  saveData()
  doSomethingStupid()
Return

That would allow us to create something similar in code above, where the subroutines are from separate scripts; may be in a library.

Andreone
  • Members
  • 257 posts
  • Last active: Mar 19 2008 05:30 PM
  • Joined: 20 Jul 2007
In the same manner, if auto-execute sections could be merged, a script could be either run as a stand alone script or integrated in a main script with no code change.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
This would make it easier to merge scripts, but what if:[*:3m2o2kh8]a label has the same name (i.e. by coincidence) and shouldn't be merged, or
[*:3m2o2kh8]the first instance of the label has conditional returns - where does one label end and the other begin?

In the same manner, if auto-execute sections could be merged,

IMO, that would be useful more often, and is less likely to cause problems. There's still a chance that it'd break existing scripts, though. (For instance, some of my #includes have test code at the top that only runs if I run the file standalone.)

Andreone
  • Members
  • 257 posts
  • Last active: Mar 19 2008 05:30 PM
  • Joined: 20 Jul 2007

IMO, that would be useful more often, and is less likely to cause problems. There's still a chance that it'd break existing scripts, though. (For instance, some of my #includes have test code at the top that only runs if I run the file standalone.)

That's right. Maybe adding an option to the #include directive could avoid breaking scripts: like -m for merge
#include -m myfile
Or maybe better: if a special label could be defined for initialization and cleanup steps:
AlwaysExecuteOnStart, MyInitLabel ; always perform this sub initialization sub
AlwaysExecuteOnExit, MyCleanupLabel ; always perform this cleanup sub
With that, "the only thing to do" is to generate a list of sub routines calls in the right place. There won't be compatibility issues since this behavior would be by design.

Tuncay
  • Members
  • 1945 posts
  • Last active: Feb 08 2015 03:49 PM
  • Joined: 07 Nov 2006
Proposal: #EnableAutoMerge or alternatively #NoAutoMerge or may be #AutoMergeLabel LabelName or more flexible
Label:
  AutoMerge, On ; Thread based command.
Return


corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
I think auto-merging sounds like a bad idea since AutoHotkey will not know how the merge should be done. Side effects are inevitable and might be difficult to troubleshoot. An alternative might be to use a different symbol for a label definition to allow code to be prepended to an existing Label if it already exists or added as a new label otherwise.

Andreone
  • Members
  • 257 posts
  • Last active: Mar 19 2008 05:30 PM
  • Joined: 20 Jul 2007

An alternative might be to use a different symbol for a label definition to allow code to be prepended to an existing Label if it already exists or added as a new label otherwise.

Yes, prepend is exactly what is requested.:)
I agree the term merge is not appropriated here. It should not be thought as in merging two files, but more as in concatenating labels.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Although I don't think this will happen anytime soon, I appreciate the ideas and have added them to my notes.