Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1
Send Topic Print
Experimenting with Inheritance (Read 8641 times)
SteveS
Full Member
*
Offline



Posts: 15

Experimenting with Inheritance
Oct 04th, 2013, 12:44am
 
I have a model of my software consulting business in excel, including pseudo-OO VBA code to keep track of current customers, employees, expenses, revenue, profit etc.  It is a bit cumbersome to use.

I decided to try to create a similar Tinderbox model, and the found myself drawn to the idea of trying to simulate some OO concepts in the model.

Specifically
  • Deep inheritance of key attributes
  • Deep inheritance of rules


I made some very interesting progress on deep inheritance of key attributes, and had some issues with rules.

I next decided to see if I could create a way to "wire" inheritance/prototype tress by via relationships, and i have struggled with this a bit as well.

I am going to start back at the beginning, and work through the goals in a logical chronology, refactoring and establishing conventions, and asking for help as needed, and sharing my ideas.

Whether or not this exercise will end up being useful is yet to be seen, but it has been lots of fun, and a great way to learn more about Tinderbox coding.  My end goal is to apply useful inheritance techniques to my consulting business model.

Stay Tuned!
Steve
Back to top
 
 
  IP Logged
SteveS
Full Member
*
Offline



Posts: 15

Re: Experimenting with Inheritance
Reply #1 - Oct 4th, 2013, 2:15am
 
FOUNDATION

General Concepts

    * Prototypes serve as pseudo "classes"
    * Notes that use use prototypes serve as pseudo "sub-classes"
    * Sub classes should deeply inherit all key attributes form it's parent class
    * Sub classes should deeply inherit rules form it's parent class (?)
    * It is useful to provide a way to "wire" up sub-classes to prototypes through a particular relationship type (for easy prototype assignment and visual clarity)

Conventions:

    * The prefix "Inh" is used for note names, attributes, etc that are directly used to support inheritance
    * All non-built in class/subclass names begin with "<"
    * "virtual" classes (never meant to be used directly) have names that begin with "<-"
    * "concrete" classes (meant to be used directly)  have names that begin with "<="
    * code blocks that represent rules for classes are defined in separate notes that use "Code" as a prototype, and the name of the code block will be "cd<-className".  For example, rules for the root note "<-InhRootNote" are defined in the note named "cd<-InhRootNote"

Structure:

    * There is a single root note [<-InhRootNote] that provides the foundational rules for attribute and rule (I hope) inheritance of derived classes.  All sub-classes that you wish to support deep inheritance must be a descendant of this root note.
    * The relationship type "InhUsesPrototype" is used to wire up a subclass to a parent class.  Create the intended sub-class (w/o specifically indicating prototype), then create relationship from intended sub-class to intended parent class of the type "InhUsesPrototype", and the sub-class should automatically have the proper parent class prototype assigned based on rules defined in [<-InhRootNote] (not currently working)

Back to top
 
 
  IP Logged
SteveS
Full Member
*
Offline



Posts: 15

Re: Experimenting with Inheritance
Reply #2 - Oct 4th, 2013, 2:28am
 
WIRING INHERITANCE

Based on the previous posts, I have created a rule in [<-InhRootNote], defined in [cd<-InhRootNote], that is meant to assign prototypes to "derived" classes, for all notes that have an inbound link of type [InhUsesPrototype], here is the code snippet:
--------------------------------------------------------------------
$InhMySubClasses=links.inbound."InhUsesPrototype".$Path;
$InhMySubClasses.each(curSub)
{
     $Prototype(curSub)=this.$Name;
};
--------------------------------------------------------------------

This appears not to be working.  As soon as I figure out how to post images and attach TBX files, I will provide supporting evidence.

If I can get any insight as to why this prototype assignment code is not working, that would be greatly appreciated.

Cheers
Steve
Back to top
 
 
  IP Logged
SteveS
Full Member
*
Offline



Posts: 15

Re: Experimenting with Inheritance
Reply #3 - Oct 4th, 2013, 2:32am
 
PLEASE ADVISE:
- how do I upload/post an image to this forum
- how do i upload a TBX file to this forum
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Experimenting with Inheritance
Reply #4 - Oct 4th, 2013, 4:04am
 
In this answer I need refer to BBCode, the mark-up used by this forum. BBCode uses square [ ] brackets for inline codes.  As I can't use them here without them being turned into mark-up, I'll use curly brackets {} instead, e.g. an example of bolding a word: this will become {b}bold{/b} text in the posted message.

OK, the answer to both your questions is, you can't upload files to this forum, you need to refer to them. The forum has no provision for such features. So first upload your image or file to your own webspace or use dropbox etc. If you're only going to keep the asset at that URL for a short while it's worth noting the fact in the post where you'll place the link.

Images
Image insertion in a post looks, in edit mode like this:

  {img}http://example.com/somepic.png{img};

Or, paste the image URL into your post's edit box, select the URL and click the image button. this is the 3rd icon, top row, of the buttons  above the edit box. Tip: to get readable spacing above below the image in the resulting post, place the image link on its own line with a blink line above/below.

Links to files/webpages
The same method applies to both - if the browser doesn't understand the format it will offer to download the file. Some browsers see that a TBX is XML and load (display) the raw XML. As such I find it useful to compress as a ZIP any TBXs I'm sharing via the forum.

A link takes the form:

  {url}http://example.com/mytbx.zip{url};

or

  {url=http://example.com/mytbx.zip}see my TBX{url}

The first example above shows the actual URL and makes it a clickable link. The second example makes the text between the tags the link anchor text and uses the supplied URL as the target.

You can also insert the {url}{/url} tag pair around any selected draft test by using the 'Insert Hypertext' button, top left button above the edit box. This link mark-up creates no exrtra space or line breaks so can be used inline in general text.

Dont forget to use [ and not { backets in actual use!

Footnote: if you've 'finished' examples/demos, as opposed to files illustrating examples, you can send them to Eastgate for possible submission on the 'File Exchange' section of their website (though the latter's lost steam of late - I guess through lack of submissions).
Back to top
 
« Last Edit: Oct 4th, 2013, 4:08am by Mark Anderson »  

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
SteveS
Full Member
*
Offline



Posts: 15

Re: Experimenting with Inheritance
Reply #5 - Oct 4th, 2013, 4:33pm
 
Thanks Mark, let me give this a try.

The TBX file is here
http://sentosatech.com/TBXPub/Tinderbox%20Inheritane%20Lab%20(Oct%203%202013)a.t...

... and a screen shot is below (sorry for the big image).  

Have a look at the code in the gray "cd<-InhRootNote" note (which is loaded as the rule for the black "<-InhRootNote".  The "dbg" window is the output.

My goal is that "<-InhRootNote" find all inbound links of type "InhUsesPrototype", and then assign the link originator note a prototype of itself.  "<-InhRootNote" seems to be finding the inbound links OK, and the prototype assignment does not seem to be working.  

Any advice would be greatly appreciated.
Steve

Back to top
 
« Last Edit: Oct 5th, 2013, 12:56pm by SteveS »  
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Experimenting with Inheritance
Reply #6 - Oct 5th, 2013, 12:38pm
 
Thanks for those references. I won't get a chance to delve deeper for a bit, but I'd make one note. Starting names with "less than minus" (<-) or "less than or equal to" (<=) is perfectly allowable. But, going back a ways, TB used to not require quoted strings and would evaluate expressions passed to it.  Thus if any of your code passes a name like "<-InhRootNote" and evaluates it, strange and unexpected things might [sic] occur. For that reason I'd avoid starting note names with characters that also double in ASCII as mathematical or logical operators. It could certainly already be a cause for silent failures in your existing code.

The above isn't an issue of right/wrong practice, but simply of precaution against the unexpected.

Also, I'm not sure about your 'this.$Name = ' usage comes from. My guess is TB is parsing that code as trying to say '$Name =', perhaps. TB Action code is not a complete language/environment. Dot-chaining is used for action codes but not as generic concatenator.

Where is the sample data you're using in your TBX? I ask only so we can test the same data.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Experimenting with Inheritance
Reply #7 - Oct 5th, 2013, 5:53pm
 
Mark Anderson catches a syntax error that I missed.

    Code:
 this.$Name = "...." 

  <----- JAVASCRIPT

isn't valid in Tinderbox.  Instead, we write

    Code:
$Name(this) 



or simply

    Code:
 $Name 

Back to top
 
 
WWW   IP Logged
J Fallows
Full Member
*
Offline



Posts: 418

Re: Experimenting with Inheritance
Reply #8 - Oct 5th, 2013, 7:30pm
 
This is a reply not on the merits of the coding, which are beyond me, but on the map-view display you offer.

How, please, do you get notes to display their $Text contents so nicely in the Map view? I am thinking for instance of the notes called "General Concepts" and "Conventions." I am sure there is a very obvious answer to this, but it is not one I have applied on my own before. And as I look through some of the prototypes and the $DisplayExpression and Map-attribute settings in your sample file, I don't see how you arranged this. Advice gratefully received.
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Experimenting with Inheritance
Reply #9 - Oct 6th, 2013, 3:16am
 
@J_Fallows: The map items to which you refer are likely normal notes displaying body text, and with a few non-default changes. I was able to recreate the look of the 'General Concepts' note in the screen grab, via these changes to a default note (with a suitable title and $Text). Thus, we alter Appearance attributes:
  • $Border -> 4
  • $BorderBevel -> plain
  • $BorderColor -> black
  • $Color -> #d0cad9
Then, Map attributes:
  • $NameBold -> true
  • $Height/Width as needed to display body text as required.
There are plenty of other visualisation settings, such as $MapBodyTextColor, $NameFont, etc.

Once you have a number of attribute settings that match a look you desire, you can then easily 'deploy' them via Stamps, prototypes, etc.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
J Fallows
Full Member
*
Offline



Posts: 418

Re: Experimenting with Inheritance
Reply #10 - Oct 6th, 2013, 1:30pm
 
As always, thank you Mark.
Back to top
 
 
  IP Logged
Paul Walters
Full Member
*
Offline



Posts: 267

Re: Experimenting with Inheritance
Reply #11 - Oct 7th, 2013, 7:11am
 
@SteveS -- the TBX document found at the link in your most recent note does not appear to be the one portrayed in the screen shots.
Back to top
 
 
  IP Logged
SteveS
Full Member
*
Offline



Posts: 15

Re: Experimenting with Inheritance
Reply #12 - Oct 14th, 2013, 7:27pm
 
Mark & All,

Thanks for the notes RE "this" syntax, and avoiding using mathematical operators as first character of a note name.  I made a few changes along those lines, and would like to share the results.

Here is a quick code snippet (debug statements removed).  The intent is for a note to find inbound links of type "InhUsesPrototype", store a list of the originating notes in the InhMySubClasses attribute, and then set set the prototype of the originating notes to be itself:

   $InhMySubClasses=links.inbound."InhUsesPrototype".$Path;
   $InhMySubClasses.each(curSub)
   {
     $Prototype(curSub)=$Name(this);
   };

Here is and image with the full code in the gray box (with debug statements) as well as the debug window in white:



As you can see, prototype of the notes originating link type "InhUsesPrototype" are not being changed.

Now, as an experiment, I added the line of code in red, which explicitly sets the prototype of one of the "InhUsesPrototype" originators to the type of self.

   $InhMySubClasses=links.inbound."InhUsesPrototype".$Path;
   $InhMySubClasses.each(curSub)
   {
     $Prototype(curSub)=$Name(this);
   };
   $Prototype("subCls A")=$Name(this);

Here is an image with the full code in the gray box (with debug statements) as well as the debug window in white, which shows that this last line did take effect.



So, it seems like the next step is figuring out why the following takes effect:
       $Prototype("subCls A")=$Name(this);

but, in the context of an each loop, the follow does not
     $Prototype(curSub)=$Name(this);

Here is the associated tinderbox file, in case anybody is interested.
       http://sentosatech.com/TBXPub/Wiring-Prototypes-Oct-14-2013.zip

As always, thanks for your help
Cheers!
Steve


Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Experimenting with Inheritance
Reply #13 - Oct 15th, 2013, 6:10am
 
I think I see the problem. First remember this isn't a scripting system built from a pre-set model, different similar looking methods may work differently. Also, list.each() was originally added IIRC, to let a note iterate a set of list data in the context of the calling note, i.e. the one running the loop. By contrast you want, and I do see why, to simply use the host note as a place to work on other notes. Thus the loop code (note: it doesn't work) that you want is:

$InhMySubClasses=links.inbound."InhUsesPrototype".$Path;
$InhMySubClasses.each(curSub){
     $Prototype(curSub) = $Name;
};


It fails though. My best guess is because left-side offset calls (i.e. $Prototype(curSub)) aren't being evaluated and/or cause that line of code to be ignored. If left-side evaluations can be fixed, then the above is the solution. If not, you may need to take a different approach. Perhaps an agent finding all the links of the relevant type then setting each matching item to set its $Prototype to the name of the note linked to (by the relevant link type). I fear I've no time to test the latter idea now.
Back to top
 
« Last Edit: Oct 15th, 2013, 6:11am by Mark Anderson »  

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Experimenting with Inheritance
Reply #14 - Oct 15th, 2013, 2:07pm
 
Here's a workaround solution using an agent. I've designed it for agent re-use via prototypes. An upside of agents is (a) you can turn them off - or to lower priority - when not needed and (b) you can store them away off your map avoiding visual clutter.

First add two user String-type attributes: $ProtoName, $ProtoLinkName. (Feel free to alter these names to ones you like better, as long as all instances are updated).

Now make a new agent. Make it a prototype. Set the two new attributes as key attributes. Now, make these settings:

Query:   linkedTo($ProtoName(agent),$ProtoLinkName(agent)
Action:   $Prototype = $ProtoName(agent);

Done, now make a new agent and set it to use the above prototype. Set the new agent's $ProtoName to "p_InhRootNote" and $PrototLinkName to "InhUsesPrototype". Make other agents as required for other link relationships.

Assumptions:
  • A note may link to a prototype like "p_InhRootNote" for reasons other than dependency. Thus the link type filter on the query.
  • A note only ever links to one prototype via the specified name/link-type combo.
Another upside of this is we're not cluttering all the not rules for constantly scanning rules that in most cases only need to run once.

One minor nitpick on your file. The map displayed is set to make all new notes a prototype when it's not clearly the case that they should be. IOW, you're creating (unseen, by an OnAdd, prototypes you don't want/need).
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Pages: 1
Send Topic Print