• Problem compliling words in GFROTH

    From Jose Morales@21:1/5 to All on Sun Oct 30 04:33:45 2022
    Sorry all, it looks like I'm having an issue I can't seem to understand my problem.

    Here is what I'm trying to accomplish... it seems to work when I'm interactive, with the exception if the condition. I have some concerns on the AND condition as that might be the problem... but it fails on the last part off the definition.

    \ Next we calculate an uncorrected date for the Paschal full moon, p'; then we apply a
    \ minor correction to get the exact date, p, as the number of days after 21st March.
    \ p' = (3 - 11g + s - l) mod 30
    \ if (p' == 29) or (p' == 28 and g > 11) then
    \ p = p' - 1
    \ else
    \ p = p'

    Here is my word that fails to compile...
    : _PascalCorr ( -- -- ) compiled
    3 11 G @ * - S @ L @ - + 30 MOD P' ! compiled
    P' @ DUP 29 = IF P ! ELSE DROP compiled
    P' @ DUP 28 = AND G @ 11 > IF 1 - P ! ELSE DROP THEN compiled
    P' @ P ! ;
    :163: unstructured
    P' @ P ! >>>;<<<
    Backtrace:
    $7F185F1E8988 throw
    $7F185F1F84E0 c(abort")
    $7F185F2055E0 def?
    $7F185F1F18C0 ;-hook

    Any pointers into this issue would shed some light as I seem to be missing something.

    Cheers!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Doug Hoffman@21:1/5 to jem...@gmail.com on Sun Oct 30 06:44:58 2022
    It would help if you provided example values for
    your input variables and what you expect the
    output P to then be.

    Just glancing at your pseudocode and your Forth
    definition they don't look like the same algorithm.

    Your Forth definition uses two IF statements
    where your pseudocode uses one.

    Further, your Forth code is missing a THEN for
    one of the IFs which is probably why it did not compile..

    Did you mean something like:

    : pascalCorr' { g s L -- p }
    3 11 g * - s + L - 30 mod \ leaves p' on stack
    dup 29 = over 28 = g 11 > and or
    if 1-
    then ;

    I used locals for simplicity and readability but left p'
    on the stack.
    Once it works you could easily remove the locals
    and replace with variables (and @ !).

    -Doug

    On Sunday, October 30, 2022 at 7:33:47 AM UTC-4, jem...@gmail.com wrote:
    Sorry all, it looks like I'm having an issue I can't seem to understand my problem.

    Here is what I'm trying to accomplish... it seems to work when I'm interactive, with the exception if the condition. I have some concerns on the AND condition as that might be the problem... but it fails on the last part off the definition.

    \ Next we calculate an uncorrected date for the Paschal full moon, p'; then we apply a
    \ minor correction to get the exact date, p, as the number of days after 21st March.
    \ p' = (3 - 11g + s - l) mod 30
    \ if (p' == 29) or (p' == 28 and g > 11) then
    \ p = p' - 1
    \ else
    \ p = p'

    Here is my word that fails to compile...
    : _PascalCorr ( -- -- ) compiled
    3 11 G @ * - S @ L @ - + 30 MOD P' ! compiled
    P' @ DUP 29 = IF P ! ELSE DROP compiled
    P' @ DUP 28 = AND G @ 11 > IF 1 - P ! ELSE DROP THEN compiled
    P' @ P ! ;
    :163: unstructured
    P' @ P ! >>>;<<<
    Backtrace:
    $7F185F1E8988 throw
    $7F185F1F84E0 c(abort")
    $7F185F2055E0 def?
    $7F185F1F18C0 ;-hook

    Any pointers into this issue would shed some light as I seem to be missing something.

    Cheers!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anton Ertl@21:1/5 to Jose Morales on Sun Oct 30 15:58:48 2022
    Jose Morales <jemo07@gmail.com> writes:
    Here is my word that fails to compile...
    : _PascalCorr ( -- -- ) compiled
    3 11 G @ * - S @ L @ - + 30 MOD P' ! compiled
    P' @ DUP 29 = IF P ! ELSE DROP compiled
    ^^
    This IF has no THEN

    P' @ DUP 28 = AND G @ 11 > IF 1 - P ! ELSE DROP THEN compiled
    P' @ P ! ;
    :163: unstructured
    P' @ P ! >>>;<<<

    - 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: https://forth-standard.org/
    EuroForth 2022: https://euro.theforth.net

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jemo07@gmail.com@21:1/5 to Doug Hoffman on Sun Oct 30 11:54:36 2022
    On Sunday, October 30, 2022 at 2:45:00 PM UTC+1, Doug Hoffman wrote:
    It would help if you provided example values for
    your input variables and what you expect the
    output P to then be.

    Just glancing at your pseudocode and your Forth
    definition they don't look like the same algorithm.

    Your Forth definition uses two IF statements
    where your pseudocode uses one.

    Further, your Forth code is missing a THEN for
    one of the IFs which is probably why it did not compile..

    Did you mean something like:

    : pascalCorr' { g s L -- p }
    3 11 g * - s + L - 30 mod \ leaves p' on stack
    dup 29 = over 28 = g 11 > and or
    if 1-
    then ;

    Thank you Dough, i missed the second THEN for the failed compilation, Thanks Anton for catching this also.

    What I'm trying to do is multiple condition testing in the IF statement, was hopping for a ANDIF word...

    So the conditions are:
    P' == 28 ( Condition1)
    G > 11 ( Condition2)

    if Condittion1 && Condition2 TRUE THEN P = P1 - 1.
    In testing the values, consider P'=28 and G=15
    So this case the value of P is P' 1- or 27

    Not sure if this is a case for factoring and testing the condition outside with a new word.

    Again, thank you.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From minforth@arcor.de@21:1/5 to jem...@gmail.com on Sun Oct 30 12:59:52 2022
    jem...@gmail.com schrieb am Sonntag, 30. Oktober 2022 um 19:54:38 UTC+1:
    On Sunday, October 30, 2022 at 2:45:00 PM UTC+1, Doug Hoffman wrote:
    It would help if you provided example values for
    your input variables and what you expect the
    output P to then be.

    Just glancing at your pseudocode and your Forth
    definition they don't look like the same algorithm.

    Your Forth definition uses two IF statements
    where your pseudocode uses one.

    Further, your Forth code is missing a THEN for
    one of the IFs which is probably why it did not compile..

    Did you mean something like:

    : pascalCorr' { g s L -- p }
    3 11 g * - s + L - 30 mod \ leaves p' on stack
    dup 29 = over 28 = g 11 > and or
    if 1-
    then ;

    Thank you Dough, i missed the second THEN for the failed compilation, Thanks Anton for catching this also.

    What I'm trying to do is multiple condition testing in the IF statement, was hopping for a ANDIF word...

    So the conditions are:
    P' == 28 ( Condition1)
    G > 11 ( Condition2)

    if Condittion1 && Condition2 TRUE THEN P = P1 - 1.
    In testing the values, consider P'=28 and G=15
    So this case the value of P is P' 1- or 27

    Not sure if this is a case for factoring and testing the condition outside with a new word.

    Again, thank you.

    G 11 > P' 28 = AND P +

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jemo07@gmail.com@21:1/5 to All on Mon Oct 31 02:26:00 2022
    Again, thank you.
    G 11 > P' 28 = AND P +

    Thank you all!

    It's all working now as expected, is the final working def of the word:

    3 11 G @ * - S @ L @ - + 30 MOD P' !
    P' @ DUP 29 = IF P ! ELSE DROP
    P' @ DUP 28 = G @ 11 > AND IF 1 - P ! ELSE
    P' @ P ! THEN THEN ;

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)