Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic DOORS (steve huntington)
Decrease font size
Increase font size
Topic Title: Peculiar behavior
Topic Summary:
Created On: 19-Feb-2008 15:51
Status: Post and Reply
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
Quick Reply Quick Reply
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
 19-Feb-2008 15:51
User is offline View Users Profile Print this message


David Pechacek

Posts: 674
Joined: 5-Dec-2006

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
Report this to a Moderator Report this to a Moderator
 19-Feb-2008 16:06
User is offline View Users Profile Print this message


ron lewis

Posts: 650
Joined: 20-Sep-2004

If I recall correctly Tony Goodman documented this behavior within the last couple of years
Report this to a Moderator Report this to a Moderator
 19-Feb-2008 16:27
User is offline View Users Profile Print this message


Tony Goodman

Posts: 1098
Joined: 12-Sep-2002

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
Report this to a Moderator Report this to a Moderator
 19-Feb-2008 18:22
User is offline View Users Profile Print this message


David Pechacek

Posts: 674
Joined: 5-Dec-2006

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
Report this to a Moderator Report this to a Moderator
 19-Feb-2008 21:13
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

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
Report this to a Moderator Report this to a Moderator
 20-Feb-2008 13:37
User is offline View Users Profile Print this message


Tony Goodman

Posts: 1098
Joined: 12-Sep-2002

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
Report this to a Moderator Report this to a Moderator
 23-Feb-2008 10:58
User is offline View Users Profile Print this message


Eric Piallat

Posts: 33
Joined: 26-Jan-2004

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
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 1 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 16:36.
There are currently 0 guests browsing this forum, which makes a total of 1 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.