Jump to content

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

AutoHotkey v2 Alpha Release


  • Please log in to reply
870 replies to this topic
infogulch
  • Moderators
  • 717 posts
  • Last active: Jul 31 2014 08:27 PM
  • Joined: 27 Mar 2008
Oooooh I just had an idea. Never mind what I just said lol.

If splitting by characters, then pass an array. (like Franke said)

BUT if the parameter is a number instead then split the string with number-characters per index.


string := "abc 12 xy_zwk cd_ahk"
StrSplit(string, [" ","_"]) ; yields: ["abc","12","xy",zwk","cd","ahk"]
StrSplit(string, 4)  ; yields: ["abc ", "12 xy", "_zwk", " cd_", "ahk"]


Frankie
  • Members
  • 2930 posts
  • Last active: Feb 05 2015 02:49 PM
  • Joined: 02 Nov 2008
I was thinking that "delim" and ["delim"] would be equivalent. If you want to use multiple delimiters you can put them in an array. Otherwise just use the one and only delimiter as a literal string / variable containing a string.

It's the most consistent way I can think of. That is assuming multi-character delimiters are going to be allowed at all.
aboutscriptappsscripts
Request Video Tutorials Here or View Current Tutorials on YouTube
Any code ⇈ above ⇈ requires AutoHotkey_L to run

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

It allows the most flexibility with minimal negative effects.

StrSplit(String, [SingleDelimiterString]) is just as flexible. It's just a matter of which would be more commonly used: a list of delimiting characters or a single delimiting string.

I think the Delimiters param should allow two values: a string or an array.

That was my intention, as implied by my previous post.

This allows the current syntax to remain intact

This is not of particular concern for the v2 alpha.

BUT if the parameter is a number instead then split the string with number-characters per index.

I thought of that too, which is why I didn't add that little bit of extra code to convert numeric parameters to strings. But would it really be useful enough?

Another issue is the OmitList parameter: for performance and convenience, it might be best to leave it as is, but it might seem inconsistent.

Frankie
  • Members
  • 2930 posts
  • Last active: Feb 05 2015 02:49 PM
  • Joined: 02 Nov 2008

BUT if the parameter is a number instead then split the string with number-characters per index.

I thought of that too, which is why I didn't add that little bit of extra code to convert numeric parameters to strings. But would it really be useful enough?

I often limit output to less than 80 characters. A StrSplit of every 79 characters and then joining them back together with `n between each line would do the trick. Join can be done very easily.
for key, val in StrSplit(Data, [color=darkred]79[/color], "`n`r") ; Each 79 characters
   if Key < 50 ; Limit to 50 lines
      Out .= val "`n"

Another issue is the OmitList parameter: for performance and convenience, it might be best to leave it as is, but it might seem inconsistent.

I can't think of any cases why I'd want to omit strings of characters.
aboutscriptappsscripts
Request Video Tutorials Here or View Current Tutorials on YouTube
Any code ⇈ above ⇈ requires AutoHotkey_L to run

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

I often limit output to less than 80 characters.

Thanks for the example. That's very practical.

Join can be done very easily.

Even so, it makes sense to provide StrJoin() as a built-in function. Since it can be easily added later without breaking anything, it might wait until after the first stable release.

I can't think of any cases why I'd want to omit strings of characters.

My point was that one parameter accepting an array and the other parameter accepting a list of characters as a string would be inconsistent. Requiring OmitList to be an array like [A_Space, A_Tab] would be more consistent but less efficient. (I'll probably just go with the easiest approach: leave OmitList exactly the way it is.)

haichen
  • Members
  • 200 posts
  • Last active: Oct 20 2013 01:14 PM
  • Joined: 05 Feb 2007

I often limit output to less than 80 characters.

Here's a small wordwrap function:
wordwrap(text,linelength:=35){

 for key, val in StrSplit(text, A_Space, "`n`r")

 {

  if out <> ""

   le := "`n"

  if key=1

   line := val 

  else if (!mod(StrLen(line),linelength) or (StrLen(line)=0))

  {  

   Out .= le line 

   line := val 

  }

  else if ((mod(StrLen(line),linelength )+ StrLen(val) +1 ) > linelength) 

  {

   out .= le line  

   line := val 

  }

  else        

   line .=  " " val 

 }

 return out

}



infogulch
  • Moderators
  • 717 posts
  • Last active: Jul 31 2014 08:27 PM
  • Joined: 27 Mar 2008

Well obviously one can split a string word wrap with custom code, I thought that was self-evident enough not to mention but I guess not... :roll:

Deja-vu or is it just me?

Can we please skip all the "here's a function that does that" posts already? If someone mentions an example, they probably already have a custom function to do it.

Sometimes it's nice when the language you're using does some of the more simple and obvious things for you (faster I might add) without having to code it up and test it yourself, every time.


Lexikos: I would leave omitchars as is, I can't think of an example where I would want to omit strings, not just characters.
And I like the length-split idea. :)

haichen
  • Members
  • 200 posts
  • Last active: Oct 20 2013 01:14 PM
  • Joined: 05 Feb 2007

Can we please skip all the "here's a function that does that" posts already?

Sorry.. I don't do it again!

Frankie
  • Members
  • 2930 posts
  • Last active: Feb 05 2015 02:49 PM
  • Joined: 02 Nov 2008

Can we please skip all the "here's a function that does that" posts already?

Agreed. I'll do my best to remember.
aboutscriptappsscripts
Request Video Tutorials Here or View Current Tutorials on YouTube
Any code ⇈ above ⇈ requires AutoHotkey_L to run

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
I just noticed new Class returns a new object even if __New is defined but couldn't be called because required parameters were omitted. Should it be changed so that new fails in that case?

Frankie
  • Members
  • 2930 posts
  • Last active: Feb 05 2015 02:49 PM
  • Joined: 02 Nov 2008

Should it be changed so that new fails in that case?

Yes it should be changed. If you have some code in your __New function that's critical to class function (regardless of personal preferences) it should always run.

I get confused with class and prototype syntaxes existing at the same time. Is it possible to determine that new CN() is defined with a minimum of one argument, and thus should give an error? If I had to guess I'd (sadly) say it isn't.

The other side of this would be creating descendant objects dynamically. You did say "even if _New is defined." Well what if it isn't? Would the rules be different to allow the following? Or the same for the sake of consistency?
oFirst := {Prop: "Look at my property!"}
oCopy := new oFirst()
oCopy.Prop := "I have a different value.  I'm my very own object!"

Msgbox % oFirst.Prop
Msgbox % oCopy.Prop
Msgbox % oCopy.base = oFirst ; true in 1.1.01.00

aboutscriptappsscripts
Request Video Tutorials Here or View Current Tutorials on YouTube
Any code ⇈ above ⇈ requires AutoHotkey_L to run

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

I get confused with class and prototype syntaxes existing at the same time.

I've said this before: one is syntax, and the other is functionality. Class syntax "can be used to construct a base object" or in other words, a class is a prototype. If the apparent duality bothers you, just choose one way and stick with it.

Is it possible to determine that new CN() is defined with a minimum of one argument,

Yes.
MsgBox % CN.__New.MinParams  ; Includes the implicit "this" param.
MsgBox % IsFunc(CN.__New)  ; Can be given a function name OR reference.
class CN {
    __New(param) {
        ;...
    }
}

Well what if it isn't?

That is a different case to the specific one described in my previous post, and therefore would not be affected by the proposed change.

Your example is equivalent to this:
class oFirst
{
    static Prop := "Look at my property!"
}
oCopy := new oFirst()
... except that static initializers are always evaluated before the auto-execute section, and oFirst.__Class contains the string "oFirst". Would you want new oFirst() to fail in that case, since __New is not defined? (You don't need to answer that.)

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
v2.0-a017-5157e3d:
[*:vh7uefce]Merged v1.1.02.03.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
v2.0-a018-38235ab:
[*:1j5rhnxb]Merged v1.1.03.00.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
v2.0-a019-b56df88:
[*:3f1lt5p8]Merged v1.1.04 (WIP).I have more planned for v1.1.04, so it's not released yet. See the commit history for a full list of changes. The highlight of this release is try/catch/throw, coded mostly by fincs and reviewed by myself. It affects a large number of commands, so watch out for bugs.