AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

?() function parse error ? [ie. function "?" not r

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
Joy2DWorld



Joined: 04 Dec 2006
Posts: 422
Location: Galil, Israel

PostPosted: Mon Jun 18, 2007 10:08 am    Post subject: ?() function parse error ? [ie. function "?" not r Reply with quote

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:

Code:
?(x || x := 0)


which is nice since math with nulls gets nulled....
_________________
Joyce Jamce
Back to top
View user's profile Send private message
Joy2DWorld



Joined: 04 Dec 2006
Posts: 422
Location: Galil, Israel

PostPosted: Mon Jun 18, 2007 10:10 am    Post subject: Reply with quote

if not explicit enough:


expression gets evaluated,
function does not get called.
_________________
Joyce Jamce
Back to top
View user's profile Send private message
Helpy
Guest





PostPosted: Mon Jun 18, 2007 10:43 am    Post subject: Reply with quote

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

PostPosted: Mon Jun 18, 2007 1:18 pm    Post subject: Reply with quote

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.


Quote:
a < 10 || a := 23
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
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4015
Location: Pittsburgh

PostPosted: Mon Jun 18, 2007 2:59 pm    Post subject: Reply with quote

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
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Mon Jun 18, 2007 6:19 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Tue Jun 19, 2007 1:31 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Joy2DWorld



Joined: 04 Dec 2006
Posts: 422
Location: Galil, Israel

PostPosted: Tue Jun 19, 2007 4:33 am    Post subject: Reply with quote

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
View user's profile Send private message
Joy2DWorld



Joined: 04 Dec 2006
Posts: 422
Location: Galil, Israel

PostPosted: Tue Jun 19, 2007 4:42 am    Post subject: Reply with quote

@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
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4015
Location: Pittsburgh

PostPosted: Tue Jun 19, 2007 6:49 am    Post subject: Reply with quote

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
View user's profile Send private message
Joy2DWorld



Joined: 04 Dec 2006
Posts: 422
Location: Galil, Israel

PostPosted: Wed Jun 20, 2007 6:54 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group