~aw/misc

12 4

UF

Details
Message ID
<YzO+G7dR0gIoyXBs@localhost.lan>
DKIM signature
missing
Download raw message
Thread for me to document discussion of the UF project!

http://www.call-with-current-continuation.org/uf/uf.html
Details
Message ID
<YzO+yRs+3V4L04BH@localhost.lan>
In-Reply-To
<YzO+G7dR0gIoyXBs@localhost.lan> (view parent)
DKIM signature
missing
Download raw message
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
Details
Message ID
<16643557470.711103@mail.networkname.de>
In-Reply-To
<YzO+yRs+3V4L04BH@localhost.lan> (view parent)
DKIM signature
missing
Download raw message
> 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
Details
Message ID
<16643657760.684158@mail.networkname.de>
In-Reply-To
<YzO+yRs+3V4L04BH@localhost.lan> (view parent)
DKIM signature
missing
Download raw message
> 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
Details
Message ID
<270A9413-9E73-43AA-BBE6-16061498B3EA@alexwennerberg.com>
In-Reply-To
<16643657760.684158@mail.networkname.de> (view parent)
DKIM signature
missing
Download raw message
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
> 
Details
Message ID
<YzjiDTmKxhnsfm0k@localhost.lan>
In-Reply-To
<16643657760.684158@mail.networkname.de> (view parent)
DKIM signature
missing
Download raw message
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
Details
Message ID
<16647274860.928834@mail.networkname.de>
In-Reply-To
<YzjiDTmKxhnsfm0k@localhost.lan> (view parent)
DKIM signature
missing
Download raw message
> 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
Details
Message ID
<16648816170.683436@mail.networkname.de>
In-Reply-To
<YzjiDTmKxhnsfm0k@localhost.lan> (view parent)
DKIM signature
missing
Download raw message
Hi!

I pushed a few fixes (`>=` and `<=` where broken, if you can
believe it), dmath should work better now, I think.


felix
Details
Message ID
<CNEIEYTDUSFW.3BZQVJ6W6XFK5@localhost>
In-Reply-To
<16648816170.683436@mail.networkname.de> (view parent)
DKIM signature
missing
Download raw message
Looks like that fixed my issue, thanks!

Alex
Details
Message ID
<Y5YheSLSmI1QSF37@localhost.lan>
In-Reply-To
<YzO+yRs+3V4L04BH@localhost.lan> (view parent)
DKIM signature
missing
Download raw message
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
Details
Message ID
<16708399410.285758@mail.networkname.de>
In-Reply-To
<Y5YheSLSmI1QSF37@localhost.lan> (view parent)
DKIM signature
missing
Download raw message
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
Details
Message ID
<COZSI0NL7W9C.26FLTNNWDUIP7@localhost>
In-Reply-To
<16708399410.285758@mail.networkname.de> (view parent)
DKIM signature
missing
Download raw message
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
Details
Message ID
<16708451030.0206708@mail.networkname.de>
In-Reply-To
<COZSI0NL7W9C.26FLTNNWDUIP7@localhost> (view parent)
DKIM signature
missing
Download raw message
> > > 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
Reply to thread Export thread (mbox)