AutoHotkey Community

It is currently May 24th, 2012, 6:36 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 60 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
 Post subject: concatenation
PostPosted: February 15th, 2007, 8:21 am 
Offline

Joined: December 29th, 2006, 6:57 am
Posts: 123
Location: Australia
I have found that AHK runs hand in glove with the basic dialect I use which is Rapidq.
I am pleased that it seems a mixture of c and basic with simple english commands.

It is this mix that I find confusing sometimes and the documentation although a massive work in itself often does not explain simple concepts
for instance adding two strings
in basic this is simple. I have found a way in AHK but
a = abc
b = def
c = a + b
msgbox c ; should = abcdef
it works this way
a = abc
b = def
c = %a%%b%
msgbox %c%

works but not logical >>>I wish!

_________________
(The guy from Oz)


Last edited by TeeTwo on February 15th, 2007, 11:54 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 15th, 2007, 11:19 am 
Offline
User avatar

Joined: December 20th, 2004, 12:19 pm
Posts: 794
Location: LooseChange911.com Ask Questions, Demand Answers █ The WTC bldgs █ shouldn't have fallen █ that fast
Your subject is useless...it should be...
    plus (+) should be concat(enation)
...but in any case...
...I AGREE...

_________________
AutoHotkey-Hotstring.ahk - Helping the world spell "AutoHotkey" correctly! (btw, it's a lowercase k!)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 15th, 2007, 11:30 am 
Indeed, I wish you change this subject...
It is like people putting "Help me" as subject in the Help section.
We haven't seen "My Script" in the script section (I didn't, at least), but it is in the same spirit...

Note: You have c = %a%%b%, but also c := a . b, so it has a real concatenation symbol already, no need to change it.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 16th, 2007, 12:51 am 
Offline

Joined: November 13th, 2004, 4:08 am
Posts: 2951
Location: Minnesota
Yes, we already have the concatenate operator, and I think that's better than overloading the plus (+) symbol. Unlike some other languages that use it for concatenation, AutoHotkey implicitly converts strings that contain a representation of a number into the number itself:
Code:
x := "23"
y := "8"
MsgBox % x . y  ; 238
MsgBox % x + y  ; 31


Which of the two cases above should '+' perform when both the strings are purely numeric? It's ambiguous, because of AHK's weak typing.

Besides, even without the ambiguity, why not have a separate operator for it? There's much less potential for confusion that way, especially for beginners who may not find '+' as concatenation to be very intuitive.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2007, 4:58 am 
Offline

Joined: December 29th, 2006, 6:57 am
Posts: 123
Location: Australia
Thanks for heads up you'r right about subject and I have changed it Sorry :oops:

It will take me a while as I easily reach for the + as I have gained bad habits not all related to scripting :)

Thanks for comments especially yours jonny. The others well! I stand corrected.

_________________
(The guy from Oz)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2007, 2:19 pm 
Offline
User avatar

Joined: December 20th, 2004, 12:19 pm
Posts: 794
Location: LooseChange911.com Ask Questions, Demand Answers █ The WTC bldgs █ shouldn't have fallen █ that fast
jonny wrote:
It's ambiguous, because of AHK's weak typing.

...yes, AHK should receive "typing"...in one of my concat posts I made an example of it...ok I can't find the post, so here...

Code:
x1:="23"
y1:="8"

x2:=23
y2:=8

MsgBox % x1+y1                          ;//238
MsgBox % x2+y2                          ;//31

MsgBox % toNum(x1)+toNum(y1)            ;//31
MsgBox % toString(x2)+toString(y2)      ;//238

jonny wrote:
Besides, even without the ambiguity, why not have a separate operator for it?

...because!...ok not a good enough reason?...well because! anyway...I like plus...I don't care if dot stays, but I want plus for strings too...

TeeTwo wrote:
...as I have gained bad habits...

...I don't see how using plus as concat is a "bad habit"...you are adding strings together, so + = add...you don't "dot" strings together...

_________________
AutoHotkey-Hotstring.ahk - Helping the world spell "AutoHotkey" correctly! (btw, it's a lowercase k!)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2007, 2:29 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
JSLover wrote:
you are adding strings together, so + = add...you don't "dot" strings together...
No, you are not adding them, you concatenate them, that's not the same operation. Or why is there a separate word?
Adding two string should be something like:
Code:
s1 = A string
s2 = Another string
l1 := StrLen(s1), l2 := StrLen(s2)
l := l1 > l2 ? l1 : l2
Loop %l%
{
   added .= Chr(Asc(SubStr(s1, A_Index)) + Asc(SubStr(s1, A_Index)))
}
MsgBox %added%
No? With perhaps some constrain on printable Ascii...

When I add 1 and 1, I don't expect to get 11... (10, at worse :-))

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2007, 4:49 am 
Offline

Joined: November 13th, 2004, 4:08 am
Posts: 2951
Location: Minnesota
I expect to get 0 with the overflow bit set. :P


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2007, 1:23 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
I prefer space as concatentation and to leave . for something kewl, like pseudo - classes.

Like, StdLib.MyFunction(...)

or for struct support: myStruct.myField := 4

Well, this can be done even now as "." is not concatenation but " . "

It will be confusing though...

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2007, 12:15 am 
Offline

Joined: November 13th, 2004, 4:08 am
Posts: 2951
Location: Minnesota
Wasn't this already discussed? Space as concatenation is horrible programming practice, mostly because it increases the chance of errors, but also because of ambiguity (not logical so much as visual). It doesn't even make much sense: an expression is not a specification for the construction of a string, it is a series of operations that may include data types ranging from numerical to boolean to textual.

Quote:
Well, this can be done even now as "." is not concatenation but " . "

It will be confusing though...


Actually, it can't, '.' not being a legal character in a variable name.

Also, the space padding issue should be seen to fairly soon:
Chris wrote:
Concerning the need for spaces around the dot, .=, and ? operators, I hope to resolve that in v2 (and possibly sooner for the dots).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2007, 6:55 am 
Offline

Joined: December 29th, 2006, 6:57 am
Posts: 123
Location: Australia
You sticks your toe in the water and the sharks bite.

I must say I do appreciate this. I am a concatenation of knowledge now.

_________________
(The guy from Oz)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2007, 12:59 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
majkinetor wrote:
I prefer space as concatentation
What about a concat assign operator?

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2007, 1:57 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
we can keep it :P

jonny wrote:
Actually, it can't, '.' not being a legal character in a variable name.

I didn't mean NOW, like NOW, but NOW like, AHK can be upgraded NOW to treat . as namespace delimiter as it can not be used in variable names and sentence Namespace.Variable is not valid in concatenation context...

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2007, 10:54 pm 
Offline

Joined: November 13th, 2004, 4:08 am
Posts: 2951
Location: Minnesota
Ah, I see. However, ideally Ident1.Ident2 would work (as concatenation).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 23rd, 2007, 1:38 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2537
jonny wrote:
Ah, I see. However, ideally Ident1.Ident2 would work (as concatenation).
No...


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 60 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 3 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