Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #49641

Re: A possible alternative to structures

From anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups comp.lang.forth
Subject Re: A possible alternative to structures
Date 2016-07-29 08:34 +0000
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID <2016Jul29.103437@mips.complang.tuwien.ac.at> (permalink)
References <2ccc8718-6c3f-4e9c-8f7f-b256c36ab68a@googlegroups.com> <2016Jul29.064809@mips.complang.tuwien.ac.at> <30144d4b-6ce2-461b-b009-33bbf7d787dc@googlegroups.com>

Show all headers | View raw


humptydumpty <ouatubi@gmail.com> writes:
>On Friday, July 29, 2016 at 8:10:10 AM UTC+3, Anton Ertl wrote:
>> So if you only want cell-sized fields, as in the
>> example above, here's an implementation of the only word of
>> X:structures that is needed for that, in stack-effect-less one-liner
>> style, as above:
>> 
>> : field: >r : r@ ]] literal + ; [[ r> cell+ ;
...
>Yes! Optimized structures do that.

Nothing particularly optimized about this, just another way to
implement FIELD:.

>But look at the simplicity of second version (simpler version,
>I'll copy here for the easy of read):
>
>\ templates.fs
>' CONSTANT alias CT  \ for brevity
>
>CREATE PIX
>    here 1 ,
>    here 2 ,
>    here 50  c,
>    here 100 c,
>    here 150 c,
>align HERE CT END-PIX
>CT B  CT G CT R CT Y CT X
>
>: PIXELS  [ END-PIX PIX - ] literal * ;
>: PIXEL   PIX - ;
>
>
>: .pixel  ( apix -- )
>  PIXEL dup X + ? dup Y + ? dup R + c@ . dup G + c@ . B + c@ .
>;
>PIX .pixel

So you have eliminated the one-liner above, and pay for that by having
to define a template and a word PIX, having to define the field names
in reverse order, having to define a word PIXEL, and using it on every
access to fields (e.g., in .PIXEL), and additionally having to use +
explicitly on every field access.  Quite a lot more usage complexity
that you pay for the small decrease in implementation simplicity.

>No need to define structure, fields that operates differently depending
>of 'STATE' or fancy align.

No structure is defined in any of the examples I gave in this thread,
nor STATE-smart fields, nor fancy alignment.

> Just bare necessity.  

Actually the classic bare-necessity way to do such things is to write
nothing, "2+", "4 +", "5 +", "6 +" for the fields of this example.
While the implementation of this way is simple and follows Chuck
Moore's principle of shifting computation to the programmer, it has
significant disadvantages, and that's why many of us use field words
these days.

>Template cookbook:
>1. Create a testing-template
>2. For each field push current field address then 'comma' the value.
>   If needed, do 'align'
>3. Annotate the end-of-template ( make it 'constant')
>4. Annotate each field from addresses pushed on stack
>5. Make a definition <template-name> which take an address
>   and return a delta-address form testing-template address
>6. Optionally, make a definition to multiply input by size-of-template,
>   for arrays.

X:structures cookbook:
1. 0
2. For each field, use the appropriate field-defining word; if needed,
   do ALIGNED.
3. define a constant for the size of the structure.

Looks quite a bit simpler to me.

>Amazing how my(our) previous knowledge (of structures in this case)
>acts like a delusion and get into my(our) ways to do simple, straightforward thing (templates).

Probably because it is more complex to define and use.

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: http://www.forth200x.org/forth200x.html
   EuroForth 2016: http://www.euroforth.org/ef16/

Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

A possible alternative to structures humptydumpty <ouatubi@gmail.com> - 2016-07-28 10:46 -0700
  Re: A possible alternative to structures humptydumpty <ouatubi@gmail.com> - 2016-07-28 13:00 -0700
  Re: A possible alternative to structures anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-07-29 04:48 +0000
    Re: A possible alternative to structures humptydumpty <ouatubi@gmail.com> - 2016-07-28 23:45 -0700
      Re: A possible alternative to structures anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-07-29 08:34 +0000
        Re: A possible alternative to structures humptydumpty <ouatubi@gmail.com> - 2016-07-29 02:56 -0700
          Re: A possible alternative to structures anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-07-29 10:06 +0000
            Re: A possible alternative to structures hughaguilar96@gmail.com - 2016-07-31 19:26 -0700
          Re: A possible alternative to structures albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-07-29 13:27 +0200
            Re: A possible alternative to structures humptydumpty <ouatubi@gmail.com> - 2016-07-29 18:31 -0700
        Re: A possible alternative to structures "WJ" <w_a_x_man@yahoo.com> - 2016-07-29 16:00 +0000
        Re: A possible alternative to structures JennyB <jennybrien@googlemail.com> - 2016-07-29 14:37 -0700
        Re: A possible alternative to structures hughaguilar96@gmail.com - 2016-07-31 19:36 -0700
          Re: A possible alternative to structures foxaudioresearch@gmail.com - 2016-08-01 05:51 -0700
            Re: A possible alternative to structures hughaguilar96@gmail.com - 2016-08-02 13:58 -0700
      Re: A possible alternative to structures Julian Fondren <julian.fondren@gmail.com> - 2016-07-29 09:39 -0700
        Re: A possible alternative to structures humptydumpty <ouatubi@gmail.com> - 2016-07-29 11:02 -0700
          Re: A possible alternative to structures Julian Fondren <julian.fondren@gmail.com> - 2016-07-29 20:02 -0700
            Re: A possible alternative to structures humptydumpty <ouatubi@gmail.com> - 2016-07-30 04:32 -0700
              Re: A possible alternative to structures Julian Fondren <julian.fondren@gmail.com> - 2016-07-30 05:55 -0700
                Re: A possible alternative to structures humptydumpty <ouatubi@gmail.com> - 2016-07-30 06:52 -0700
                Re: A possible alternative to structures humptydumpty <ouatubi@gmail.com> - 2016-07-30 07:15 -0700
  Re: A possible alternative to structures humptydumpty <ouatubi@gmail.com> - 2016-07-29 18:13 -0700
  Re: A possible alternative to structures humptydumpty <ouatubi@gmail.com> - 2016-08-01 09:44 -0700
    Re: A possible alternative to structures hughaguilar96@gmail.com - 2016-08-01 10:04 -0700
      Re: A possible alternative to structures humptydumpty <ouatubi@gmail.com> - 2016-08-02 12:09 -0700
        Re: A possible alternative to structures hughaguilar96@gmail.com - 2016-08-02 14:11 -0700
    Re: A possible alternative to structures Doug Hoffman <glidedog@gmail.com> - 2016-08-13 07:42 -0400

csiph-web