On Mon, Apr 28, 2025 at 05:32:29PM -0400, Camm Maguire wrote:
> Greetings, and thanks so much!
> 
> Waldek Hebisch <de...@fricas.org> writes:
> 
> > AFAICS the attached Lisp file is doing the same sequence of Lisp
> > operations and exhibits the same problem.  It depends on FriCAS
> > macros, run via
> >
> > )read ttt3b.lisp
> >
> > at FriCAS prompt.
> 
> These may be the same operations, and my fix for the first issue may
> address a hidden compiler failure if any, but something else appears to
> be going on:

I am not sure what you want to say above.

> =============================================================================
> (sid)camm@glory:/mnt/sda4/debian/fricas$ fricas
> openServer result 0
>                        FriCAS Computer Algebra System 
>                  Version: FriCAS 1.3.11 built with gcl 2.7.1
>                    Timestamp: Sun Apr 27 01:41:50 UTC 2025
> -----------------------------------------------------------------------------
>    Issue )copyright to view copyright notices.
>    Issue )summary for a summary of useful system commands.
>    Issue )quit to leave FriCAS and return to shell.
> -----------------------------------------------------------------------------
>  
> 
> (1) -> )read /home/camm/ttt3b.lisp
> (0 1 2 3 4 5 6 7 8 9 10)
> (0 1 2 3 4 5 6 7 8 9 10)
> (1) -> )read /home/camm/ttt3b.lisp
> (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
> (0 1 2 3 4 5 6 7 8 9 10)
> (1) -> )read /home/camm/ttt3b.lisp
> (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
> (0 1 2 3 4 5 6 7 8 9 10)
> (1) -> )quit

That is what I see with gcl.  Expected output (and what I get with
sbcl) is:

(0 1 2 3 4 5 6 7 8 9 10)
(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
(0 1 2 3 4 5 6 7 8 9 10)
(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
(0 1 2 3 4 5 6 7 8 9 10)
(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)

So on first run gcl uses correct (current) value of n.  But
susequent runs apparently use n from previous iteration.

> (sid)camm@glory:/mnt/sda4/debian/fricas$ fricas
> openServer result 0
>                        FriCAS Computer Algebra System 
>                  Version: FriCAS 1.3.11 built with gcl 2.7.1
>                    Timestamp: Sun Apr 27 01:41:50 UTC 2025
> -----------------------------------------------------------------------------
>    Issue )copyright to view copyright notices.
>    Issue )summary for a summary of useful system commands.
>    Issue )quit to leave FriCAS and return to shell.
> -----------------------------------------------------------------------------
>  
> 
> (1) -> )fin
> GCL (GNU Common Lisp)  2.7.1 Thu Apr 10 09:38:27 PM EDT 2025  ANSI    git: 
> Version_2_7_2ore2
> Source License: LGPL(gcl,gmp), GPL(unexec,bfd,xgcl)
> Binary License:  GPL due to GPL'ed components: (XGCL UNEXEC)
> Modifications of this banner must retain notice of a compatible license
> Dedicated to the memory of W. Schelter
> 
> Use (help) to get some basic information on how to use GCL.
> Temporary directory for compiler files set to /tmp/
> 
> BOOT>(in-package :compiler)
> 
> #<"COMPILER" package>
> 
> COMPILER>(defun encap-src-val (val)
>   (typecase val
>     (function  (afe (cons 'df nil) (mf (fle val))))
>     (cons (cons (encap-src-val (car val)) (encap-src-val (cdr val))))
>     (t val)))
> 
> (defun c1constant-value (val always &aux (val (if (exit-to-fmla-p) (not (not 
> val)) val)))
>   (case 
>    val
>    ((nil) (c1nil))
>    ((t)   (c1t))
>    (otherwise
>     (let ((l (c1constant-value-object val (or always (when *compiler-compile* 
> (not *keep-gaz*))))))
>       (when l 
>       `(location 
>         ,(make-info :type (or (ltvp val)
>                               (object-type (encap-src-val val))))
>         ,l))))))
>        
> ENCAP-SRC-VAL
> 
> COMPILER>
> C1CONSTANT-VALUE
> 
> COMPILER>(in-package :boot)
> 
> #<"BOOT" package>
> 
> BOOT>(|fricas_restart|)
>                        FriCAS Computer Algebra System 
>                  Version: FriCAS 1.3.11 built with gcl 2.7.1
>                    Timestamp: Sun Apr 27 01:41:50 UTC 2025
> -----------------------------------------------------------------------------
>    Issue )copyright to view copyright notices.
>    Issue )summary for a summary of useful system commands.
>    Issue )quit to leave FriCAS and return to shell.
> -----------------------------------------------------------------------------
>  
> 
> (1) -> )read /home/camm/ttt3b.lisp
> (0 1 2 3 4 5 6 7 8 9 10)
> (0 1 2 3 4 5 6 7 8 9 10)
> (1) -> )read /home/camm/ttt3b.lisp
> (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
> (0 1 2 3 4 5 6 7 8 9 10)
> (1) -> )read /home/camm/ttt3b.lisp
> (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
> (0 1 2 3 4 5 6 7 8 9 10)

That is the same result as previously.

> (1) -> )set functions cache all
>    In general, interpreter functions will cache all values.
> (1) -> n==10
>                                                                    Type: Void
> (2) -> v==[i for i in 0..n]
>                                                                    Type: Void
> (3) -> v
>    Compiling body of rule n to compute value of type PositiveInteger 
>    n will cache all previously computed values.
>    Compiling body of rule v to compute value of type List(
>       NonNegativeInteger) 
>    v will cache all previously computed values.
> 
>    (3)  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>                                                Type: List(NonNegativeInteger)
> (4) -> n==15
>    Compiled code for n has been cleared.
>    Compiled code for v has been cleared.
>    1 old definition(s) deleted for function or rule n 
>                                                                    Type: Void
> (5) -> v
>    Compiling body of rule n to compute value of type PositiveInteger 
>    n will cache all previously computed values.
>    Compiling body of rule v to compute value of type List(
>       NonNegativeInteger) 
>    v will cache all previously computed values.
> 
>    (5)  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>                                                Type: List(NonNegativeInteger)
> (6) -> n==15
>    Compiled code for n has been cleared.
>    Compiled code for v has been cleared.
>    1 old definition(s) deleted for function or rule n 
>                                                                    Type: Void
> (7) -> v
>    Compiling body of rule n to compute value of type PositiveInteger 
>    n will cache all previously computed values.
>    Compiling body of rule v to compute value of type List(
>       NonNegativeInteger) 
>    v will cache all previously computed values.
> 
>    (7)  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
>                                                Type: List(NonNegativeInteger)
> (8) ->
> =============================================================================

This is slightly different sequence of operations, but consistent
with "uses n from previous run".  Running Lisp version multiple
times corresponds to:

n==10
v==[i for i in 0..n]
v
n==15
v
n==10
v
n==15
v
n==10
v
n==15
v

There is a difference which probably is insignificant: FriCAS uses
fresh gensyms for local variables.  In Lisp code I use ordinary
variables.

Looking more at the issue, I suspect that gcl is inlining definition
of |*0;n;1;frame1;AUX|.  I am not sure if Lisp standard allows
such inlining (those are discrete definitions via separate evals,
not parts of single file).  In this case I can (re)define called
function first and after that (re)define caller.  Such change
seem to fix this problem.  However, FriCAS in many places
assumes that redefinitions on the fly work as expected.

-- 
                              Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/fricas-devel/aBAInGfRZyNl4oVI%40fricas.org.

Reply via email to