cspears2002 Posted February 24, 2007 Share Posted February 24, 2007 My instructor showed me an expression: bbox(strcat("../xform_move_me_", atof(opdigits(".")-1)), D_XMAX) My confusion stems from the following: / -> exhelp opdigits float opdigits (string name) / -> exhelp atof float atof (string source) Will forcibly convert a string into a float According to exhelp, both functions return floats. In just about every programming or scripting language I know of, concatenating a string and a float results in an error. Why doesn't the bbox expression above cause some sort of error? Quote Link to comment Share on other sites More sharing options...
grasshopper Posted February 24, 2007 Share Posted February 24, 2007 My instructor showed me an expression:bbox(strcat("../xform_move_me_", atof(opdigits(".")-1)), D_XMAX) My confusion stems from the following: / -> exhelp opdigits float opdigits (string name) / -> exhelp atof float atof (string source) Will forcibly convert a string into a float According to exhelp, both functions return floats. In just about every programming or scripting language I know of, concatenating a string and a float results in an error. Why doesn't the bbox expression above cause some sort of error? Actually there are plenty of languages out there that do implicit type conversions based on context which is what hscript is doing here. strcat needs strings as arguments so if it sees integers or floats it simply converts them for you. Perl is a good example of a language where implicit type conversions like this are common. For example, in Perl you can have: $string = "Hello" # Quotes denote strings $int = 42 # No quotes denote integers or floats print $string . $int > Hello42 Quote Link to comment Share on other sites More sharing options...
rdms Posted February 24, 2007 Share Posted February 24, 2007 My instructor showed me an expression:bbox(strcat("../xform_move_me_", atof(opdigits(".")-1)), D_XMAX) My confusion stems from the following: / -> exhelp opdigits float opdigits (string name) / -> exhelp atof float atof (string source) Will forcibly convert a string into a float According to exhelp, both functions return floats. In just about every programming or scripting language I know of, concatenating a string and a float results in an error. Why doesn't the bbox expression above cause some sort of error? As grasshopper already noted, the "str" expressions convert the arguments on the fly to a string type. For example, if you did: strcat("foo","1") strcat("foo",1) strcat(foo,1) strcat(foo,"1") the result is always foo1. What I didn't understand in your expression was the section atof(opdigit(".")-1) . You are right that opdigit returns a float so I'm not sure why you'd put the atof before it. It still evaluates the same if you remove the atof. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.