Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic Rhapsody (steve huntington)
Decrease font size
Increase font size
Topic Title: Q Language - subset "such that" expression
Topic Summary:
Created On: 15-May-2008 22:30
Status: Read Only
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
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.
 15-May-2008 22:30
User is offline View Users Profile Print this message


Sean Duggan

Posts: 29
Joined: 21-Apr-2008

I feel like I'm banging my head against a brick wall trying to understand the Q Language and how to use it in ReporterPlus. The long and short of it is that my team has set up this one diagram to show how the classes are organized into subpackages. The catch is that, for that diagram, they insist on using Packages to represent the classes (chiefly because they "look nicer"). So what I need to do is to scan through this list of Packages and check to see if there is a class which a corresponding name. I can go as far as determining whether such a class exists, but I am at a loss on how to actually access the matches. I think it may have something to do with "map" or "filter", but the documentation that came with Rhapsody only mentions the existence of such functions as "map", "filter", "sort", and "traverse" but does not deign to define or explain them. In fact, Telelogic support has gone so far as to tell me that these functions are undocumented by design!

Could anyone help me clarify this? To help, I have the code below with which I can prove the existence of a matching class for a given package:
if(there_exists x in model-> [project] -> [containedPackages] {$name = "Architecture"} -> [nestedPackages] {$name = "Interfaces"} -> [classes] => attribute("name", x) = ("I"+ $name)) then "Match" else "No Match"
Report this to a Moderator Report this to a Moderator
 16-May-2008 10:06
User is offline View Users Profile Print this message


Simon Morrish

Posts: 127
Joined: 17-May-2005

Hi Sean

I can relate to that feeling...

I'll assume you've got a node in ReporterPlus which is iterating through all the packages on your diagram, and you want to get the matching class for each? You can do so in this way:

  1. Create a subnode, within your packages iteration
  2. Select the Iteration tab and set it to iteration type "Class" (as opposed to "Association").
  3. Select "Class" from the dropdown, so that the iterated items are Classes.
  4. Select the Condition tab and paste this code in:
    <Specific Object>
    model
    -> [project]
    -> [containedPackages] { $name = "Architecture" }
    -> [nestedPackages] { $name = "Interfaces" }
    -> [classes] { $name = "I" + $name of this }
  5. The iteration will return the (single) class that matches the package, and you can access its attributes and relationships as you please.
In this case, it was not necessary to use the filter/traverse/map/sort statements, but you could do so if you wish. An alternative way to achieve the above is to substitute this condition:

<Specific Object>
filter {
$fullPathName of current -> [owner] = "Architecture::Interfaces"
and $name of current = "I" + $name of this
}
over
all "Class"


Please post back how you get on. If you have any problems getting this working, or if it's not quite what you want, I should be able to help further...

best regards,
Simon

-------------------------
Simon Morrish
simon.morrish@eu.panasonic.com
http://panasonic.co.uk
Panasonic ideas for life

Edited: 16-May-2008 at 10:06 by Simon Morrish
Report this to a Moderator Report this to a Moderator
 20-May-2008 14:48
User is offline View Users Profile Print this message


Sean Duggan

Posts: 29
Joined: 21-Apr-2008

Thank you, Simon. That actually worked out quite nicely. I even managed to work around the fact that my teammates were inconsistent about how they used spaces and underscores between the classes and packages by strategic use of the Replace function.

Mainly, I was very frustrated at the seeming lack of documentation for the Q Language, not to mention that I'm still getting my head wrapped around an expression-based language that lacks variables. Either situation by itself would be bad, but both together can get intolerable.
Report this to a Moderator Report this to a Moderator
 21-May-2008 22:57
User is offline View Users Profile Print this message


Sean Duggan

Posts: 29
Joined: 21-Apr-2008

I've got another one for you. Now, I have to list the classes which don't exist in one of the above packages. I still need to be displaying classes, so I couldn't just reverse the technique. I tried using the following advanced condition when iterating over all classes, but to no avail:
<Specific Object> model-> [project] -> [containedPackages] {$name = "Architecture"} -> [nestedPackages] {$name = "Interfaces"} -> [classes] {not (there_exists x in model-> [project] -> [containedPackages] {$name = "Architecture"} -> [nestedPackages] {$name = "Architecture"} -> [nestedPackages] -> [nestedPackages] => "I"+attribute("name", x) = $name of this)}

My intent was to search for all classes within the interface directory such that there does not exist a package in the sublayer with the same name. The problem is, this always matches.

I was able to do this to some degree using the following expression in the heading field (and a similar concept in the body field):
if (not (there_exists x in model-> [project] -> [containedPackages] {$name = "Architecture"} -> [nestedPackages] {$name = "Architecture"} -> [nestedPackages] -> [nestedPackages] => "I"+attribute("name", x) = $name of this)) then "Class " + $name else "";"";skip following

This works, but I have to apply it to every field beneath it, and I'm supposed to be displaying all of the operations, attributes, etc of the class. I don't want to have to stick that unwieldy if-expression in every location where I might display a value. Do you have any advice?
Report this to a Moderator Report this to a Moderator
 22-May-2008 09:28
User is offline View Users Profile Print this message


Simon Morrish

Posts: 127
Joined: 17-May-2005

Hi Sean

Yes; the problem with your first attempt is "$name of this". In a <Specific Object> iteration, the "this" keyword refers to the context of the iteration, not the context of each element returned by the iteration. So you're actually running the same test for each class, which will always return the same result; true, in your case.

Clearly, you'd like a way to refer to each class as you're testing it. Q provides the "current" keyword for this purpose, but there's a catch: once inside a there_exists clause, "current" evaluates to the same as "x". Bah.

This is where the "let" statement is helpful. Although Q doesn't provide variables in quite the usual sense, it does provide a means to remember values that you want to reuse in your expression, or to pass values to a sub-scope.

So, by saving "current" to a variable when the context is the class that you're testing, you can access it inside your there_exists clause:

<Specific Object>
model -> [project]
-> [containedPackages] {$name = "Architecture"}
-> [nestedPackages] {$name = "Interfaces"}
-> [classes] {
let c=current
in
not (
there_exists x in model -> [project]
-> [containedPackages] {$name = "Architecture"}
-> [nestedPackages] {$name = "Architecture"}
-> [nestedPackages] -> [nestedPackages]
=> "I"+attribute("name", x) = $name of c
)
}


I hope that helps!
best regards,
Simon

PS. I'm happy to help further; it keeps my Q language skills tuned. But I'd prefer to deal with each one in its own thread, if you don't mind.

-------------------------
Simon Morrish
simon.morrish@eu.panasonic.com
http://panasonic.co.uk
Panasonic ideas for life

Edited: 22-May-2008 at 09:30 by Simon Morrish
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic Rhapsody forum.
There are currently 1 users logged in.
You have posted 0 messages to this forum. 0 overall.

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