James Posted July 12, 2013 Share Posted July 12, 2013 (edited) Referring to >this post: $Export_File = (StringRight(StringLower($Export_File), 4) == ".dma") ? $Export_File : $Export_File & ".dma" How do you suppose that is returning true? I suspect you aren't fully grasping how the ternary operator, or AutoIt's interpreter, works. The condition is tested, if its TRUE then what comes between '? .. :' is evaluated, otherwise what follows ':' is evaluated. After evaluation, if there is an assignment on the left hand side of the ternary expression, the result of the evaluated expression is then moved into that . Optimizing compilers (which AutoIt isn't) could possibly fix that flawed code by doing a no-op or an append, but its better to fix the problem where it starts - at the programmer level. My understanding of ternary is just fine, it just seems that the LParam is not set. In PHP and JavaScript you can do this: $bStartString = "James"; $sEndString = "Brooks"; $bAppendSurname = TRUE; $sFinalString = $bStartString . ($bAppendSurname ? " " . $bEndString : "") . ","; echo "Hello " . $sFinalString; Edit: Updated actual, decent example of LAssign with ternary. Edited July 12, 2013 by James Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Ascend4nt Posted July 12, 2013 Share Posted July 12, 2013 My understanding of ternary is just fine, it just seems that the LParam is not set. In PHP and JavaScript you can do this: $bStartString = "James"; $bEndString = "Brooks"; $bAppendSurname = TRUE; $bEndString = $bStartString . ($bAppendSurname ? " " . $bEndString : "") . ","; echo "Hello " . $bEndString; If your understanding of ternary is just fine, then your fingers must be acting on their own to do crazy things like assign a value to itself. But really, the problem has nothing to do with LValue-ness, but rather poor coding. It seems you want so desperately to use ternary operators that you're coming up with poor examples. That PHP code is also bad form (overwriting last name?), and pretty unreadable Try: $sStartString = "James"; $sEndString = "Brooks"; $bAppendSurname = TRUE; $sName = $sStartString; if ($bAppendSurname) $sName .= " " . $sEndString; echo "Hello " . $sName . ","; My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
James Posted July 12, 2013 Share Posted July 12, 2013 (edited) I was at work and very quickly wrote an example, I wasn't meant to overwrite the $bEndString variable, you can see I was rushing since I prefix a string variable with $b it should've been $s like $sStartString was. I've updated the example. Questioning my ability to write code is a bit off topic, if you have an issue with me or my code, please PM me. On topic again, the fact still remains that AutoIt doesn't support left-assign with ternaries. Edit: I never finished... Edited July 12, 2013 by James Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Ascend4nt Posted July 13, 2013 Share Posted July 13, 2013 James, I have no problem with you. You seem like a decent enough person. I was discussing the bad code being used as examples. I don't see why you think it's off topic, as it had to do with someone not fully understanding, or at least not showing their understanding in a satisfactory way, of the way ternary operators work. In other words, the discussion could help others understand where not to use ternary operators, which is why its relevant. Looking at your revised PHP code now, the changes you made to create a 'decent example' is still missing the mark in two areas. In the False case, a "" or non-assignment is done. The primary reason to use ternary operators is to give one of two results or expressions with some meaning to them. The code lacks readability. If a one-line statement can't be understood without rereading it a few times, it shouldn't be written. My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
James Posted July 13, 2013 Share Posted July 13, 2013 It may not be a perfect example, but AutoIt isn't a perfect language. The example I posted (and updated) illustrates the issue with it. Whether or not it degrades the way I write code or not. It doesn't work as it does in other languages. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
trancexx Posted July 13, 2013 Share Posted July 13, 2013 James, which code doesn't do what you expect it to? ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
czardas Posted July 13, 2013 Share Posted July 13, 2013 (edited) If I produce a bad example, I'd like it if others tell me about it. Some people might take offence at having their code scrutinized by others, however I believe it's generally a fruitful and rewarding process in the long term. On a different note: Anyone can make mistakes, also in English - and especially if you learn English online. I sometimes wonder why some people express themselves the way they do. Recently an Italian user said shite (which to me is Scouse slang) when he meant to say SciTE. It was just a typo, but I'm sure that the user was unaware of how insulting it came across even after I had pointed out the mistake. Edited July 13, 2013 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
James Posted July 13, 2013 Share Posted July 13, 2013 If I produce a bad example, I'd like it if others tell me about it. Some people might take offence at having their code scrutinized by others, however I believe it's generally a fruitful and rewarding process in the long term. I'm not taking umbrage, I'm just trying to come up with an example that was meant to portray the problem. @Ascend4nt, whether it's correct in your head or not, it's a fully working example. @trancexx You should be able to get the result of a ternary expression and then perform another expression on it. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
trancexx Posted July 13, 2013 Share Posted July 13, 2013 @trancexx You should be able to get the result of a ternary expression and then perform another expression on it. Hm, and you can't? I don't see how your PHP example written in AutoIt misbehaves. Do you get anything unexpected when your run this: $bStartString = "James" $sEndString = "Brooks" $bAppendSurname = True $sFinalString = $bStartString & ($bAppendSurname ? " " & $sEndString : "") & "," ConsoleWrite("Hello " & $sFinalString & @CRLF) ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
czardas Posted July 13, 2013 Share Posted July 13, 2013 (edited) I'm not taking umbrage, I'm just trying to come up with an example that was meant to portray the problem. Thank you James, I find the discussion quite useful. Although I haven't used the conditional operator, it seems straight forward enough. >This example by Mat is very informative: Edited July 19, 2013 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now