Hi Felix -- I created a simple public thread just to share this q+a in
case others had similar questions.
Have you thought about adding an 'include' function to uf.f? I have seen
some forth functions add it and was wondering on your thoughts (like I
said, I'm still relatively new to forth)
Alex
> Hi Felix -- I created a simple public thread just to share this q+a in > case others had similar questions.> > Have you thought about adding an 'include' function to uf.f? I have seen > some forth functions add it and was wondering on your thoughts (like I > said, I'm still relatively new to forth)
Yes, `include` is dearly missing, but a bit complicated due to
the way input-processing is currently done. We can only read whole
files in uxn, not piecewise, so we'd need to load the included file into
some memory and parse it from there. I will think about how to make
this work.
felix
> Hi Felix -- I created a simple public thread just to share this q+a in > case others had similar questions.> > Have you thought about adding an 'include' function to uf.f? I have seen > some forth functions add it and was wondering on your thoughts (like I > said, I'm still relatively new to forth)
Please see the current gitlab version, I have added `include` (and `included`),
perhaps you can give it a try:
https://gitlab.com/b2495/uf
felix
Thanks, I’ll give it a shot!
Alex
> On Sep 28, 2022, at 4:50 AM, felix.winkelmann@bevuta.com wrote:> > >> >> Hi Felix -- I created a simple public thread just to share this q+a in >> case others had similar questions.>> >> Have you thought about adding an 'include' function to uf.f? I have seen >> some forth functions add it and was wondering on your thoughts (like I >> said, I'm still relatively new to forth)> > Please see the current gitlab version, I have added `include` (and `included`),> perhaps you can give it a try:> > https://gitlab.com/b2495/uf> > > felix>
include has been working great so far! I had a few questions about dmath.f
1. It looks like the link to
http://excamera.com/files/j1demo/docforth/nuc.fs.html is broken
2. I'm having trouble getting m*/ to get the result that I want. I want
to multiply a double by a 16-bit number but I'm not getting the result I
expect. The double is 991459 and the 16-bit number is 1980.
8419 15 1980 1 m*/ d.
yields me 1073714682, when I expect 1963088820. 1963088820 shouldn't
overflow a signed 32 bit number, so I'm wondering why I'm having this
issue? I may be misunderstanding m*/
Thanks!
Alex
> include has been working great so far! I had a few questions about dmath.f> > 1. It looks like the link to > http://excamera.com/files/j1demo/docforth/nuc.fs.html is broken > 2. I'm having trouble getting m*/ to get the result that I want. I want > to multiply a double by a 16-bit number but I'm not getting the result I > expect. The double is 991459 and the 16-bit number is 1980.> > 8419 15 1980 1 m*/ d.> > yields me 1073714682, when I expect 1963088820. 1963088820 shouldn't > overflow a signed 32 bit number, so I'm wondering why I'm having this > issue? I may be misunderstanding m*/>
I don't really understand this code - the original code is
this here, I think:
https://web.archive.org/web/20181118215700/http://excamera.com/files/j1demo/docforth/nuc.fs.html
I have committed a small change, but the result is still
not correct. Perhaps you have an idea? It would also be
worthwhile, I think, to consult the source in other Forth
implementatrions. I'm not really good with this math stuff...
felix
Hi Felix, I have a couple UF questions if you don't mind entertaining
them.
First, one difference I notice between UF and other forths is there is
no >number that takes an uncounted string, only a counted string. I am
wondering what the best way to, e.g, parse a number from input is. EG
imagine my input is:
foo 5
foo -1
and I want to define "foo" to take the number and do something with it.
I have tried a few approaches:
1. Use parse, then write a new to-num that takes an uncounted string
2. use parse, then use place to store the uncounted string as a counted
string somewhere, then use number
3. Use word, which to my knowledge basically does 2, but also has added
overhead? Is there any reason not to do this?
Anything else that is simpler and more idiomatic that I may be missing?
Next, I noticed that some forths allow create / does> definitions
outside of words. it looks like UF only allows me to define does> inside
the context of a definition. Is there a reason for this?
Thanks again!
Alex
Hi, Alex!
Sorry for the delay.
> First, one difference I notice between UF and other forths is there is > no >number that takes an uncounted string, only a counted string. I am > wondering what the best way to, e.g, parse a number from input is. EG > imagine my input is:> > > foo 5> foo -1> > and I want to define "foo" to take the number and do something with it. > I have tried a few approaches:> > 1. Use parse, then write a new to-num that takes an uncounted string> 2. use parse, then use place to store the uncounted string as a counted > string somewhere, then use number> 3. Use word, which to my knowledge basically does 2, but also has added > overhead? Is there any reason not to do this?
`word` + `number` is the way to do it, I would say. Since conversion
of a string to a number is a basic operation in the outer interpreter
and I didn't want to introduce two words for this, I settled on the
version taking a counted string.
> > Anything else that is simpler and more idiomatic that I may be missing?
Not that I know of. Since this is done during interpretation, I assume
this is not performance critical, so using `word` or doing a `place`
to `pad` seems like the right way.
> Next, I noticed that some forths allow create / does> definitions > outside of words. it looks like UF only allows me to define does> inside > the context of a definition. Is there a reason for this?
I've not seen the use of `does>` outside of colon definitions, yet.
It assumes it us invoked (immediately) during compilation. One could change
it, though, to explicitly switch to the compilation state. Would you
have a use case where this would be useful?
felix
On Mon Dec 12, 2022 at 2:20 AM PST, wrote:
> Hi, Alex!>> Sorry for the delay.
No worries! Always appreciate your help. I'm still shaky on parts of
forth, I went back to the compiler/interpreter chapters of "starting
forth" after emailing you.
> `word` + `number` is the way to do it, I would say. Since conversion> of a string to a number is a basic operation in the outer interpreter> and I didn't want to introduce two words for this, I settled on the> version taking a counted string.
Makes sense. I "discovered" this but, having not seeing much forth code,
I wondered whether it was a hack.
> > Next, I noticed that some forths allow create / does> definitions> > outside of words. it looks like UF only allows me to define does> inside> > the context of a definition. Is there a reason for this?>> I've not seen the use of `does>` outside of colon definitions, yet.> It assumes it us invoked (immediately) during compilation. One could change> it, though, to explicitly switch to the compilation state. Would you> have a use case where this would be useful?
Hm, I thought I read this in some other forth code, but I think I
misread it.
The situation was, I wanted to define a word with create directly rather
than in a colon definition, but still give it a does> runtime
definition. Not sure if this is something I would need/want to do
though.
All the best,
Alex
> > > Next, I noticed that some forths allow create / does> definitions> > > outside of words. it looks like UF only allows me to define does> inside> > > the context of a definition. Is there a reason for this?> >> > I've not seen the use of `does>` outside of colon definitions, yet.> > It assumes it us invoked (immediately) during compilation. One could change> > it, though, to explicitly switch to the compilation state. Would you> > have a use case where this would be useful?> > Hm, I thought I read this in some other forth code, but I think I > misread it.> > The situation was, I wanted to define a word with create directly rather > than in a colon definition, but still give it a does> runtime > definition. Not sure if this is something I would need/want to do > though.
You can do this:
: doing does> .s ;
create foo doing
`does>` always patches the most recent definition in the
dictionary.
felix