• >ALLOC

    From none) (albert@21:1/5 to All on Mon Nov 14 13:10:39 2022
    A useful word that I use more and more is an addition
    to the ALLOCATE wordsset.
    Often words are geared towards creating a data structure at
    HERE. They can be in the way. >ALLOC moves it to allocated
    space.

    \ Make a freshly created object at `HERE permanent.
    : >ALLOC DUP >R HERE OVER - DUP ALLOCATE THROW
    DUP >R SWAP MOVE R> R> DP ! ;
    \ DP ! can be replace by a negative ALLOT.

    Example (counted strings)
    CREATE animals
    HERE 3 C, &a C, &a C, &p C, >ALLOC ,
    HERE 4 C, &g C, &e C, &i C, &t C, >ALLOC ,

    animals 1 CELLS + COUNT TYPE
    goat


    Groetjes Albert
    --
    "in our communism country Viet Nam, people are forced to be
    alive and in the western country like US, people are free to
    die from Covid 19 lol" duc ha
    albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marcel Hendrix@21:1/5 to none albert on Mon Nov 14 10:11:05 2022
    On Monday, November 14, 2022 at 1:10:43 PM UTC+1, none albert wrote:
    [..]
    HERE 4 C, &g C, &e C, &i C, &t C, >ALLOC ,

    animals 1 CELLS + COUNT TYPE
    goat

    It has a build Dutch->English translator unit?

    Groetjes Albert

    Why would you ALLOT first and then laboriously ALLOCATE and move?
    Can't you just swap DP with some allocated memory and then swap DP
    back? Or use A" instead of S" ?

    -marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anton Ertl@21:1/5 to Marcel Hendrix on Mon Nov 14 18:42:53 2022
    Marcel Hendrix <mhx@iae.nl> writes:
    Why would you ALLOT first and then laboriously ALLOCATE and move?

    I guess it's for the example's sake.

    Gforth has

    : save-mem ( addr1 u -- addr2 u ) \ gforth
    \g copy a memory block into a newly allocated region in the heap

    with 9 uses inside Gforth (and I use it regularly elsewhere). There
    is also a less frequently used

    : save-mem-dict ( addr1 u -- addr2 u )

    that ALLOTs the memory instead of ALLOCATEing it.

    One big advantage of SAVE-MEM over >ALLOC is that it has a stack
    diagram.

    - 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: https://forth-standard.org/
    EuroForth 2022: https://euro.theforth.net

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From none) (albert@21:1/5 to Anton Ertl on Tue Nov 15 09:40:48 2022
    In article <2022Nov14.194253@mips.complang.tuwien.ac.at>,
    Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
    Marcel Hendrix <mhx@iae.nl> writes:
    Why would you ALLOT first and then laboriously ALLOCATE and move?

    I guess it's for the example's sake.

    Gforth has

    : save-mem ( addr1 u -- addr2 u ) \ gforth
    \g copy a memory block into a newly allocated region in the heap

    with 9 uses inside Gforth (and I use it regularly elsewhere). There
    is also a less frequently used

    : save-mem-dict ( addr1 u -- addr2 u )

    That is not an alternative!
    ALLOC allows to build memory structures the usual way
    in the dictionary.
    You probably have a hard time to recover the space "addr1 u".


    that ALLOTs the memory instead of ALLOCATEing it.

    One big advantage of SAVE-MEM over >ALLOC is that it has a stack
    diagram.

    It has actual documentation, that comprises a stack diagram.
    The convention has been explained numerous times.
    I really need to write an uglifyer that translates
    actual documentation to a stack diagram.


    - anton
    --
    "in our communism country Viet Nam, people are forced to be
    alive and in the western country like US, people are free to
    die from Covid 19 lol" duc ha
    albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dxforth@21:1/5 to albert on Tue Nov 15 21:14:56 2022
    On 15/11/2022 7:40 pm, albert wrote:
    In article <2022Nov14.194253@mips.complang.tuwien.ac.at>,
    Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
    Marcel Hendrix <mhx@iae.nl> writes:
    Why would you ALLOT first and then laboriously ALLOCATE and move?

    I guess it's for the example's sake.

    Gforth has

    : save-mem ( addr1 u -- addr2 u ) \ gforth
    \g copy a memory block into a newly allocated region in the heap

    with 9 uses inside Gforth (and I use it regularly elsewhere). There
    is also a less frequently used

    : save-mem-dict ( addr1 u -- addr2 u )

    That is not an alternative!

    : /$ ( a -- a' ) count + ; \ next string
    : $, ( a -- a' ) dup , /$ ;
    : $,s ( a -- ) begin dup c@ while $, repeat drop ;

    here ( a)
    ," aap" ," geit"
    0 c,

    create animals ( a) $,s

    animals 1 cells + @ count type

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From none) (albert@21:1/5 to dxforth@gmail.com on Tue Nov 15 14:33:11 2022
    In article <tkvor0$17fs$1@gioia.aioe.org>, dxforth <dxforth@gmail.com> wrote: >On 15/11/2022 7:40 pm, albert wrote:
    In article <2022Nov14.194253@mips.complang.tuwien.ac.at>,
    Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
    Marcel Hendrix <mhx@iae.nl> writes:
    Why would you ALLOT first and then laboriously ALLOCATE and move?

    I guess it's for the example's sake.

    Gforth has

    : save-mem ( addr1 u -- addr2 u ) \ gforth
    \g copy a memory block into a newly allocated region in the heap

    with 9 uses inside Gforth (and I use it regularly elsewhere). There
    is also a less frequently used

    : save-mem-dict ( addr1 u -- addr2 u )

    That is not an alternative!

    : /$ ( a -- a' ) count + ; \ next string
    : $, ( a -- a' ) dup , /$ ;
    : $,s ( a -- ) begin dup c@ while $, repeat drop ;

    here ( a)
    ," aap" ," geit"
    0 c,

    create animals ( a) $,s

    animals 1 cells + @ count type


    Nice, but.

    Suppose that you have a
    0 0 class point
    M: y M; ,
    M: x M; ,
    endclass

    In my book that also generates a word that builds an anonymous
    point `BUILD-point and a `^point containing a pointer to the
    current point object.

    CREATE points
    HERE 3 4 BUILD-point >ALLOC ,
    HERE 13 14 BUILD-point >ALLOC ,

    points 1 CELLS + @ ^point ! ( make the second point current)
    x ? y ?
    13 14 OK

    See my point now?

    Groetjes Albert
    --
    "in our communism country Viet Nam, people are forced to be
    alive and in the western country like US, people are free to
    die from Covid 19 lol" duc ha
    albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anton Ertl@21:1/5 to albert@cherry. on Tue Nov 15 17:40:12 2022
    albert@cherry.(none) (albert) writes:
    In article <2022Nov14.194253@mips.complang.tuwien.ac.at>,
    Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
    Gforth has

    : save-mem ( addr1 u -- addr2 u ) \ gforth
    \g copy a memory block into a newly allocated region in the heap

    with 9 uses inside Gforth (and I use it regularly elsewhere).
    [...]
    That is not an alternative!

    I would not know from your nebulous description of >ALLOC.

    ALLOC allows to build memory structures the usual way
    in the dictionary.

    "The usual way"?

    You probably have a hard time to recover the space "addr1 u".

    Not in the least. The usual use of SAVE-MEM is when the memory at
    addr1 u could be overwritten or its lifetime ends otherwise.
    Otherwise, just let it stay there, and don't use SAVE-MEM.

    One big advantage of SAVE-MEM over >ALLOC is that it has a stack
    diagram.

    It has actual documentation, that comprises a stack diagram.
    The convention has been explained numerous times.

    I don't see at a quick glance what happens on the stack, so it's not
    useful for me, so I did not learn your way[1]. I also find the
    "documentation" of >ALLOC unclear in other respects. The only thing
    that made it clear to me that it is somewhat different from SAVE-MEM
    was the examples.

    [1] According to <https://en.wikipedia.org/wiki/Convention_(norm)>, "A convention is a set of agreed, stipulated, or generally accepted
    standards, norms, social norms, or criteria"; so your way of
    documenting is not a convention, just like Humpty-Dumpty's use of
    "glory" is not a convention.

    - 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: https://forth-standard.org/
    EuroForth 2022: https://euro.theforth.net

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dxforth@21:1/5 to albert on Thu Nov 17 12:32:54 2022
    On 16/11/2022 12:33 am, albert wrote:
    ...
    Suppose that you have a
    0 0 class point
    M: y M; ,
    M: x M; ,
    endclass

    In my book that also generates a word that builds an anonymous
    point `BUILD-point and a `^point containing a pointer to the
    current point object.

    CREATE points
    HERE 3 4 BUILD-point >ALLOC ,
    HERE 13 14 BUILD-point >ALLOC ,

    points 1 CELLS + @ ^point ! ( make the second point current)
    x ? y ?
    13 14 OK

    See my point now?

    I can't speak for OOP needs. As I don't have (or particularly want) ALLOCATE
    I try to look for alternate strategies e.g. ALLOTing buffers at run-time rather than compile-time - not least because I have more RAM available.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From none) (albert@21:1/5 to dxforth@gmail.com on Thu Nov 17 12:37:41 2022
    In article <tl4306$1bhd$1@gioia.aioe.org>, dxforth <dxforth@gmail.com> wrote: >On 16/11/2022 12:33 am, albert wrote:
    ...
    Suppose that you have a
    0 0 class point
    M: y M; ,
    M: x M; ,
    endclass

    In my book that also generates a word that builds an anonymous
    point `BUILD-point and a `^point containing a pointer to the
    current point object.

    CREATE points
    HERE 3 4 BUILD-point >ALLOC ,
    HERE 13 14 BUILD-point >ALLOC ,

    points 1 CELLS + @ ^point ! ( make the second point current)
    x ? y ?
    13 14 OK

    See my point now?

    I can't speak for OOP needs. As I don't have (or particularly want) ALLOCATE >I try to look for alternate strategies e.g. ALLOTing buffers at run-time rather
    than compile-time - not least because I have more RAM available.

    I don't want to have large buffers allocated in an executable either.
    I use REALLOT.
    Preliminary (for testing) I have
    VALUE BUFFER HERE TO BUFFER 1 , 2 ,
    In the main word (that is executed by the turnkey) it goes
    : main 2,000,000 BUFFER REALLOT .... ;
    expanding the buffer to 2 Mbyte, and of course it can depend
    on in line arguments such as.

    linux>turnkey 1000
    then it would be `` 1 ARG[] EVALUATE DUP * CELLS BUFFER REALLOT ...
    ^ 10000 ^ (but only in this execution instance)

    [Actually I don't use values, I patch the data field of constants.
    That amounts to the same trick.
    dea ("name token") must be the xt of a constant.
    : AT-HERE HERE SWAP >DFA ! ; ( dea -- )
    : REALLOT SWAP AT-HERE ALLOT ; ( amount dea -- )
    Come to think of it, if you use VALUE's, it is nasty to implement,
    because the VALUE has to be changed, and that is only possible
    if the name is parsed. That triggers a rename to AT-HERE: .
    Perfect demonstration of the reason why true Forthers hate VALUE's.]

    Groetjes Albert
    --
    "in our communism country Viet Nam, people are forced to be
    alive and in the western country like US, people are free to
    die from Covid 19 lol" duc ha
    albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From minforth@arcor.de@21:1/5 to none albert on Thu Nov 17 05:47:07 2022
    none albert schrieb am Donnerstag, 17. November 2022 um 12:37:45 UTC+1:
    [Actually I don't use values, I patch the data field of constants.
    That amounts to the same trick.
    dea ("name token") must be the xt of a constant.
    : AT-HERE HERE SWAP >DFA ! ; ( dea -- )
    : REALLOT SWAP AT-HERE ALLOT ; ( amount dea -- )
    Come to think of it, if you use VALUE's, it is nasty to implement,
    because the VALUE has to be changed, and that is only possible
    if the name is parsed. That triggers a rename to AT-HERE: .
    Perfect demonstration of the reason why true Forthers hate VALUE's.]

    Well, what's wrong with parsing TO VALUENAME during compile-time,
    when the system is already parsing anyhow?

    Anyway, compiled it should result to a non-parsing
    <VALUEADDRESS> ! / 2! / F! / Loc!
    and/or what you have.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From none) (albert@21:1/5 to minf...@arcor.de on Thu Nov 17 20:16:52 2022
    In article <a1e958d5-05af-400c-824f-0b4a7458a75bn@googlegroups.com>, minf...@arcor.de <minforth@arcor.de> wrote:
    none albert schrieb am Donnerstag, 17. November 2022 um 12:37:45 UTC+1:
    [Actually I don't use values, I patch the data field of constants.
    That amounts to the same trick.
    dea ("name token") must be the xt of a constant.
    : AT-HERE HERE SWAP >DFA ! ; ( dea -- )
    : REALLOT SWAP AT-HERE ALLOT ; ( amount dea -- )
    Come to think of it, if you use VALUE's, it is nasty to implement,
    because the VALUE has to be changed, and that is only possible
    if the name is parsed. That triggers a rename to AT-HERE: .
    Perfect demonstration of the reason why true Forthers hate VALUE's.]

    Well, what's wrong with parsing TO VALUENAME during compile-time,
    when the system is already parsing anyhow?

    Anyway, compiled it should result to a non-parsing
    <VALUEADDRESS> ! / 2! / F! / Loc!
    and/or what you have.


    Pray, try to implement the above with values.

    Groetjes Albert
    --
    "in our communism country Viet Nam, people are forced to be
    alive and in the western country like US, people are free to
    die from Covid 19 lol" duc ha
    albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From S Jack@21:1/5 to dxforth on Thu Nov 17 14:39:14 2022
    On Wednesday, November 16, 2022 at 7:32:57 PM UTC-6, dxforth wrote:
    I can't speak for OOP needs. As I don't have (or particularly want) ALLOCATE I try to look for alternate strategies e.g. ALLOTing buffers at run-time rather
    than compile-time - not least because I have more RAM available.

    I have ALLOCATE, string stack, local macros and possibly other code that
    I never or seldom use. The problem is my hang-up. If I build foo and it
    uses the string stack that made the operation very easy, I go back and
    re-do foo so that it doesn't require a string stack. I feel a need to not
    have words depended on big-gun resources. Yes, use the resource in a
    script but not in the build of a word (unless it's a throw away word
    in the script).
    --
    me

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)