Google Skupine ne podpirajo več novih objav ali naročnin v storitvi Usenet. Zgodovinsko vsebino si je še vedno mogoče ogledati.
Dismiss

A nice and simple implementation of locals in ANS Forth

117 ogledov
Preskoči na prvo neprebrano sporočilo

lehs

neprebran,
27. jun. 2016, 05:32:5727. 6. 16
do
I would like such an implementation to include in all ANS Forth code where needed. In my BigInteger I used extra stacks to avoid locals to get portability, which seemed to work OK, but in BigZ

https://github.com/Lehs/BigZ/blob/master/README.md

I've just had to use locals to decrease the lateral thinking and stack juggling. I saw that Hugh Aguilar had something like that in his Novice package, but it seems very integrated in the rest of the package. I just want the locals to be included in the beginning of my code.

hughag...@gmail.com

neprebran,
27. jun. 2016, 06:42:4827. 6. 16
do
Well, ANS-Forth does have locals --- perhaps you mean the { word that has the parameters in the correct order?

I didn't invent the { word --- this called the "John Hopkins Locals Format" --- it has been in use since the early 1990s, prior to ANS-Forth, so there are many implementations available.

The only implementation that I know to be bad, is Anton Ertl's {: that he wrote for Forth-200x --- he doesn't initialize the locals to the right of the | to zero, but instead he initializes them to whatever values happened to be in memory already (if the programmer forgets to explicitly initialize them, then they may or may not work as expected from one run of the program to the next) --- also, the name has always been { for at least a quarter of a century, but Anton changed it to {: because SwiftForth uses { for multi-line comments.

minf...@arcor.de

neprebran,
27. jun. 2016, 06:46:5027. 6. 16
do
Why do you need portability at all?


lehs

neprebran,
27. jun. 2016, 06:56:2527. 6. 16
do
Is it possible to extract the nice locals from the novice pack in a few rows? I tried to figure out how it worked in GForth but couldn't.

lehs

neprebran,
27. jun. 2016, 07:06:2627. 6. 16
do
Well, I've defined a system for computational mathematics with a lot of mathematical functions, nestled set handeling and big integers and maybe others would like to integrate it or parts of it into their own systems. My BigInt worked alright for a lot of processors with ANS Forth, but BigZ just works for SP-Forth and GForth.

As written: why invent the wheel over and over again? It's better to adapt and improve existing code.

Mark Wills

neprebran,
27. jun. 2016, 10:32:5427. 6. 16
do
It's not ANS, it's my own flavour of locals (which I prefer). It's all written
in Forth though, so it might give you some ideas:

http://turboforth.net/resources/locals.html

Mark Wills

neprebran,
27. jun. 2016, 10:37:0427. 6. 16
do
On Monday, 27 June 2016 10:32:57 UTC+1, lehs wrote:
Sorry. My previous post linked to the latest version of my library which
contains some machine code.

Try this one:

http://turboforth.net/resources/old_locals.html

It's V1.0 and is 100% Forth.

lehs

neprebran,
27. jun. 2016, 13:43:3527. 6. 16
do
Thanks! I've looked at it and it looks good, but I'm to inexperienced looking and working under the hood.

In my ignorance I hadn't noticed the word locals| which will due I think. My idea is to reform my code from a lot of extra stacks and I'll have to do a lot of work anyway. I can live with the awkwardness of locals| that isn't too awkward from the Forth perspective anyway.

hughag...@gmail.com

neprebran,
27. jun. 2016, 15:47:0627. 6. 16
do
On Monday, June 27, 2016 at 3:56:25 AM UTC-7, lehs wrote:
> Is it possible to extract the nice locals from the novice pack in a few rows? I tried to figure out how it worked in GForth but couldn't.

It is not complicated. I just construct a string containing LOCALS| ... | and then I EVALUATE it. I have to push the local-name strings to the return-stack and then pop them off so they get put in LOCALS| in a backwards order to how they appeared in { ... } .

Anton used (LOCAL) instead of LOCALS| --- I wasn't able to do this because at the time I was using SwiftForth-v2 that has a bug in it causing (LOCAL) to crash the system when it is used. If you don't care about supporting SwiftForth-v2 however, you could use (LOCAL) and avoid the need to concatenate strings. Concatenating strings was easy for me because I already had <CSTR ... CSTR> available, but if you don't have any way to construct strings then you may want to avoid using LOCALS| and use (LOCAL) instead.

Why do you not want to use the novice-package? You INCLUDE this, then you get { as well as quite a lot of other good stuff too --- the { was actually a trivial bit of low-level code that I wrote many years ago --- I have a lot more now.

lehs

neprebran,
27. jun. 2016, 18:21:1527. 6. 16
do
If I was starting from scratch and if I liked everything in your Novice pack I might have used it, but as it is now some of your code doesn't harmonize with my code. Besides I have started to like locals| which I use parallel with stack diagrams.
0 novih sporočil