AutoHotkey Community

It is currently May 27th, 2012, 6:37 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 741 posts ]  Go to page Previous  1 ... 10, 11, 12, 13, 14, 15, 16 ... 50  Next
Author Message
 Post subject:
PostPosted: April 13th, 2011, 5:18 pm 
Lexikos wrote:
- Labels defined in functions are now private to the function which encloses them. If a global label with the same name exists, the local label takes precedence.

Very nice. For SetTimer, would there be any way outside of the function to turn the timer off?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 13th, 2011, 5:25 pm 
In the timer itself?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 13th, 2011, 5:33 pm 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
Anonymous wrote:
In the timer itself?
Ooooh I like this idea. How about adding something to SetTimer to designate self-editing...

How about changing:
Code:
SetTimer, Label [, Period|On|Off, Priority]  ;ahk basic
SetTimer [, Label, Period|On|Off, Priority]

When the executing code was called from a timer and if the label arg is blank then SetTimer refers to the currently executing timer's label. If it doesn't meet these requirements either fail with an error or maybe silently with an ErrorLevel

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 13th, 2011, 5:39 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5482
Location: the tunnel(?=light)
Better yet, if you can declare global varname outside of a function, why not global timerlabel (or just global label)? Obviously there could be name collision concerns but you would expect that only someone who knows enough to know better would be using such a technique anyway.

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 13th, 2011, 6:19 pm 
Offline

Joined: March 10th, 2011, 7:17 pm
Posts: 374
CodeKiller wrote:
trueski wrote:
For multiline assignments, can you make it so that text between quotes may span more than one line?

Code:
Variable := "This
 Should
 Work"


Is there a problem with this design?


This pattern is not used in any other language, it's a bit strange to write text on multiple lines...
And to write multilines text you just need to put a `n so... :P

Code:
test := "This`nIs`nA`nTest"
Msgbox % test



pretty sure that pattern works in PHP, since if there is no semicolon to end the line, the next line is added


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 13th, 2011, 8:24 pm 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
LiquidGravity logged off wrote:
Whats wrong with using continuation method #2 described here: http://www.autohotkey.com/docs/Scripts.htm#continuation

; EXAMPLE #1:
Var =
(
Line 1 of the text.
Line 2 of the text. By default, a linefeed (`n) is present between lines.
)
Well there is no literal assignment currently.
= was replaced with `= then `= was removed. Now only := works for assignment.

The multi-line would be a good compromise if it would work (seems very different than any current syntax). The main point to consider would be handling of trailing and leading spaces.

Code:
; For purposes of demonstration \s means space
Var := "\s\s\s\s Leading Spaces on First Line
Trailing Spaces on Line Other Than Last \s\s\s
\s\s\s\s Leading Spaces on Other Than First Line
Trailing Spaces Last Line\s\s\s\s"

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 13th, 2011, 8:52 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
@Lexikos: you forgot to update format.ahk:
Quote:
C:\Program Files (x86)\AutoHotkey\v2-alpha\x86\Lib\format.ahk (34) : ==> Missing variable name.
Specifically: "(.*?)\K\{(\w+)(?::([^%}]*))?\}", m, j)


@Frankie: remember this is still possible:
Code:
Var := "
(
Line 1 of the text.
Line 2 of the text. By default, a linefeed (``n) is present between lines.
)"

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 13th, 2011, 9:37 pm 
Offline

Joined: April 8th, 2008, 1:08 am
Posts: 100
Location: Minnesota, USA
I think the current method wastes space and looks a bit ugly:
Code:
Var := "
(
Line 1 of the text.
Line 2 of the text. By default, a linefeed (``n) is present between lines.
)"


I don't like how you have to put the parenthesis on the next line.

In addition to this idea with quotes...
Code:
Variable := "This
Should
Work"


What about allowing expressions to do the same thing? (Yes I know that you can already do this by placing an operator as the first character on the next line...). This would allow for a bit more flexibility:
Code:
Variable := (This + Should -
Work)


...So if an open parenthesis is placed on a variable assignment, AHK looks for the closing parenthesis on the following lines if it is not found.

_________________
-trueski-


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 13th, 2011, 11:11 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
trueski wrote:
Is there a problem with this design?
If you're missing an end quote, it might not be detected until many lines further down in the script (when the next quote mark is found). Worse: it might not be detected at all if the remainder of the text after the ending quote can be parsed as an expression. This might be confusing. Currently the continuation logic is done before determining what's actually on the line (e.g. a command or expression), but it might be possible to change that.

If it can be done with quotation marks, it would be logical to allow it with parentheses/brackets/braces. For example:
Code:
Func(
    param1,
    param2
  )
x := {
    a: 1,
    b: 2
  }

CodeKiller wrote:
And to write multilines text you just need to put a `n so...
That is far from practical if each line is 80+ chars long and/or you have many lines.
a4u wrote:
For SetTimer, would there be any way outside of the function to turn the timer off?
Call the function. :P
infogulch wrote:
When the executing code was called from a timer and if the label arg is blank then SetTimer refers to the currently executing timer's label.
Any line inside the function can refer to local labels, so this isn't really necessary. (However, dynamic labels used in a subroutine called by SetTimer, Hotkey, etc. will never resolve to local labels.) I do like the idea, though. A_ThisLabel might be used (even if it's not a timer), for simplicity.
sinkfaze wrote:
Better yet, if you can declare global varname outside of a function, why not global timerlabel (or just global label)?
Labels aren't variables. At the time the global declaration is found, it must create super-global variable unless the declaration is something unique, like global timerlabel:. Maybe the actual label should use that syntax, rather than requiring a forward-declaration outside the function? Alternatively, what do we think about allowing local labels to be addressed from anywhere by prefixing the function name (e.g. SetTimer MyFunc:timer, Off)?
fincs wrote:
@Lexikos: you forgot to update format.ahk
Fixed. To forget, I'd have had to think of it in the first place. :P


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 14th, 2011, 4:59 am 
Offline

Joined: January 26th, 2009, 5:26 pm
Posts: 151
I may have missed something here but why are we getting rid of literal assignments? If the only reason is to make it easier by preventing confusion then I don't think this will make it easier.

If you want to get rid of one why not get rid of expression assignments := and instead use traditional with forced expressions? From what I can tell it is already supported in V1.
Code:
; don't use
Var := MyArray%A_Index% + 100
; instead use
Var =% MyArray%A_Index% + 100
; It is the same amount of characters and should be simple change over with a the replace function in any text editor.

; then this still works with the correct replacement of vars
Var =
(
Line 1 of the text. %SomeVar%
Line 2 of the text. %SomeVar2% By default, a linefeed (`n) is present between lines.
)
; versus this mess:
Var :="
(
Line 1 of the text. " . %SomeVar% . "
Line 2 of the text. " . %SomeVar2% . " By default, a linefeed (`n) is present between lines.
)"

; and this works
Var =% "The variable MyVar contains " . MyVar . "."
; Or this
Var =The variable MyVar contains %MyVar%.

Btw wrapping percent signs around the variable name can sometimes prevent the incorrect variable from being used. I hope that it remains as an option at least.
Code:
MyVar1 = don't fix
MyVar10 = what isn't broken
MyVar1014 = right?
Var = I really want to say %MyVar1014510.
What would that even end up as?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 14th, 2011, 6:13 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Lexikos wrote:
[concerning SetTimer] Call the function. :P
... eventually figured that out:
Code:
SetBatchLines("20ms")
; ...
SetBatchLines("Off")
; ...

SetBatchLines(p) {
   SetTimer, BatchLines, % RTrim(p, "ms")
   return
   BatchLines:
      Sleep, 10
      return
}
Quote:
... what do we think about allowing local labels to be addressed from anywhere by prefixing the function name ...
This would be nice, though I forsee it opening the door to wanting to access static vars the same way. This would be particularly nice if it applies to a Class definition (depending on the exact implementation), or if the previous mentioned advanced features for functions are implemented (where the prototype object could be created via function, and the user could then access the "class private variables").
LiquidGravity wrote:
If you want to get rid of one why not get rid of expression assignments :=
Definately -1 for this, though I do agree (as I've already stated) that there should be a literal assignment option.
Quote:
What would that even end up as?
Yes, you would want to use an end percent sign to show where your var ends. You could just test the code, but since MyVar1014510 isn't defined, Var would contain "I really want to say ."

... also wanted to point out that this thread currently is receiving 600+ views per day - impressive 8) ...

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 14th, 2011, 6:59 am 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Hi Lexikos,

V2 looks really great :D

Some thoughts wrote:
    Lexikos wrote:
    The idea is that expressions may be embedded in a non-expression arg by writing %func(params) or %(expression). I believe this will require extensive changes to implement properly, so it probably won't be implemented in v2.0. However, I will add support for the simplest case, %(var), if there's enough demand for it.
  • +1
    fincs wrote:
    Auto-concat is one of my favourite features of AHK, so please don't remove it.
  • +1
    majkinetor wrote:
    Integrated lowlevel.ahk
  • +1
    Quote:
    ... what do we think about allowing local labels to be addressed from anywhere by prefixing the function name ...
  • +1

LiquidGravity wrote:
If you want to get rid of one why not get rid of expression assignments :=
I think this is a necessary change towards the future for AHK. = is now always a comparison, this will remove any confusion especially in expressions.

Will this be possible at some point?
Code:
Func, test
func(a){
   MsgBox % a
}

;another one
DllCall("MessageBox","Uint",0,"Str","MsgBox","Str","Title","Uint",0)
DllCall,MessageBox,Uint,0,Str,MsgBox,Str,Title,Uint,0

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 14th, 2011, 10:13 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
LiquidGravity wrote:
If the only reason is to make it easier by preventing confusion then I don't think this will make it easier.
I do. It solves the second of the two "big changes" from the v2 plan:
Chris wrote:
The burden of maintaining backward compatibility with legacy features reduces the usability and convenience of the language. The two big problems are that:
  1. IF-statements must usually be enclosed in parentheses to be expressions, which is a big source of confusion and script-bugs.
  2. The equal-sign operator does not assign an expression, so statements like x=y produce a counterintuitive effect. Even after users get used to it, they're still prone to type = instead of :=, which is a big source of script-bugs.
(The equal-sign operator still does not assign an expression, but statements like x=y don't pass through unchecked, so it won't be a source of bugs.) Frankly, I'm not willing to consider keeping = as literal assignment.
Quote:
If you want to get rid of one why not get rid of expression assignments := and instead use traditional with forced expressions?
Firstly, that would be completely pointless. You'd still have two types of assignments, just that they'd be written as = and =% instead of = and :=. In fact, = with forced expression (% ) is internally translated to :=. Secondly, := is valid in the middle of an expression such as If(retval := func()), whereas "% " is only valid at the beginning of an "arg" in command/traditional mode.
Quote:
; versus this mess:
You're right to call it a mess. Why did you use double-derefs in the second example? Also, why explicit concatenation? Well, I can guess it's because you were trying to make the code unreadable to further your point. Anyway, these do work in the current alpha:
Code:
Var := "
(
Line 1 of the text. %SomeVar%
Line 2 of the text. %SomeVar2% By default, a linefeed (`n) is present between lines.
)"
Var := "The variable MyVar contains %MyVar%."
... and there was talk about allowing this:
Code:
Var := "
Line 1 of the text. %SomeVar%
Line 2 of the text. %SomeVar2% By default, a linefeed (`n) is present between lines.
"
How it handles the leading/trailing `n or indentation may be the topic of another discussion.
Quote:
Btw wrapping percent signs around the variable name can sometimes prevent the incorrect variable from being used. I hope that it remains as an option at least.
At the moment I'm inclined to keep the double-percent-sign method, but %(var) would be more consistent; i.e. because each % would introduce exactly one variable. Instead of "%var1%%var2%_%var3" you could write "%var1%(var2)_%var3".

jethrow wrote:
This would be particularly nice if it applies to a Class definition
If supported, a class definition would purely be syntax sugar for defining a base/prototype object. Static class variables, if supported, would merely be fields in the "class" object rather than variables or fields in the derived object.

HotKeyIt wrote:
Will [using command syntax to call a function] be possible at some point?
I have mentioned in passing that I want to make commands and functions equivalent, allowing either syntax in every case. However, there may be difficulties with user-defined functions:
Code:
#MustDeclare
GetFoo foo, some text
#MustDeclare Off
...
GetFoo(ByRef aFoo, aBar) {
    aFoo := CalculateFooFromBar(aBar)
}

At the point the command is parsed, GetFoo hasn't been defined, so the parser doesn't know how many or what type of args it has. GetFoo's args can be processed at a later stage, after the function is resolved, but in that case the positional behaviour of var declarations/var references/#MustDeclare would have to be changed.

This problem could be avoided by marking all args of user-defined commands unconditionally as literal text (and probably requiring literal commas to be escaped even in the final arg); but in addition to making the usage less intuitive, it would rule out the possibility of overriding built-in commands (which have output variables) the same way built-in functions can be overridden. On the other hand, for user-defined commands to provide the same amount of flexibility as built-in ones, there'd need to be some way to indicate a parameter should be an expression (as with WinMove x+n, y+m) or an input var.

There are other problems with the positional behaviour of var declarations/var references/#MustDeclare which I hadn't considered until recently. The main use I had in mind for super-global variables was for "constants" like WM_USER, which could be defined in a library file. However, for the main script to be able to reference it, the library file would need to be explicitly #included prior to the script's first use of the variable. Similarly, if a class definition caused a super-global variable to be introduced (containing a class/base/prototype object), scripts would need to include that class definition at the top of the file to be able to reference any static class variables or instantiate the class.

Functions don't need to be declared in advance because they're resolved at a later stage than variables, after all lines have been parsed but immediately before each expression is fully processed.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 14th, 2011, 12:27 pm 
Offline

Joined: October 31st, 2010, 3:02 am
Posts: 87
WinMove doesn't accpect the number variable in the v2.0-a005-96c78bd (do not test in preview alpha release)!

Is it a change I haven't noticed before or a bug?

"Error: This variable name starts with a number, which is not allowed"
Code:
x := y := 10
WinMove, %x,%y


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 14th, 2011, 1:00 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
aSEioT wrote:
"Error: This variable name starts with a number, which is not allowed"
In other words, you're using percent signs when you shouldn't. Or did you really mean to deref the variable named "10"?
Quote:
Removed legacy exception for %var% in expression args. For example, return %var% is now equivalent to return (%var%) instead of return var.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 741 posts ]  Go to page Previous  1 ... 10, 11, 12, 13, 14, 15, 16 ... 50  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo and 22 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group