+size structs... 
Author Message
 +size structs...

Quote:



> 0 basestru+
> +field ->mystru.a char+
> +field ->mystru.b char+
> struct+: mystru+

> 0 otherstru+
> +field ->newstru.u mystru+
> +field ->newstru.v cell+
> struct+: newstru+

> ... and to get the size, it is just a writing style that says
> one can use the two-word-sequence `0 newstru+` for it, e.g. in

> 0 newstru+ buffer: x
> 0 mystru+  buffer: y

> ... with traditional accessing like in


> hmmm, may be this one should be called "struct-p". It still
> has the advantage to *not* use words like "field" or "struct"
> that is known to be different for each system predefining it.

Practice showed one more aspect:

: otherstru[]^ ( index baseaddr -- addr )
        SWAP 0 otherstru+ * +
;

I dislike " 0 otherstru+ * ". It should be " /otherstru * "

Quote:
> Secondly, in quite some programs I saw "->struct.member"
> as the general naming scheme for the offsetword - which does
> obviously look intuitive atleast to C programmers.

1) In C "->" means: fetch, then add offset (pointer -- component).
In Forth [as above], "->" means just
"add offset" (struc -- component), that is, what "." means in C.

2) The -> symbol is long. It looks almost as whitespace
and attracts attention, while the important thing is not ->
but something else. If accessing a structure is not
a remarkable event in itself, it should not
attract so much attention.

The word >R is called >R rather than ->R because -> does
not read well. But it is pronounced as if it was ->R .

 BEGIN DUP my.b WHILE DUP my^c dosomething my.next REPEAT
vs

A bit resembles the DP+! story, IMO.

--
"We are not poets, our concern is clearness", said Editor
and replaced 'and' with 'as well as'.



Sat, 06 Mar 2004 06:41:48 GMT  
 +size structs...

Quote:




> > 0 basestru+
> > +field ->mystru.a char+
> > +field ->mystru.b char+
> > struct+: mystru+

> > 0 otherstru+
> > +field ->newstru.u mystru+
> > +field ->newstru.v cell+
> > struct+: newstru+

> > ... and to get the size, it is just a writing style that says
> > one can use the two-word-sequence `0 newstru+` for it, e.g. in

> > 0 newstru+ buffer: x
> > 0 mystru+  buffer: y

> > ... with traditional accessing like in


> > hmmm, may be this one should be called "struct-p". It still
> > has the advantage to *not* use words like "field" or "struct"
> > that is known to be different for each system predefining it.

> Practice showed one more aspect:

> : otherstru[]^ ( index baseaddr -- addr )
>         SWAP 0 otherstru+ * +
> ;

> I dislike " 0 otherstru+ * ". It should be " /otherstru * "

the plus-operation is quick on all cpus while mul is not.
OTOH, yes, this is a small advantage for the size-based
structs that have just "/otherstru +" and "/otherstru *".

The main trick of +field structs has been that we already
have the struct-words for the basic types like `char+` and
`cell+` and all the others - and for quite a reason all of
these types are doubled with a scaling operation like is
`chars` and `cells`.

One may adopt the hybrid that was almost visible in your
latest posting - use the offsetwords for the basic types
and let compound structs be just sizewords. A struct
member would therefore look like

0 /otherstru +
+field ->newstru.a char+
+field ->newstru.b /oldstru +
constant /newstru

in a way however it does not have that much a benefit
over openfirmware struct style as it could adopt the
basictypes's offsetwords - it's just the other way round:

0 constant /0

/0 /otherstru +
/0 cell+ field ->newstru.a
/oldstru field ->newstru.b
constant /newstru

Quote:

> > Secondly, in quite some programs I saw "->struct.member"
> > as the general naming scheme for the offsetword - which does
> > obviously look intuitive atleast to C programmers.

> 1) In C "->" means: fetch, then add offset (pointer -- component).
> In Forth [as above], "->" means just
> "add offset" (struc -- component), that is, what "." means in C.

ack.

Quote:

> 2) The -> symbol is long. It looks almost as whitespace
> and attracts attention, while the important thing is not ->
> but something else. If accessing a structure is not
> a remarkable event in itself, it should not
> attract so much attention.

may be, but...

Quote:

> The word >R is called >R rather than ->R because -> does
> not read well. But it is pronounced as if it was ->R .

>  BEGIN DUP my.b WHILE DUP my^c dosomething my.next REPEAT
> vs

> A bit resembles the DP+! story, IMO.

quite so. Actually, a simple "." in front of a structmember
offsetword would be too easily overlooked, like in


furthermore the "." words are more used for output of things,
and anyway it should be more obvious to be a binary operation.
The ">" is already taken as "move-over", perhaps ">>" as shift-upto
could be used but it would stand out even more. You could of course
propose to start using "^" ... up front IMHO, like ^my.c to make
it bind closer to the preceding adress, or as the last char to make
it more visible as an operation (but my.c^ looks bad to my eyes).

Anyway, all I can tell you is that I have seen many programs that
use the "->" style - it is almost as traditional as "/" for the
"sizeof" or "#" or "numberof". If I would start to change it, I'd
simply use that "+" tacked to the end of a word containing a dot
in the middle, like in


which would also serve well for the interesting case - nested
structures and structs containing pointers to structs. Those
have to be readable if written in a row...


and with dot-plus style it would become


and your style (disregarding fetch/store words)


and comparing these three, each has its advantages on some
scale, being short or making it intuitivly visible that we
deal with structs and members - your style would have the
least intuition but people could learn about it. It's just
not that far yet, on the contrary people could speak it as
toggle,swap,merge,exchange - a case of being used to, or not.

so much for struct/field styles, even that we still have no
such portable standard yet, and likewise in a word where every
mature system provides a struct/field implementation of its own.
And still I like mpe's one best for a size-based stru-package
that is almost simple and quite powerful with its nested
and union-like declarations.

cheers,
-- guido                            Edel sei der Mensch, hilfreich und gut



Sat, 06 Mar 2004 07:23:03 GMT  
 
 [ 17 post ]  Go to page: [1] [2]

 Relevant Pages 
 

 
Powered by phpBB® Forum Software