MetaCase Homepage
Forum Home Forum Home > > MetaEdit+
  New Posts New Posts RSS Feed - MERL generator
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

MERL generator

 Post Reply Post Reply
Author
Message
Saivignesh View Drop Down
Contributor
Contributor


Joined: 01.May.2017
Location: Netherlands
Points: 17
Post Options Post Options   Thanks (0) Thanks(0)   Quote Saivignesh Quote  Post ReplyReply Direct Link To This Post Topic: MERL generator
    Posted: 04.May.2017 at 10:39
Suppose I have an object1 and the object has properties (lets say name). I have made a decomposition to the object1 and I have an object2. How to write a generator for Object2 so that the name of Object1 is displayed in Object2?
Back to Top
stevek View Drop Down
MetaCase
MetaCase
Avatar

Joined: 11.Mar.2008
Points: 643
Post Options Post Options   Thanks (0) Thanks(0)   Quote stevek Quote  Post ReplyReply Direct Link To This Post Posted: 04.May.2017 at 10:56
A decomposition is from an object to a graph. That doesn't quite fit what you say, but maybe by "Object1" you actually mean "Graph1", and presumably then Object2 has a decomposition to Graph1.

In that case the MERL in Object2 to display the Name of Graph1 is:

do decompositions { :Name }

There's an example of this in the Digital Watch project, where the LogicalWatch objects have decompositions to WatchApplication graphs. Since we want the name of a LogicalWatch object to be the name of its decomposition graph, we don't need any properties in the LogicalWatch object itself. Instead, we set the LogicalWatch object type to use an identifier generator like the above code. Similarly, the symbol for LogicalWatch can use a text element with a similar generator (or, indeed, just id).
Back to Top
Saivignesh View Drop Down
Contributor
Contributor


Joined: 01.May.2017
Location: Netherlands
Points: 17
Post Options Post Options   Thanks (0) Thanks(0)   Quote Saivignesh Quote  Post ReplyReply Direct Link To This Post Posted: 04.May.2017 at 11:01
Nope. Thats is not what I meant. 

I have a new graph1. I have created an object (say object1 and it has a property name). I have a made a new graph2 for decomposition of Object1. I have created another Object (say Object2) in Graph2. I want to display the name of Object1 in Object2. 
Back to Top
stevek View Drop Down
MetaCase
MetaCase
Avatar

Joined: 11.Mar.2008
Points: 643
Post Options Post Options   Thanks (0) Thanks(0)   Quote stevek Quote  Post ReplyReply Direct Link To This Post Posted: 04.May.2017 at 11:45
OK. There isn't a unique answer in general, because the same subgraph Graph2 could be a decomposition of many objects - object1 and objectX in graph1, objectY in graphZ etc. As a general rule of conceptual modelling, it's better for an element to know its subelements, rather than for each subelement to know its parent. For instance, if you make Graph2 first (a bottom-up style of development: build the components, then put them together), there is no Graph1 or Object1, so no name to show for Object2.

Is Object1's name the same as Graph2's name, and creating an Object1 means you should also create the corresponding decomposition, Graph2? If so, there is a nice solution: what I described in my previous answer, plus that Object1's symbol has a text element with a generator id;1. The ;1 means to get the information not from the current element in MERL, but from one stack level further out. A symbol generator is called with the context of the graph then the object, so id;1 here will be the name of Graph2, and hence the name of Object1.

If that doesn't work, then you probably need to look a bit more at what you actually need in the modelling language and possible code generators. Certainly from the point of view of a code generator there isn't a need for Object2 to have a link to Object1 - your generator will have started from the top level, so it can simply get the name from the context stack with id;2 (assuming a stack of Graph1, Object1, Graph2, Object2), or then if it feels easier you could store the name of Object1 in a variable and use it later in Object2. The question then is more that why does the modeller need to see the name of Object1 in Object2 in Graph2. Generally that shouldn't be necessary: if I'm writing a function, I don't need (or want) to know the name of the calling function. We can have black box, grey box or white box components, with the difference as to whether the caller can see inside the callee, but never can the callee see inside the caller. 

I'd encourage you to think this through and aim for good modularization practices. I've seen too many bad examples to stay quiet on this :). Of course MERL is able to search through all graphs to find Object1:

$Graph2Name = id;1
do graphs
{  foreach .Object1Type; where decompositions = $Graph2Name
   {  id  }
}

But that's a different cost performance-wise as the number of graphs and objects grow. You can improve it somewhat by filtering to just graphs of the right type and avoiding performing the default sort on them:
do graphs where type='Graph1Type' orderby ''


Edited by stevek - 04.May.2017 at 13:49
Back to Top
Saivignesh View Drop Down
Contributor
Contributor


Joined: 01.May.2017
Location: Netherlands
Points: 17
Post Options Post Options   Thanks (0) Thanks(0)   Quote Saivignesh Quote  Post ReplyReply Direct Link To This Post Posted: 04.May.2017 at 12:37
Why is so complicated? Why can't I just inherit the name?
Back to Top
Saivignesh View Drop Down
Contributor
Contributor


Joined: 01.May.2017
Location: Netherlands
Points: 17
Post Options Post Options   Thanks (0) Thanks(0)   Quote Saivignesh Quote  Post ReplyReply Direct Link To This Post Posted: 04.May.2017 at 12:45
For my graph when I decompose object1. I can have only 1 object 2.
Back to Top
stevek View Drop Down
MetaCase
MetaCase
Avatar

Joined: 11.Mar.2008
Points: 643
Post Options Post Options   Thanks (0) Thanks(0)   Quote stevek Quote  Post ReplyReply Direct Link To This Post Posted: 04.May.2017 at 13:34
See my first paragraph above ^^^. The problem isn't the number of Object2s: there could be any number of those, and by your definition all would have the same name. The problem is the possible number of objects that have decompositions to Graph2. In general, across all modeling languages, there could be any number 0..N. That means MetaEdit+ can't give each object a single 'parent' or 'container' link to point to its graph (the same object may be used in multiple graphs), nor can it give each graph a single 'parent' or 'decomposesFrom' link to an object (the same graph may be the target of multiple decompositions). Rather than maintain back-links like these, MetaEdit+ has forward links: an object has a decomposition link to a graph, a graph has a link to the objects within it.

If you want a computer science explanation: the world is not a tree. In a tree every element has one parent (or none, for the root). The world isn't like that, so MetaEdit+ isn't like that: an element can have more than one parent (or more accurately, be referred to from more than one place). Even in a normal computer science tree data structure, where there is a unique parent, there is no way to navigate from an element to its parent. To do that, you need a different data structure: a doubly-linked tree. By doubling links, as some meta-metamodels do, you create high coupling and prevent modularization. Tools (and languages) based on those meta-metamodels have trouble scaling, in terms of modeller comprehension, tool performance, and productivity increase.

Think of a graph as a component or a function. A component or function shouldn't know who is using it. By not knowing, it becomes reusable - it has no link to or entanglement with its 'user', so it can be freely applied elsewhere.
Back to Top
Saivignesh View Drop Down
Contributor
Contributor


Joined: 01.May.2017
Location: Netherlands
Points: 17
Post Options Post Options   Thanks (0) Thanks(0)   Quote Saivignesh Quote  Post ReplyReply Direct Link To This Post Posted: 04.May.2017 at 13:39
Sorry I didnt understand a single word.!
Back to Top
stevek View Drop Down
MetaCase
MetaCase
Avatar

Joined: 11.Mar.2008
Points: 643
Post Options Post Options   Thanks (0) Thanks(0)   Quote stevek Quote  Post ReplyReply Direct Link To This Post Posted: 04.May.2017 at 13:48
Smile. Teaching and learning are both hard. Come back to this when you've made a few languages, and seen how different decisions in language design affect the benefits of language use, and maybe it will make more sense - or not. For now you'll just have to accept that in a new field, there will be things that sound like a good idea at first, but experience shows don't work. You have the freedom to do either, and I've even provided the MERL to go the 'seemed like a good idea at the time' route if that's your choice :).
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.05
Copyright ©2001-2022 Web Wiz Ltd.

This page was generated in 0.088 seconds.