On Thursday, May 11, 2017 at 4:39:58 PM UTC-4,
hughag...@gmail.com wrote:
> On Wednesday, May 10, 2017 at 7:29:52 PM UTC-7, Elizabeth D. Rather wrote:
> > On 5/9/17 11:07 PM, The Beez wrote:
> > > IMHO the problem with Forth in general has always been that people are TALKING more about Forth than DOING things with Forth. E.g. the number of OO discussions are countless, but who has presented any REAL code in OO?
> >
> > Whenever I teach a course in Forth, I always tell people to check out
> > c.l.f. Most report they just don't have time for that sort of thing.
> > That is certainly true of Leon and our other staff.
>
> You insult all Forth programmers by describing yourself as the "leading expert" of Forth, which implies that all Forth programmers are inferior to you.
>
> When you teach your course in Forth, how many of those students become Forth programmers? None! You turn them off from Forth with your arrogance. You can't name any student of your novice class that has become a Forth programmer --- all of them thought that you were a low-grade moron because you were teaching them to use PAD for holding strings, and all of them went back to programming in C --- all of them spent the rest of their lives telling the other C programmers that they learned Forth from the "leading expert" in Forth, and found Forth to be utterly stupid.
>
> Also, SWOOP is grossly inefficient. This makes Forth appear to be inefficient and useless.
>
> This is my code:
> -------------------------------------------------------------------------
>
> \ ******
> \ ****** This provides the IS-A function for classes.
> \ ******
>
> 98769876 constant class-id \ used to make sure a class is actually a class; must be a distinctive value
>
> 0
> w field .class-parent \ pointer to parent class \ must be first field
> w field .class-size \ size of object
> w field .class-id \ should always be CLASS-ID
> constant class-struct
>
> \ Every object has a W field in front which is a pointer to the class-struct for its class.
>
> : check-class ( class -- )
> .class-id @ class-id <> abort" *** tried to use a class that wasn't actually a class ***" ;
>
> : create-nada ( -- ) \ create a class that has no parent
> create
> nil , \ .class-parent \ there is no parent
> w , \ .class-size \ room for the object's pointer to its class-struct
> class-id , \ .class-id \ this is for error-checking
> does> ( -- )
> true abort" *** it is illegal to make objects of class NADA ***" ;
>
> create-nada nada \ NADA is the only class that has no parent
>
> \ NADA is only available so it can be the parent of classes that have no parent.
> \ It is not really a class that can be used as such.
>
> ' alloc constant heap-new \ give this to the class to get a new object in the heap
> ' concrete-alloc constant dict-new \ give this to the class to get a new object in the dictionary
>
> : class-size ( class -- size )
> .class-size @
> dup 0< abort" *** CLASS-SIZE given a class that never had its .CLASS-SIZE field set by END-CLASS ***" ;
>
> : size' ( -- size ) \ stream: class-name
> ' >body dup check-class
> class-size ;
>
> : object-size ( object -- size )
> @ \ -- class
> .class-size @ ; \ -- size
>
> : class ( -- class offset ) \ stream: class-name parent-name
> create here \ -- class
> ' >body \ -- class parent
> dup check-class \ -- class parent \ make sure PARENT is a class
> dup , \ -- class parent \ .class-parent
> -1 , \ -- class parent \ .class-size \ this will get filled in by END-CLASS
> class-id , \ -- class parent \ .class-id \ this is for error-checking
> class-size \ -- class offset
> does> ( 'alloc -- adr ) \ make a new object ( 'ALLOC is either HEAP-NEW or DICT-NEW)
> >r \ 'alloc -- \ r: -- class
> r@ class-size swap execute \ -- object
> dup r@ class-size erase \ zero out the object
> r> over ! ; \ first field of object is pointer to class
>
> : end-class ( class offset -- )
> over check-class \ make sure CLASS is a class
> swap .class-size ! ;
>
> : <<is-a>> ( object target -- flag )
> over check-class over check-class
> = ;
>
> : <is-a> ( object 'target -- flag )
> swap @ swap >body <<is-a>> ;
>
> : is-a ( object -- flag ) \ stream: target-class-name
> ' <is-a> ;
>
> : [is-a] ( object -- flag ) \ stream: target-class-name
> postpone ['] postpone <is-a> ;
> immediate
>
> : <<is-child-of>> ( ancestor class -- flag )
> over check-class over check-class
> begin
> 2dup = if 2drop true exit then
> @ \ -- ancestor parent \ .class-parent is first field
> dup 0= if 2drop false exit then
> again ;
>
> : <is-child-of> ( object 'ancestor )
> >body swap @ <<is-child-of>> ;
>
> : is-child-of ( object -- flag ) \ stream: ancestor-class-name
> ' <is-child-of> ;
>
> : [is-child-of] ( object -- flag ) \ stream: ancestor-class-name
> postpone ['] postpone <is-child-of> ;
> immediate
>
> \ IS-CHILD-OF tests if the object has ANCESTOR as an ancestor, meaning that it can use ANCESTOR's methods.
>
> : <is-parent-of> ( object 'child )
> >body swap @ swap <<is-child-of>> ;
>
> : is-parent-of ( object -- flag ) \ stream: child-class-name
> ' <is-parent-of> ;
>
> : [is-parent-of] ( object -- flag ) \ stream: child-class-name
> postpone ['] postpone <is-parent-of> ;
> immediate
>
> \ IS-PARENT-OF tests if the object has CHILD as a child, meaning that it can be upgraded to be a CHILD.
>
> : <become> ( object 'class -- new-object )
> >body >r \ -- object \ r: -- class
> r@ class-size realloc \ -- new-object
> r> over ! ; \ -- new-object \ class is object's first field
>
> \ <BECOME> converts an object into a new class.
> \ The new class must either be an ancestor or a child of the object's class.
> \ Use IS-CHILD-OF to find out if the object is a child of the new class (can be downgraded to the parent class).
> \ Use IS-PARENT-OF to find out if the object is a parent of the new-class (can be upgraded to the child class).
>
> : become ( object -- new-object ) \ stream: class-name
> ' <become> ;
>
> : [become] ( object -- new-object ) \ stream: class-name
> postpone ['] postpone <become> ;
> immediate
Hugh please other forth gods stop insulting one another
work together
insults do nothing
look a media vs trump
huge waste
ad money good just creating time wasting drama
huge are you writing any new books?
ever consider do web kinda stuff? even cgi?
writing howot book on such?
database buidler book?