czardas Posted January 6, 2014 Share Posted January 6, 2014 (edited) Okay, I still don't like the name 'ternary operator'. I think it breaks some ground rules. Edited January 6, 2014 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
trancexx Posted January 6, 2014 Share Posted January 6, 2014 Okay, I still don't like the name 'ternary operator'. I think it breaks some ground rules.What are you talking abut czardas?! The reason this operator is called "the ternary operator" is because it's the only ternary operator in the language. An alternative is to call it "question_mark_colon" operator, or maybe not even calling it at all.If "plus" is the only binary operator it would also be called "the binary operator". But it's not so it's called "binary operator plus" or simply fucking "plus".I used word "fucking" as modifier, not unary operator. czardas 1 ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Mobius Posted January 6, 2014 Share Posted January 6, 2014 (edited) What are you talking abut czardas?! The reason this operator is called "the ternary operator" is because it's the only ternary operator in the language. An alternative is to call it "question_mark_colon" operator, or maybe not even calling it at all.If "plus" is the only binary operator it would also be called "the binary operator". But it's not so it's called "binary operator plus" or simply fucking "plus".I used word "fucking" as modifier, not unary operator. Well met. Edited January 6, 2014 by Mobius Link to comment Share on other sites More sharing options...
czardas Posted January 6, 2014 Share Posted January 6, 2014 (edited) It doesn't matter what I'm on about. Mat's links exposed my misunderstanding, but even so: someone has to challenge mainstream opinion. I do not like the naming strategy becasue it conflicts with other interpretations of both the word 'ternary' and 'argument'. There are the three arguments that you see plus the two that I see. Where would programming be without logic? ; MsgBox(0, "czardas is", Random(0 ,1, 1) ? "stupid" : "not stupid") ; As for my idea of a ternary operator, am I to now call that a quaternary operator when it is an implimentation in TVL? That hurts a lot I'm afraid. Edited January 6, 2014 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Mat Posted January 6, 2014 Share Posted January 6, 2014 It definitely doesn't conflict with the meaning of "argument". Ternary is used in a lot of places, the fact it's a ternary "operator" is the difference. A ternary "operator" could easily work with ternary "logic" if it wanted to. AutoIt Project Listing Link to comment Share on other sites More sharing options...
czardas Posted January 6, 2014 Share Posted January 6, 2014 (edited) My argument is this: there is a conflict. Is this misuse of the word argument? No it's just a different meaning of the word which also applies, in context to this operator, with equal validity. I take on board your arguments, but the justification seems somewhat tenuous. I'm obviously not going to win this one. Edit Actually Mat's links did jog my memory (thanks). I have come across this use of the word 'argument' previously in school all those years ago. I remember thinking it was stupid back then. I still see no justification for this counterintuitive terminology. Until I'm presented with a reasonable case for it, I have no reason to change my opinion. Peer pressure is not always enough. If it makes sense to everyone else then fine - to me it's a semantic collision which is simply too close to for comfort. This is my only criticism, but one I feel is important enough to maintain. It is my conviction that programming should be accessible to all in the future, and not continue its current course towards impregnable terminology. To me an argument must have a point. Random(0, 1, 1) does not have a point and is therefore no argument. I'm finished. Edited January 7, 2014 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
DatMCEyeBall Posted January 7, 2014 Share Posted January 7, 2014 (edited) Is it possible to assign a value with the ternary operator in C++? You know: = - assignment == - expression I'd call it "The_two_choice_operator_based_on_three_arguments_thingy" Edited January 7, 2014 by DatMCEyeBall "Just be fred, all we gotta do, just be fred." -Vocaliod "That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha @tabhooked Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation Link to comment Share on other sites More sharing options...
guinness Posted January 7, 2014 Share Posted January 7, 2014 Is it possible to assign a value with the ternary operator in C++? You know: = - assignment == - expression I'd call it "The_two_choice_operator_based_on_three_arguments_thingy" Well, best check before asking. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Mat Posted January 7, 2014 Share Posted January 7, 2014 Is it possible to assign a value with the ternary operator in C++? You know: = - assignment == - expression I'd call it "The_two_choice_operator_based_on_three_arguments_thingy" Assignment *is* an expression. So "true ? (a = 5) : (a = 6)" would return 5, and assign the value of 5 to a. AutoIt Project Listing Link to comment Share on other sites More sharing options...
DatMCEyeBall Posted January 7, 2014 Share Posted January 7, 2014 Yes. #include <iostream> using namespace std; int main(int argc, char *argv[]) { int a = 0; int b = 22; cout << "Before: " << a << "\n"; (b == 23) ? (a = 12) : (a = 13); // b <> 23, so a = 13 cout << "After: " << a << "\n"; system("PAUSE"); return 0; } "Just be fred, all we gotta do, just be fred." -Vocaliod "That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha @tabhooked Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation Link to comment Share on other sites More sharing options...
Richard Robertson Posted January 7, 2014 Share Posted January 7, 2014 AutoIt doesn't let you make assignments mid-expression. Assignment can only occur at the statement level, and the ternary (?: for czardas) operator handles expressions, not statements. czardas 1 Link to comment Share on other sites More sharing options...
czardas Posted January 7, 2014 Share Posted January 7, 2014 (edited) ... and the ternary (?: for czardas) operator ... thx! I'm going to play with my quaternary_three_value_logic_conditional_operator soon. Until then, I'll go with the flow. Edited January 7, 2014 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
DatMCEyeBall Posted January 7, 2014 Share Posted January 7, 2014 The "flow" being _Iif()? czardas 1 "Just be fred, all we gotta do, just be fred." -Vocaliod "That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha @tabhooked Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation Link to comment Share on other sites More sharing options...
Tlem Posted January 9, 2014 Share Posted January 9, 2014 (edited) As we are in Dev forum and this topic ask for clarification about ternary operator, I would like to know if there is a chance to have the same new syntax like in php 5.3 ? As kylomas write in the first post, we can write the expression like this : $Var = (@Condition) ? $ExpTrue : $ExpFalse In php we can write : $Return = $Var1 ? $Var1 : $Var2; and contract it in : $Return = $Var1 ?: $Var2; Do you think that it will be possible to have the same syntax in future version of AutoIt ? Edited January 9, 2014 by Tlem Best Regards.Thierry Link to comment Share on other sites More sharing options...
DatMCEyeBall Posted January 9, 2014 Share Posted January 9, 2014 Last one is the @Condition $Var1 and the true expression also $Var1? That could prove useful... "Just be fred, all we gotta do, just be fred." -Vocaliod "That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha @tabhooked Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation Link to comment Share on other sites More sharing options...
guinness Posted January 9, 2014 Share Posted January 9, 2014 What, another macro? UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
DatMCEyeBall Posted January 9, 2014 Share Posted January 9, 2014 What, another macro? @Condition isn't a macro, it's something that Tlem used to describe the condition in the ternary operator example that he posted. ; This $Return = $Var1 ? $Var1 : $Var2; ; Convert (shows the contraction process) $Return = $Var1 ?[$Var1]: $Var2; ; Can be this (The first expression (the "Run on true") one is omitted and in the contracted one the conditional statement becomes the "Run on true" expression) $Return = $Var1 ?: $Var2; "Just be fred, all we gotta do, just be fred." -Vocaliod "That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha @tabhooked Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation Link to comment Share on other sites More sharing options...
trancexx Posted January 10, 2014 Share Posted January 10, 2014 I explicitly disallowed that back then in hope someone would ask for it in future. (It should have been nice game that I never got to play.) Yes, it's possible. Make feature request and see what Jon says. This isn't just syntactic sugar, being able to omit second argument makes valuable difference. For example here: $c = $a ? $a : $b ... $a is evaluated twice, whereas here: $c = $a ?: $b ...only once. At first you may not realize the quality of the difference, until you gear-up and imagine what would happen if $a isn't simple variable but, for example function call. In former case, that function would possibly be called twice based on it's return. All in all, it would make nice addition to the feature jaberwacky and Xandy 2 ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Richard Robertson Posted January 10, 2014 Share Posted January 10, 2014 I explicitly disallowed that back then in hope someone would ask for it in future. (It should have been nice game that I never got to play.) Yes, it's possible. Make feature request and see what Jon says. This isn't just syntactic sugar, being able to omit second argument makes valuable difference. For example here: $c = $a ? $a : $b ... $a is evaluated twice, whereas here: $c = $a ?: $b ...only once. At first you may not realize the quality of the difference, until you gear-up and imagine what would happen if $a isn't simple variable but, for example function call. In former case, that function would possibly be called twice based on it's return. All in all, it would make nice addition to the feature If you are calling a function twice due to checking its return value for non-false-equivalence, then you need to cache better. Link to comment Share on other sites More sharing options...
trancexx Posted January 10, 2014 Share Posted January 10, 2014 AutoIt is known by its lazy evaluation strategy, so no that's never the case. You misunderstood me if you assume something like that. ♡♡♡ . eMyvnE 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