Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #30723
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!eweka.nl!lightspeed.eweka.nl!193.141.40.65.MISMATCH!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!feed.news.schlund.de!schlund.de!news.online.de!not-for-mail |
|---|---|
| From | Bernd Paysan <bernd.paysan@gmx.de> |
| Newsgroups | comp.lang.forth |
| Subject | Re: A slightly longer mini-oof2.fs example. |
| Date | Mon, 26 May 2014 00:47:49 +0200 |
| Organization | 1&1 Internet AG |
| Lines | 154 |
| Message-ID | <lltrum$vf2$1@online.de> (permalink) |
| References | <70a9649b-29ee-43f8-a1f8-af2581dafab8@googlegroups.com> <2014May23.141134@mips.complang.tuwien.ac.at> <zLCdnQlJo9IW9eLOnZ2dnUVZ8tCdnZ2d@supernews.com> <llo2ag$i0l$1@online.de> <2014May24.173516@mips.complang.tuwien.ac.at> <llqsu1$ivh$1@online.de> <2014May25.170321@mips.complang.tuwien.ac.at> |
| NNTP-Posting-Host | p4fc55e8b.dip0.t-ipconnect.de |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Trace | online.de 1401058071 32226 79.197.94.139 (25 May 2014 22:47:51 GMT) |
| X-Complaints-To | abuse@einsundeins.com |
| NNTP-Posting-Date | Sun, 25 May 2014 22:47:51 +0000 (UTC) |
| User-Agent | KNode/4.11.5 |
| Xref | csiph.com comp.lang.forth:30723 |
Show key headers only | View raw
Anton Ertl wrote: > Bernd Paysan <bernd.paysan@gmx.de> writes: >>And when you refactor your code, you can concentrate on the essence of >>refactoring, instead of going through your entire code base. > > Given that, as you write, one should only access an instance variable > in its class (and maybe descendent classes), you don't need to go > through the entire code base. That could be a variable in a base class... used in a lot of places. > Sure, if I don't control the code base > that would need to be changed, keeping the interface the same is the > way to go, but if I do, it may be better to actually change it > (although keeping the interface the same may be good for the > intermediate step). Anyway, you also have both options with > objects.fs. Changing an interface in a sufficiently large code base is always a problem, even if you control the codebase. > E.g. let's say >>foo was first an instance variable, holding a cell. After a while, you >>discover that your object really has two states in which it has two >>different foos, and you now define >> >>: foo ( -- addr ) mystate @ IF foo1 ELSE foo2 THEN ; > > This works in objects.fs, too; THIS is global, and is not changed when > you call a colon definition. One may discuss whether this is a > feature, or just an artifact of the implementation; it was not > intended as a feature, but maybe you can convince me that it is one > (better, convince Andrew Haley!-). I think it's just an artefact of the implementation. >>After a while, you discover furthermore that, well, this distinction is >>only necessary for 20% of your classes, and the other do well with having >>just one foo, so you declare foo as a method, and define that with >> >>' foo1 my-baseclass to foo >> >>or, for those who needs two states >> >>:noname ( -- addr ) mystate @ IF foo1 ELSE foo2 THEN ; my-sublass to >>:foo > > In objects.fs I can define > > selector foo-s > : foo this foo-s ; \ used global this > > \ in my-baseclass > m: foo1 ;m overrides foo-s \ could be made more efficient > > \ in some classes > m: ( -- addr ) mystate @ IF foo1 ELSE foo2 THEN ;m overrides foo-s Yes, the global this makes this possible... >>The invocation never changed, and therefore, you never had to dig through >>your entire code base for all invokations of foo. >> >>This sort of consistency makes maintaining code easy. The thing you need >>to maintain consistently is the signature of the word (the way it is >>invoked), not the way it is implemented. > > As I demonstrated, explicit setting of the current object is not > needed for this. You have demonstrated that you can produce a workaround by accidentially having a global current object, and that you can therefore create a wrapper that supplies the selector with an object on the stack. In Mini-OOF2, this is by design. >>> Which may be a good idea, it's more consistent with the access to the >>> instance variables of other objects. >> >>Well, you shouldn't access instance variables of other objects... > > That's what I thought when I started working with Java. now I am no > longer convinced of that, at least for Java. I'm not convinced of this rule, either, but at least it should be easier to access the own instance variables (that's why having a current object is so useful). > Anyway, back to our discussion: Yes, that was the idea behind the way > instance variables and methods are handled in objects.fs: > > Only instance variables of the current object should only be accessed, > so instance variables are only visible in their class, and they always > are accessed through the current objects. > > In contrast, methods should be callable everywhere, for arbitrary > objects, so the method selector has a global name, and you pass the > object on which it dispatches explicitly. > > As demonstrated, you can emulate the instance variable interface with > colon definitions or methods, so that's no reason to change that. Mini-OOF2 doesn't handle limited visibility (yet), it will quite likely become another thing that you can have when you want it, but not as essential feature. > Now you just need to document it so we can all see the light:-). Yes. > The other thing is whether you want to keep it dependent on Gforth > features. One of the ideas is that there are a few essential things a system needs to provide to implement OOP with good performance, and these things aren't portable yet. >>If you don't like foo >o bar o> in mini-oof2, add a dot-parser >>recognizer which will transform >> >>foo.bar into foo >o bar o> >>foo->bar into foo @ >o bar o> >> >>with any number of . and -> in the string (just replace all "." with " >o >>" and all "->" with " @ >o " and count the number of occurances, and then >>add that number of " o>" to the end - and reevaluate). > > I have been thinking about something like that, too: > > Have .BAR take the current object from the TOS, and BAR keep it as it > is (although "." is taken as a prefix in Forth, so we should probably > use something else, maybe ":" or "~"; I'll leave that discussion to > someone else, my names are generally disliked:-). This could be > implemented in standard Forth by defining two words, or in > sufficiently capable systems with a dot-parser. So we would have > > foo .bar > foo @ .bar > > for your examples. Yes, that would work, too, making the parser even easier (does it start with a dot? Is the rest found in the dictionary - use word-recognizer for that)? Interpret and compile it wrapped in >o o>. . is indeed "taken", so there can be conflicts. The original suggestion makes the dot parser way more complicated, but then, foo.bar doesn't conflict. -- Bernd Paysan "If you want it done right, you have to do it yourself" http://bernd-paysan.de/
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
A slightly longer mini-oof2.fs example. Julian Fondren <ayrnieu@gmail.com> - 2014-05-22 19:29 -0700
Re: A slightly longer mini-oof2.fs example. albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-05-23 11:22 +0000
Re: A slightly longer mini-oof2.fs example. Julian Fondren <ayrnieu@gmail.com> - 2014-05-23 09:38 -0700
Re: A slightly longer mini-oof2.fs example. anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-05-23 12:11 +0000
Re: A slightly longer mini-oof2.fs example. Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-05-23 10:26 -0500
Re: A slightly longer mini-oof2.fs example. Bernd Paysan <bernd.paysan@gmx.de> - 2014-05-23 19:59 +0200
Re: A slightly longer mini-oof2.fs example. Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-05-24 04:23 -0500
Re: A slightly longer mini-oof2.fs example. Hans Bezemer <the.beez.speaks@gmail.com> - 2014-05-24 15:47 +0200
Re: A slightly longer mini-oof2.fs example. Julian Fondren <ayrnieu@gmail.com> - 2014-05-26 12:46 -0700
Re: A slightly longer mini-oof2.fs example. anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-05-24 15:35 +0000
Re: A slightly longer mini-oof2.fs example. Alexander Skobelev <al.skobelev@gmail.com> - 2014-05-24 20:45 +0400
Re: A slightly longer mini-oof2.fs example. Bernd Paysan <bernd.paysan@gmx.de> - 2014-05-24 21:46 +0200
Re: A slightly longer mini-oof2.fs example. anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-05-25 15:03 +0000
Re: A slightly longer mini-oof2.fs example. Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-05-25 15:16 -0500
Re: A slightly longer mini-oof2.fs example. Bernd Paysan <bernd.paysan@gmx.de> - 2014-05-26 00:47 +0200
Re: A slightly longer mini-oof2.fs example. Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-05-25 18:55 -0500
Re: A slightly longer mini-oof2.fs example. albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-05-26 11:44 +0000
Re: A slightly longer mini-oof2.fs example. Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-05-27 05:25 -0500
Re: A slightly longer mini-oof2.fs example. albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-05-27 11:56 +0000
Re: A slightly longer mini-oof2.fs example. Julian Fondren <ayrnieu@gmail.com> - 2014-05-26 12:18 -0700
Re: A slightly longer mini-oof2.fs example. Paul Rubin <no.email@nospam.invalid> - 2014-05-26 12:46 -0700
Re: A slightly longer mini-oof2.fs example. Julian Fondren <ayrnieu@gmail.com> - 2014-05-26 13:43 -0700
Re: A slightly longer mini-oof2.fs example. Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-05-27 05:28 -0500
Re: A slightly longer mini-oof2.fs example. Julian Fondren <ayrnieu@gmail.com> - 2014-05-23 09:39 -0700
Re: A slightly longer mini-oof2.fs example. mhx@iae.nl - 2014-05-23 10:29 -0700
Re: A slightly longer mini-oof2.fs example. anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-05-23 17:16 +0000
Re: A slightly longer mini-oof2.fs example. andraszsoter@gmail.com - 2014-05-26 10:23 -0700
Re: A slightly longer mini-oof2.fs example. Mark Wills <markwills1970@gmail.com> - 2014-05-27 02:09 -0700
Re: A slightly longer mini-oof2.fs example. Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-05-27 06:07 -0500
Re: A slightly longer mini-oof2.fs example. andraszsoter@gmail.com - 2014-05-28 10:17 -0700
Re: A slightly longer mini-oof2.fs example. Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-05-27 05:39 -0500
Re: A slightly longer mini-oof2.fs example. Mark Wills <markwills1970@gmail.com> - 2014-05-27 04:02 -0700
Re: A slightly longer mini-oof2.fs example. Mark Wills <markwills1970@gmail.com> - 2014-05-27 04:04 -0700
Re: A slightly longer mini-oof2.fs example. Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-05-27 06:19 -0500
csiph-web