![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
Topic Title: Peculiar behavior Topic Summary: Created On: 19-Feb-2008 15:51 Status: Post and Reply |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() |
|
I wrote a function just to strip whitespace(spaces, tabs, newlines) out of a string. Whats funny is that when I call it as such:
print trim(" hello ") "\n" I get back hello but without a new line after it. It's as if the call is ignoring the parentheses around the string and is operating on the strings for the entire line. If I call it like this: print (trim(" hello ")) "\n" I get the newline after hello. Am I nuts or is this a problem since, in my mind, the call to trim() should just be operating on " hello " since its wrapped in parenthesis. ------------------------- David Pechacek AAI Services Textron dpechacek@sc-aaicorp.com David.Pechacek@gmail.com Edited: 19-Feb-2008 at 15:54 by David Pechacek |
|
![]() |
|
![]() |
|
If I recall correctly Tony Goodman documented this behavior within the last couple of years
|
|
![]() |
|
![]() |
|
The fix is to wrap the functiona call in parentheses.
print (trim(" hello ")) "\n" Parentheses around single arguments are optional in DXL. In this case they get ignored by the interpreter, so the newline is concatenated with the " hello " to make " hello \n" which is then passed to the trim function. In other words, the following lines of code are all equivalent: print trim " hello \n" print trim " hello " "\n" print trim(" hello ") "\n" ------------------------- Tony Goodman http://www.smartdxl.com |
|
![]() |
|
![]() |
|
I knew they weren't required but I didn't think the interpreter ignored them.
I guess I've just been lucky that this hasn't effected me so far yet. Just sounds like a recipe for disaster if you ask me to ignore them. ------------------------- David Pechacek AAI Services Textron dpechacek@sc-aaicorp.com David.Pechacek@gmail.com |
|
![]() |
|
![]() |
|
Hard to imagine that anybody who says
print trim(" hello ") "\n" could possibly intend the newline inside the call. This behavior is clearly wrong. Did you submit a defect report? Did Telelogic reject it? - Louie |
|
![]() |
|
![]() |
|
To be honest I can't remember if I raised a case or not.
It would probably get put in the "Logged for consideration in a future release" category which I beleive is a cylindrical container under the desk. ;-) ------------------------- Tony Goodman http://www.smartdxl.com |
|
![]() |
|
![]() |
|
It's a problem of priority: the space operator is considered as a function call, and function are called from left to right.
On the other hand, parentheses do not have the same value as in C or Java: parentheses have no "function argument" meaning, but only "grouping", "casting" and "test condition" meaning. DXL is not C. That's the reason why I advise people I train never use parentheses around a single argument, because they aren't optional but useless, and give user a false opinion that he/she's using a more classical language. For the same reason, I encourage them using "of" anywhere meaningful: to remind them they're using DXL, with DXL rules and precedences. IMHO, the right DXL syntax there was: print (trim of " hello ") "\n" And for use of the C/Java syntax, simply don't use <space> that is an heresy from those syntax point of view: string concat(string a , string b) { return a b } print (concat (trim (" hello "), "\n")) ------------------------- E. Piallat CeBeNetwork |
|
![]() |
Telelogic DOORS
» DXL Exchange
»
Peculiar behavior
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.