Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 27 |
Nodes: | 6 (0 / 6) |
Uptime: | 38:01:27 |
Calls: | 631 |
Calls today: | 2 |
Files: | 1,187 |
D/L today: |
22 files (29,767K bytes) |
Messages: | 173,681 |
Hi,
I am currently trying to digg deeper into gforth's object.fs.
For that I would like to read some good object oriented forth code
(preferred gforth's object.fs, but open to other good examples).
Any recommendations of f.e. a bigger project, thas has public code?
many thanks - okflo
Hi,
I am currently trying to digg deeper into gforth's object.fs.
For that I would like to read some good object oriented forth code
(preferred gforth's object.fs, but open to other good examples).
Any recommendations of f.e. a bigger project, thas has public code?
Hi,
I am currently trying to digg deeper into gforth's object.fs.
For that I would like to read some good object oriented forth code
(preferred gforth's object.fs, but open to other good examples).
Any recommendations of f.e. a bigger project, thas has public code?
many thanks - okflo
okflo@teletyp.ist writes:
Hi,
I am currently trying to digg deeper into gforth's object.fs.
For that I would like to read some good object oriented forth code
(preferred gforth's object.fs, but open to other good examples).
Any recommendations of f.e. a bigger project, thas has public code?
For objects.fs, I have hear from a few users a long time ago, but have nothing to point to.
Gerry Jackson has adopted and extended mini-oof for his lexgen <https://github.com/gerryjackson/Forth-LexGen> and lexex scanner
generator tools, and for grace, his parser generator.
Bernd Paysan is using mini-oof2 heavily in his net2o (see the bottom--
of <https://fossil.net2o.de/net2o/doc/trunk/wiki/get-it.md> about how
to get source code).
- anton
Hi,
I am currently trying to digg deeper into gforth's object.fs.
For that I would like to read some good object oriented forth code
(preferred gforth's object.fs, but open to other good examples).
Any recommendations of f.e. a bigger project, thas has public code?
many thanks - okflo
I would suggest that you start with mini-oof & xmini_oof to see how they
can be used as these are much simpler than Anton's object.fs which is a
more complete OO system. Once you see how mini_oof can be used in LexGen >and/or Krishna's epr-sim.4th you can move on to object.fs.
Gerry Jackson <do-not-use@swldwa.uk> writes:
I would suggest that you start with mini-oof & xmini_oof to see how they
can be used as these are much simpler than Anton's object.fs which is a
more complete OO system. Once you see how mini_oof can be used in LexGen
and/or Krishna's epr-sim.4th you can move on to object.fs.
But given that so many people found mini-oof good enough to work with
it, or to base their own extension on it, maybe the "more complete"
part of object.fs as actually not needed that often.
One thing that Bernd Paysan found missing in mini-oof is THIS, i.e., a
handle for the current object.
For every class member of <y> which needs "this", define the member as follows,
0 ptr this-a-a \ ptr is synonymous with VALUE in ANS Forth
:noname ( o -- )
-a-a to this
-a-a ...
-a-a this V1 @-a-a \ V1 is a var which belongs to the class for object o
-a-a ...
<y> defines <member-name>
...
Gerry Jackson <do-not-use@swldwa.uk> writes:
I would suggest that you start with mini-oof & xmini_oof to see how they
can be used as these are much simpler than Anton's object.fs which is a
more complete OO system. Once you see how mini_oof can be used in LexGen
and/or Krishna's epr-sim.4th you can move on to object.fs.
But given that so many people found mini-oof good enough to work with
it, or to base their own extension on it, maybe the "more complete"
part of object.fs as actually not needed that often.
One thing that Bernd Paysan found missing in mini-oof is THIS, i.e., a
handle for the current object. He added it into (the Gforth-specific) mini-oof2. Interestingly, mini-oof is based on the internal OO system
of Gray <https://www.complang.tuwien.ac.at/forth/gray.zip>, but that
system has a THIS. So the removal of THIS in mini-oof probably was
one simplification too far.
- anton
On 10/4/25 11:53 AM, Anton Ertl wrote:
One thing that Bernd Paysan found missing in mini-oof is THIS, i.e., a
handle for the current object.
We needed "this" for use in our code at work. In those instances where
it was needed, it was simple enough to implement and use within the >framework of mini-oof.fs in the following manner:
<x> class \ define a class derived from class x
... \ specify vars and members
end-class <y>
For every class member of <y> which needs "this", define the member as >follows,
0 ptr this \ ptr is synonymous with VALUE in ANS Forth
:noname ( o -- )
to this
...
this V1 @ \ V1 is a var which belongs to the class for object o
...
; \ close the noname definition, leave xt on the stack
<y> defines <member-name>
I suppose mini-oof is a good example of the Forth philosophy: a few
lines of code giving the basics of OO yet powerful, easily extendable to
add more features, easy to understand (and abuse if you need to!).
I suppose mini-oof is a good example of the Forth philosophy: a few
lines of code giving the basics of OO yet powerful, easily extendable to
add more features, easy to understand (and abuse if you need to!). And
like Forth itself a careless mistake can easily crash the system.
On 04/10/2025 17:53, Anton Ertl wrote:
Gerry Jackson <do-not-use@swldwa.uk> writes:
I would suggest that you start with mini-oof & xmini_oof to see how they >>> can be used as these are much simpler than Anton's object.fs which is a
more complete OO system. Once you see how mini_oof can be used in LexGen >>> and/or Krishna's epr-sim.4th you can move on to object.fs.
But given that so many people found mini-oof good enough to work with
it, or to base their own extension on it, maybe the "more complete"
part of object.fs as actually not needed that often.
One thing that Bernd Paysan found missing in mini-oof is THIS, i.e., a
handle for the current object.-a He added it into (the Gforth-specific)
mini-oof2.-a Interestingly, mini-oof is based on the internal OO system
of Gray <https://www.complang.tuwien.ac.at/forth/gray.zip>, but that
system has a THIS.-a So the removal of THIS in mini-oof probably was
one simplification too far.
- anton
I agree about THIS, if I'd thought of it I would probably have added it. Also if mini-oof2 had been available at the time I would have used that.
I suppose mini-oof is a good example of the Forth philosophy: a few
lines of code giving the basics of OO yet powerful, easily extendable to
add more features, easy to understand (and abuse if you need to!). And
like Forth itself a careless mistake can easily crash the system.
Krishna Myneni <krishna.myneni@ccreweb.org> writes:
On 10/4/25 11:53 AM, Anton Ertl wrote:
One thing that Bernd Paysan found missing in mini-oof is THIS, i.e., a
handle for the current object.
We needed "this" for use in our code at work. In those instances where
it was needed, it was simple enough to implement and use within the >>framework of mini-oof.fs in the following manner:
<x> class \ define a class derived from class x
... \ specify vars and members
end-class <y>
For every class member of <y> which needs "this", define the member as >>follows,
0 ptr this \ ptr is synonymous with VALUE in ANS Forth
:noname ( o -- )
to this
...
this V1 @ \ V1 is a var which belongs to the class for object o
...
; \ close the noname definition, leave xt on the stack
<y> defines <member-name>
[I inserted the line that you added in <10bsgj8$2srh2$1@dont-email.me>]
This code does not save THIS on entering the word and restore it on
exit. Which plays a role if you call another method with a different
object of the same class (e.g., when your object is a tree node, and
you want to do something for both child nodes). And once you save and >restore THIS, a per-class THIS does not buy you anything.
The saving and restoring of THIS is what M: and ;M do in objects.fs.
So that's the way I prefer to deal with THIS, and it means that I
prefer to pass the object for which a method is to be called on the
data stack.
By contrast, Bernd Paysan prefers to manipulate the current object
explicitly and to implicitly pass the object for which a method should
be called through the current object, as exemplified in mini-oof2. So
you write code as follows:
mini-oof2 objects.fs
invoke O.M, with O in THIS already: M O M
invoke O.M, with O not yet in THIS: O >o M o> O M
define a method implementation: :noname ... ; M: ... ;M
access THIS unneeded THIS
Note that O> is not like R>, but like RDROP.
Concerning implementation, one (or several) global values THIS only
work in single-threaded programs. For multi-threaded programs, you
need to use a UVALUE (i.e., a thread-local value), or use a different >approach. A simple approach that you can use in mini-oof is to define
THIS as a local; your example above becomes:
:noname {: par1 par2 this -- ... :}
...
this v1 @
...
;
<y> defines <method-selector>
Another alternative is to have special support for the current object
in the Forth engine, which is what mini-oof2 is doing for >O and O>;
but that means that the Forth engine also needs to know about method
calls and instance variable accesses (they also work with the current
object and access it internally).
- anton