| View previous topic :: View next topic |
| Author |
Message |
TeeTwo
Joined: 29 Dec 2006 Posts: 123 Location: Australia
|
Posted: Thu Feb 15, 2007 7:21 am Post subject: concatenation |
|
|
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 Thu Feb 15, 2007 10:54 am; edited 1 time in total |
|
| Back to top |
|
 |
JSLover
Joined: 20 Dec 2004 Posts: 634 Location: LooseChange911.com The WTC bldgs shouldn't have fallen that fast. The official story is a lie!
|
Posted: Thu Feb 15, 2007 10:19 am Post subject: Re: plus (+) should be concat(enation) |
|
|
Your subject is useless...it should be...
plus (+) should be concat(enation) ...but in any case...
...I AGREE... _________________
Home • Click image! • Blog |
|
| Back to top |
|
 |
Grumpy Guest
|
Posted: Thu Feb 15, 2007 10:30 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 2951 Location: Minnesota
|
Posted: Thu Feb 15, 2007 11:51 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
TeeTwo
Joined: 29 Dec 2006 Posts: 123 Location: Australia
|
Posted: Tue Feb 20, 2007 3:58 am Post subject: |
|
|
Thanks for heads up you'r right about subject and I have changed it Sorry
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) |
|
| Back to top |
|
 |
JSLover
Joined: 20 Dec 2004 Posts: 634 Location: LooseChange911.com The WTC bldgs shouldn't have fallen that fast. The official story is a lie!
|
Posted: Tue Feb 20, 2007 1:19 pm Post subject: |
|
|
| 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... _________________
Home • Click image! • Blog |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6836 Location: France (near Paris)
|
Posted: Tue Feb 20, 2007 1:29 pm Post subject: |
|
|
| 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 ) _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 2951 Location: Minnesota
|
Posted: Wed Feb 21, 2007 3:49 am Post subject: |
|
|
I expect to get 0 with the overflow bit set.  |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4511 Location: Belgrade
|
Posted: Wed Feb 21, 2007 12:23 pm Post subject: |
|
|
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... _________________
 |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 2951 Location: Minnesota
|
Posted: Wed Feb 21, 2007 11:15 pm Post subject: |
|
|
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). |
|
|
| Back to top |
|
 |
TeeTwo
Joined: 29 Dec 2006 Posts: 123 Location: Australia
|
Posted: Thu Feb 22, 2007 5:55 am Post subject: |
|
|
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) |
|
| Back to top |
|
 |
polyethene
Joined: 11 Aug 2004 Posts: 5248 Location: UK
|
Posted: Thu Feb 22, 2007 11:59 am Post subject: |
|
|
| majkinetor wrote: | | I prefer space as concatentation | What about a concat assign operator? _________________ GitHub • Scripts • IronAHK • Contact by email not private message. |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4511 Location: Belgrade
|
Posted: Thu Feb 22, 2007 12:57 pm Post subject: |
|
|
we can keep it
| 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... _________________
 |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 2951 Location: Minnesota
|
Posted: Thu Feb 22, 2007 9:54 pm Post subject: |
|
|
| Ah, I see. However, ideally Ident1.Ident2 would work (as concatenation). |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2485
|
Posted: Fri Feb 23, 2007 12:38 am Post subject: |
|
|
| jonny wrote: | | Ah, I see. However, ideally Ident1.Ident2 would work (as concatenation). | No... |
|
| Back to top |
|
 |
|