![]() |
Telelogic Rhapsody (steve huntington) | ![]() |
Topic Title: Q Language - subset "such that" expression Topic Summary: Created On: 15-May-2008 22:30 Status: Read Only |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() |
|
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" |
|
![]() |
|
![]() |
|
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:
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 |
|
![]() |
|
![]() |
|
Thank you, Simon. That actually worked out quite nicely.
![]() 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. |
|
![]() |
|
![]() |
|
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? |
|
![]() |
|
![]() |
|
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: 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 |
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.