| View previous topic :: View next topic |
| Author |
Message |
Joy2DWorld
Joined: 04 Dec 2006 Posts: 422 Location: Galil, Israel
|
Posted: Mon Jun 18, 2007 10:08 am Post subject: ?() function parse error ? [ie. function "?" not r |
|
|
| Code: |
?(123)
?(x = 0) {
return x
} |
used to work for me....
not working right now... ( v46.15)
although if you decide to leave it not working... that's ok too...
it has the neat side effect of allowing such things as:
which is nice since math with nulls gets nulled.... _________________ Joyce Jamce |
|
| Back to top |
|
 |
Joy2DWorld
Joined: 04 Dec 2006 Posts: 422 Location: Galil, Israel
|
Posted: Mon Jun 18, 2007 10:10 am Post subject: |
|
|
if not explicit enough:
expression gets evaluated,
function does not get called. _________________ Joyce Jamce |
|
| Back to top |
|
 |
Helpy Guest
|
Posted: Mon Jun 18, 2007 10:43 am Post subject: |
|
|
Chances are, it has been broken when the ternary operator ? : has been introduced, it created some minor incompatibilities with the ? identifier.
You can double it or add an underscore, etc.
| Code: | msgbox % ??(123)
??(x = 0) {
return x
} |
|
|
| Back to top |
|
 |
Joy2DWorld
Joined: 04 Dec 2006 Posts: 422 Location: Galil, Israel
|
Posted: Mon Jun 18, 2007 1:18 pm Post subject: |
|
|
actually it was working (post ? : ternary)...
and if it's being broken is 'Official', ie. "?" as a special 'null' function which will evaluate expressions and otherwise act as a null value... that's pretty cool too.
isn't a valid line,
but inside of ?(a < 10 || a := 23) , etc. works great.
(ps.. would be nice to have it a true null, ie. be able to add to strings & nums without error...) _________________ Joyce Jamce |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4015 Location: Pittsburgh
|
Posted: Mon Jun 18, 2007 2:59 pm Post subject: |
|
|
| Joy2DWorld wrote: | | actually it was working (post ? : ternary)... | Even if it did, it is not a good idea to use an operator also as a function name.
| Joy2DWorld wrote: | a < 10 || a := 23 isn't a valid line,
but inside of ?(a < 10 || a := 23) , etc. works great. | An expression cannot normally be used as a statement. It is evaluated as a function argument or in the right hand side of an assignment: _:= a < 10 || a := 23. It does not make sense as a statement: the a < 10 || part does not perform any command. |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3626 Location: Belgrade
|
Posted: Mon Jun 18, 2007 6:19 pm Post subject: |
|
|
Typical example of wrong programming style, nothing more.
Although it may be tempting to create souch "language workarounds" you shouldn't do so. _________________
 |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Tue Jun 19, 2007 1:31 am Post subject: |
|
|
| I tried a function name of "?" with 1.0.46.00 (the first ternary version) and it didn't work there either. Although this limitation isn't documented, it might be too obscure to mention. I could try to change the program to support it, but it might not be worth the R&D. |
|
| Back to top |
|
 |
Joy2DWorld
Joined: 04 Dec 2006 Posts: 422 Location: Galil, Israel
|
Posted: Tue Jun 19, 2007 4:33 am Post subject: |
|
|
Right now,
lines with ?(...) are just ignored, but the expression within the call is evaluated, WITHOUT gen of any error if nonsense present.
That fine for my needs.
??(...) works as expected.
if debug efforts seem less important than investment in cool new powers and development for AHK, cool.
but **PLEASE**,
**PLEASE**,
document (in the docs), this and *ALL* OTHER syntax that does not work as otherwise documented. What may be "obscure" to you, may be normal as daylight for someone else.
something like,
IF YOU DOCUMENT THE BEHAVIOR, IT IS NOT A BUG _________________ Joyce Jamce |
|
| Back to top |
|
 |
Joy2DWorld
Joined: 04 Dec 2006 Posts: 422 Location: Galil, Israel
|
Posted: Tue Jun 19, 2007 4:42 am Post subject: |
|
|
@Laszlo,
| Quote: | | _:= a < 10 || a := 23. It does not make sense as a statement: the a < 10 || part does not perform any command. |
actually:
1. it makes sense. the result (_) is the LOGICAL or'd value of the two expressions. If one is true.. result is true. if not, not.
2. in the sense that assignment of value to a var is a command, if a <10, a is set to 23, ie. a command is performed.
3. the operator "?" is used to test condition, and assign value thereon (true or false), functions are in a sense langauge extensions, so a function ?( ... ) that assigns value based on test, eg. ?( a < 10 || a := 20), or ?( a<10 and b:=20 || c := 20), etc... has to my view at least, some merit as legit syntax. Would be nice if function could return value.. but not at all necessary, and merit in being able to string expressions w/out regard to function expectations [as is currently the fact w/ the 'bug'].
anyhow... just sharing view. _________________ Joyce Jamce |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4015 Location: Pittsburgh
|
Posted: Tue Jun 19, 2007 6:49 am Post subject: |
|
|
| Joy2DWorld wrote: | @Laszlo,
| Quote: | | _:= a < 10 || a := 23. It does not make sense as a statement: the a < 10 || part does not perform any command. |
| Cutting sentences in half in quotes can falsify the original meaning. I said that the assignment makes sense, but the right hand side alone does not. The expression gets evaluated to a logic value, but nothing is done with it. In many languages it is allowed, but in this particular example only a := 23 has an effect, the rest is nonsense.
| Joy2DWorld wrote: | | a function ?( ... ) that assigns value based on test | There are always obvious language constraints not explicitly documented. +( ...) or *( … ) is not a function call. They are operators in front of some bracketed expressions. The same is ?( … ). Depending on the surroundings, this can be part of a ternary operator. Allowing operators as function names just makes a lot of obscure syntactic rules necessary, and makes the programs less legible.
?( … ) should actually be an incomplete ternary operator, with empty condition and missing false_part:
condition ? (true_part) : (false_part)
The ": (false_part)" could be optional, like the spaces around operators, so the most obvious interpretation of ?( … ) is to ignore it, because an empty condition is false, and so the true_part in the ternary operator should not be evaluated. |
|
| Back to top |
|
 |
Joy2DWorld
Joined: 04 Dec 2006 Posts: 422 Location: Galil, Israel
|
Posted: Wed Jun 20, 2007 6:54 am Post subject: |
|
|
| Quote: | | Cutting sentences in half in quotes can falsify the original meaning |
indeed.
no misquote intended.
my suggestion was that as expression evaluation combines the possibility of ASSIGNMENT of values, with logical processing of those assignments (OR, and), pure expression evaluation has value in AHK.
right now ?(..) allows for pure expression evaluation... which maybe is a nice thing to include in the intentional language syntax.
? is included in the class of valid var assignment characters, and thus sub labels and thus function names.
no-space preceding opening function paren is a rule of AHK syntax... so that the langauge overall design anticipates ? ( being seperate in operataion from ?( as is xxx (xxx) from xxx( xxx ).
Interestingly, ? can be used as a valid variable reference....
| Code: | d = ?
%d% = 15
msgbox %?% |
as can "OR", etc..
| Code: | or = 15
msgbox %or% |
_________________ Joyce Jamce |
|
| Back to top |
|
 |
|