Am I missing something basic?

105 views
Skip to first unread message

Rick C

unread,
May 28, 2022, 3:54:32 AMMay 28
to
CR .( loading Test20Hz)
\ On test failure, set output frequency
: Test20Hz ( -- ) 20 GetAmpMeas . ;
CR .( Done loading Test20Hz)
: Test1kHz ( -- ) 1000 GetAmpMeas . ;
CR .( Done loading Test1kHz)
: Test20kHz ( -- ) 20000 GetAmpMeas . ;
CR .( Done loading Test20kHz)

FLOAD 'ProductionTest_220526.f'

loading Test20Hz ok

On compile the first line prints to the screen. Nothing else does. No errors.

I can use locate to see GetAmpMeas , but locate Test20Hz gives an error.

I'm not even sure how to debug this. It must be staring me in the face, no? Am I misusing .( ?

--

Rick C.

- Get 1,000 miles of free Supercharging
- Tesla referral code - https://ts.la/richard11209

Heinrich Hohl

unread,
May 28, 2022, 5:49:01 AMMay 28
to
On Saturday, May 28, 2022 at 9:54:32 AM UTC+2, gnuarm.del...@gmail.com wrote:
> CR .( loading Test20Hz)
> \ On test failure, set output frequency
> : Test20Hz ( -- ) 20 GetAmpMeas . ;
> CR .( Done loading Test20Hz)
> : Test1kHz ( -- ) 1000 GetAmpMeas . ;
> CR .( Done loading Test1kHz)
> : Test20kHz ( -- ) 20000 GetAmpMeas . ;
> CR .( Done loading Test20kHz)

The source code looks fine. No missing spaces or hidden special characters.
Check the following:

a) Does GetAmpMeas work properly when you execute the command
directly? That is, does "20 GetAmpMeas" work as expected? Check
the stack after executing the command.

b) Is it possible that GetAmpMeas is an immediate word?
A faulty immediate word could explain the observed behavior.

Henry

Rick C

unread,
May 28, 2022, 2:33:25 PMMay 28
to
GetAmpMeas is not immediate. The file I started with before typing a very few mods (mostly documentation updates) has worked fine since this program was last modified in 2016. I know the fact that bugs are not observed, does not mean there are none, but I don't normally use immediate words and don't recall any in this code. Here's the definition.

: GetAmpMeas ( u1 -- u2 ) ( F: -- f ) \ Set frequency and measure AmpMeas as float
SetFreqRegs IF AmpMeasure dup 0 D>F ELSE -2 0E0 THEN
;

None of this code is being run when loading the file other than being compiled.

To debug a bit I added a line and eventually realized the problem is the association of .( ) and \. This is the original code. Removing the \ line makes it all work.

CR .( loading Test20Hz )
\ On test failure, set output frequency
: Test20Hz ( -- ) 20 GetAmpMeas . ;
CR .( Done loading Test20Hz)
: Test1kHz ( -- ) 1000 GetAmpMeas . ;
CR .( Done loading Test1kHz)
: Test20kHz ( -- ) 20000 GetAmpMeas . ;
CR .( Done loading Test20kHz)

Moving the \ line around allows different parts to work

CR .( loading Test20Hz )
: Test20Hz ( -- ) 20 GetAmpMeas . ;
CR .( Done loading Test20Hz)
: Test1kHz ( -- ) 1000 GetAmpMeas . ;
CR .( Done loading Test1kHz)
\ On test failure, set output frequency
: Test20kHz ( -- ) 20000 GetAmpMeas . ;
CR .( Done loading Test20kHz)

results in...

loading Test20Hz
Done loading Test20Hz
Done loading Test1kHz ok

So, somehow the .( printing and the \ comment words are interacting!

WTF???

With the last example where the \ comment is just before the Test20kHz definition, it seems to terminate interpretation.

loading Test20Hz
Done loading Test20Hz
Done loading Test1kHz ok
see test1khz
: TEST1KHZ lit 0x3E8 GETAMPMEAS . ; ok
see test20khz
^^^^^^^^^
Error(-13): TEST20KHZ is undefined

How could .( and \ be interacting like this?

Here is the startup from Win32Forth
Win32Forth: a 32 Bit Forth for Windows 95/98/ME/NT4/W2K/XP/VISTA/W7/W8/W10
Version: 6.15.05 Build: 2
Compiled: Thursday, December 24 2020, 5:12PM
Platform: Windows 10 Home, 8,747k bytes free
2,812 Words in Application dictionary
2,631 Words in System dictionary
5,443 Words total in dictionaries
20,312 Windows Constants available
Loading Win32For.CFG
Loading Win32ForUser.CFG

Current directory is: C:\Forth\Win32F61505\Win32Forth
Program path is: C:\Forth\Win32F61505\Win32Forth\Win32for.exe
Forth path is: C:\Forth\Win32F61505\Win32Forth\
Application path is: not set

Maybe I'll try posting to the Win32Forth groups.io group.

--

Rick C.

+ Get 1,000 miles of free Supercharging
+ Tesla referral code - https://ts.la/richard11209

Rick C

unread,
May 28, 2022, 4:18:00 PMMay 28
to
I tried sprinkling debug code around the overall program and find it does not fail until reaching this point!

CR .( Find command failure 1)
\ Comment failure test case
...
CR .( Find command failure 7)
\ Comment failure test case

CR .( loading Test20Hz )
: Test20Hz ( -- ) 20 GetAmpMeas . ;
CR .( Done loading Test20Hz)
: Test1kHz ( -- ) 1000 GetAmpMeas . ;
CR .( Done loading Test1kHz)
\ On test failure, set output frequency <<<<<< only fails here
: Test20kHz ( -- ) 20000 GetAmpMeas . ;
CR .( Done loading Test20kHz)

results in this output...

Find command failure 1
... other messages
Find command failure 2
Find command failure 3
Find command failure 4
Find command failure 5
Find command failure 6
Find command failure 7
loading Test20Hz
Done loading Test20Hz
Done loading Test1kHz ok

The final .( does not print. The definition after it is not executed.

In an attempt to define what sets this off, it gets very strange indeed.


\ comment
CR .( loading Test20Hz)
\ comment
CR .( loading Test20Hz, really)
\ comment
\ : Test20Hz ( -- ) 20 GetAmpMeas . ;
\ comment
CR .( Done loading Test20Hz)
\ comment
: Test1kHz ( -- ) 1000 GetAmpMeas . ;
\ comment
CR .( Done loading Test1kHz)
: Test20kHz ( -- ) 20000 GetAmpMeas . ;
CR .( Done loading Test20kHz)

Notice the definition of Test20Hz is commented out. When run produces...

Find command failure 7
loading Test20Hz
loading Test20Hz, really ok

If that line is actually removed it produces...

Find command failure 7
loading Test20Hz ok

This is making no sense at all that I can follow.

--

Rick C.

-- Get 1,000 miles of free Supercharging
-- Tesla referral code - https://ts.la/richard11209

P Falth

unread,
May 28, 2022, 4:18:28 PMMay 28
to
Could it be that your file has UNIX line endings and Win32Forth are expecting Windows.

It looks like \ makes the rest of the file a comment

BR
Peter

Rick C

unread,
May 28, 2022, 4:29:48 PMMay 28
to
I tried deleting and retyping lines, especially the comment line. This has all been done under Windows by typing into an editor I've used for 20+ years, so hard to see how that could happen. Also, the last test showed a very strange result where deleting a line that is commented out causes the symptom from the code above to change.

--

Rick C.

-+ Get 1,000 miles of free Supercharging
-+ Tesla referral code - https://ts.la/richard11209

P Falth

unread,
May 28, 2022, 4:43:37 PMMay 28
to
Check the file in a hex editor to find out what ends the comment line.
It really look like it lets the comment run to the end of the file.
What happens if you put your comments inside ( ) instead?

Rick C

unread,
May 28, 2022, 6:40:59 PMMay 28
to
Ok, that's what it was. Somehow the editor was using Linux line terminators and I guess Forth is looking for the 0x0D. It didn't happen on every comment because they had been typed prior to this setting getting changed... at least two computers ago.

So I guess if I copied the offending NEW comment, the problem would move with that. But I can't test the old anomalies because when I changed the setting, I let it fix all the Linux terminators it found.

I'm so glad to have gotten to the bottom of this. Thanks. I really did not believe that was the problem, because I never use the Linux setting. But I haven't used this editor much since I switched computers last year. So it's been using that setting all this time.

This is one of those things that cause problems with virtually no advantage. The two camps are never going to change, so we have to live with the muckups because of it.

Thanks again,

--

Rick C.

+- Get 1,000 miles of free Supercharging
+- Tesla referral code - https://ts.la/richard11209

Anton Ertl

unread,
May 29, 2022, 3:21:11 AMMay 29
to
Rick C <gnuarm.del...@gmail.com> writes:
[CRLF vs. LF (vs. CR)]
>This is one of those things that cause problems with virtually no advantage=
>. The two camps are never going to change, so we have to live with the muc=
>kups because of it.=20

You could use a Forth system (such as Gforth) that accepts all three
as newlines, or change your Forth system in such a way. This is a
case where Postel's law really works.

- 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: http://www.forth200x.org/forth200x.html
EuroForth 2021: https://euro.theforth.net/2021

minf...@arcor.de

unread,
May 29, 2022, 3:44:44 AMMay 29
to
The small & free notepad++ editor can display & define & change line terminations
of DOS/Windows & Linux/Unix & Mac styles.
Very handy.
Reply all
Reply to author
Forward
0 new messages