"Undefined name" error

29 views
Skip to first unread message

David Meyer

unread,
Jul 25, 2026, 3:50:59 AMJul 25
to 4th-co...@googlegroups.com
I'm trying to compile a 4tH source that begins as follows, but the "0"
at the beginning of the line "0 CONSTANT au-idx ..." triggers the error
"Word 0: Undefined name".

========== The source ==========
\ YUKO.4TH - YUnit KOnverter library for 4tH

\ Programmer: David Meyer <pa...@sdf.org> +JMJ
\ Date created: July 23, 2026
\ Language: 4tH v3.64
\ Source computer: Dell Optiplex 7010/Devuan Excalibur 6 "boxy"

\ Based on yuko3.fs by David Meyer.

\ All non-SI/metric units are US customary units.


\ Constants -- unit table indices
0 CONSTANT au-idx \ Astronomical unit [astronomical]
1 CONSTANT cup-idx \ Cup [volume]
2 CONSTANT ft-idx \ Foot [length]
3 CONSTANT floz-idx \ Fluid ounce [volume]
...
========== End source ==========

However, the following source compiles without errors:

========== The other source ==========
\ This is a comment

0 CONSTANT my-const

: test my-const . cr ;
========== End other source ==========

What am I doing wrong?


--
David Meyer
Takarazuka, Japan
pa...@sdf.org

The Beez

unread,
Jul 25, 2026, 8:50:43 AMJul 25
to 4tH-compiler
Hi David!

Frankly, I don't think you didn't make any error at all. I think it's your editor. What I think that happened is that there is some kind of control character in your source messing things up.

Fortunately, 4tH comes with a utility to clean those up:

pp4th -x bin2txt.4th yuko.4th yuko-new.4th

Sure, if you try to compile that one, you will probably get this message AGAIN, but this time it will point to the place where the offending code is, e.g. 0 CONSTANTau-idx

If you want, I can add an option where it is replaced by a space or something like that. Now why do I think that? I copied the source literally from your email -- and this was the result:

---8<---
\   YUKO.4TH - YUnit KOnverter library for 4tH

\   Programmer: David Meyer <nob...@nowhere.to.be> +JMJ              

\   Date created: July 23, 2026              
\   Language: 4tH v3.64
\   Source computer: Dell Optiplex 7010/Devuan Excalibur 6 "boxy"

\   Based on yuko3.fs by David Meyer.

\   All non-SI/metric units are US customary units.

\ Constants -- unit table indices
 0 CONSTANT au-idx     \ Astronomical unit [astronomical]
 1 CONSTANT cup-idx    \ Cup [volume]
 2 CONSTANT ft-idx     \ Foot [length]
 3 CONSTANT floz-idx   \ Fluid ounce [volume]

: hello ;              \ you can't compile nothing..
---8<---
$ pp4th -dn yuko.4th
4tH message: No errors at word 2
Object size: 2 words
String size: 0 chars
Variables  : 0 cells
Strings    : 0 chars
Symbols    : 5 names
Reliable   : Yes

  Addr| Opcode                        Operand   Argument

     0| branch                              1   hello
     1| exit                                0

---8<---

That's how I would go about it -- because to me it seems to be the most likely cause of your problem.

Hans Bezemer

The Beez

unread,
Jul 25, 2026, 9:27:07 AMJul 25
to 4tH-compiler
The source is included. Use the -c switch to replace the offending character by spaces.

Hans Bezemer
bin2txt.4th

David Meyer

unread,
Jul 25, 2026, 10:12:20 AMJul 25
to 4th-co...@googlegroups.com
Neither version of bin2txt.4th reveals any stray control characters in
the source. Any other ideas?

The Beez

unread,
Jul 26, 2026, 6:02:35 AMJul 26
to 4tH-compiler
Send me the source, I'll figure ut out. Need contact information?

Hans Bezemer

The Beez

unread,
Jul 26, 2026, 6:12:59 AMJul 26
to 4tH-compiler
BTW, if your source starts with LOTS of variable declarations, it does't need to bomb out at the first one. It may be pages later. Once a word has been compiled, it starts with 'word 1'. i handle this by placing an [ABORT] at the top and work my way down till 'Compilation aborted' makes place for another message like 'Undefined name'. Then you can pinpoint it. It's not the way you'd prefer to do it, but it does work. One thing -- the compiler has never proven me wrong in recent times. There must be somethibg there.

Hans Bezemer

David Meyer

unread,
Jul 26, 2026, 9:10:31 AMJul 26
to 4th-co...@googlegroups.com
The Beez <the.bee...@gmail.com> writes:

> BTW, if your source starts with LOTS of variable declarations, it does't need to
> bomb out at the first one. It may be pages later. Once a word has been
> compiled, it starts with 'word 1'. i handle this by placing an [ABORT] at the top
> and work my way down till 'Compilation aborted' makes place for another
> message like 'Undefined name'. Then you can pinpoint it. It's not the way you'd
> prefer to do it, but it does work.

THAT is a big hint! I didn't realize that compile errors on "word 0"
include all the source up to the first word definition. The [ABORT]
trick helped me find a comment missing the space between the "\" and the
comment text.

Now getting an error that I think I understand. Debugging continues ...

The Beez

unread,
Jul 26, 2026, 9:49:21 AMJul 26
to 4tH-compiler
That's great news!

BTW, I wasn't sitting on my hand either:

---8<---
( YUKO - YUnit KOnverter for VAX-11 fig-Forth            3/19 )
( Constants -- unit table indices )
 0 CONSTANT au-idx     ( Astronomical unit [astronomical] )
 1 CONSTANT cup-idx    ( Cup [volume] )
 2 CONSTANT ft-idx     ( Foot [length] )
 3 CONSTANT floz-idx   ( Fluid ounce [volume] )
 4 CONSTANT gm-idx     ( Gigameter [astronomical] )
 5 CONSTANT gal-idx    ( Gallon [volume] )
 6 CONSTANT gram-idx   ( Gram [mass] )
 7 CONSTANT inch-idx   ( Inch [length] )
 8 CONSTANT kg-idx     ( Kilogram [mass] )
 9 CONSTANT km-idx     ( Kilometer [length] )
10 CONSTANT lb-idx     ( Pound [mass] )
11 CONSTANT ly-idx     ( Light-year [astronomical] )
12 CONSTANT liter-idx  ( Liter [volume] )

( YUKO - YUnit KOnverter for VAX-11 fig-Forth            4/19 )
( Constants -- unit table indices cont. )
13 CONSTANT mi-idx     ( Mile [length] )
14 CONSTANT ml-idx     ( Milliliter [volume] )
15 CONSTANT mm-idx     ( Millimeter [length] )
16 CONSTANT meter-idx  ( Meter [length] )
17 CONSTANT oz-idx     ( Ounce [mass] )
18 CONSTANT pc-idx     ( Parsec [astronomical] )
19 CONSTANT pt-idx     ( Pint [volume] )
20 CONSTANT qt-idx     ( Quart [volume] )
21 CONSTANT tsp-idx    ( Teaspoon [volume] )
22 CONSTANT tbsp-idx   ( Tablespoon [volume] )
23 CONSTANT yd-idx     ( Yard [length] )
24 CONSTANT dc-idx     ( degrees Celsius [temperature] )
25 CONSTANT df-idx     ( degrees Fahrenheit [temperature] )

( YUKO - YUnit KOnverter for VAX-11 fig-Forth            5/19 )
( Constants -- unit table indices cont. )
26 CONSTANT kelvin-idx ( Kelvin [temperature] )
( Constants -- unit quantities )
0 CONSTANT length-qty
1 CONSTANT volume-qty
2 CONSTANT mass-qty
3 CONSTANT astro-qty   ( Astronomical distance )
4 CONSTANT temp-qty    ( Temperature )

( YUKO - YUnit KOnverter for VAX-11 fig-Forth            6/19 )
( Constants -- table limits )
27 CONSTANT unit-entries
( Unit quantity table )
TABLE unit-qty
  astro-qty   , volume-qty , length-qty , volume-qty ,
  astro-qty   , volume-qty , mass-qty   , length-qty ,
  mass-qty    , length-qty , mass-qty   , astro-qty  ,
  volume-qty  , length-qty , volume-qty , length-qty ,
  length-qty  , mass-qty   , astro-qty  , volume-qty ,
  volume-qty  , volume-qty , volume-qty , length-qty ,
  temp-qty    , temp-qty   , temp-qty   ,
---8<---
4tH message: No errors at word 27
Object size: 27 words

String size: 0 chars
Variables  : 0 cells
Strings    : 0 chars
Symbols    : 34 names
Reliable   : Yes

---8<---

Still - no errors. :-( Glad you figured it out! :-)

Hans Bezemer

David Meyer

unread,
Jul 26, 2026, 11:55:47 PMJul 26
to 4th-co...@googlegroups.com
The Beez <the.bee...@gmail.com> writes:

> BTW, I wasn't sitting on my hand either:

It's interesting that 4tH was able to compile that much of the fig-Forth
version of my program. I ported the program to Gforth and am working on
a 4tH version based on that. It will feature a homemade "calculator
mode" based on fdc.4th.

I'll post when I've got it working, or sooner if I get stumped again. ;)
Reply all
Reply to author
Forward
0 new messages