Re: [fricas-devel] )fin, restart, (|spad|) with Clozure CL based FriCAS

2024-05-24 Thread Grégory Vanuxem
Hello Waldek,

> When this code was written Clozure CL documentation about building
> text mode applications was rather poor.  I just followed one of
> examples that worked OK.  And Clozure CL folks did not mention
> 'ccl::toplevel-loop'.  IIUC they later simplified and improved
> creation of applications.
>
> Your code seem to be working fine.  There is a question with which
> version of Clozure CL it works, but AFAICS is works with all
> Clozure CL versions that work on may machine.  Clozure CL 1.9 and
> older seem to be broken on my machine, the patch works with Clozure
> CL 1.10 and later.  I will commit the patch, unless you want to
> update it.

I see no update, it is simple as it is, I would be glad if you commit
it. For CCLversions I have only tested the actual versions, I followed
the documentation, but it is better I agree to test previous ones, I
did not know about the recent improvement. For ccl::toplevel-loop, I
found it digging the CCL source code.

- Greg

-- 
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 on the web visit 
https://groups.google.com/d/msgid/fricas-devel/CAHnU2dYPWpd85a5dN95zJWjsHR__erAZ7jkTZ3yLyULLZ45gkA%40mail.gmail.com.


Re: [fricas-devel] )fin, restart, (|spad|) with Clozure CL based FriCAS

2024-05-24 Thread Waldek Hebisch
On Wed, May 22, 2024 at 10:03:32PM +0200, Grégory Vanuxem wrote:
> Le mar. 21 mai 2024 à 20:32, Waldek Hebisch  a écrit :
> >
> > On Tue, May 21, 2024 at 01:57:45PM +0200, Grégory Vanuxem wrote:
> >
> > The function to start FriCAS is 'fricas_restart'.  'fricas_restart'
> > is doing some initialization which may be unnecessary when executed
> > second time.  OTOH re-doing initalization should be harmless and
> > some probably is needed.
> 
> I see that, and in fact only propog CL use (|spad|) directly in other
> piece(s ?) of code. Using it is handy though, not everything is
> reinitialized.

With 'spad' Ctrl-C has no chance of working as expected: there is
no handler to handle it.

> So now, my solution to my problem. A proposed diff is attached, it
> uniformizes/simplifies the Clozure CL boot I think.
> 
> Looking at the attached transcript in my previous email I was
> surprised to see that the banner was displayed at that time, and
> experimenting more with the pure CL interpreter after ')fin' I first
> saw that calling Julia was not possible. When you embed Julia using
> libjulia, Julia does not support multithreaded code from the host
> process, I encountered this with SBCL, and it leads to segfault, bad
> stack etc. Only the thread that initialized Julia is able to use
> commands using the C interface. Experimenting some interruptions and
> backtraces I saw a thread started after ')fin'. Apparently the "main"
> process (not exactly in fact, the actual boot process of FriCAS bypass
> the CCL read-eval-print loop main thread) was at that time in a idle
> state or not started or sleeping, I don't really know, and the
> ccl::terminate method is then called on reclaimed CL objects. It's
> another thread in fact. FriCAS on CCL is then a multithreaded app :-)
> 
> Diggering more in 'save-core-restart' I saw that only FriCAS on top of
> CCL is using a fricas-application class, which is just a
> ccl::application class:
> 
> (defclass fricas-application (ccl::application) ())
> 
> and uses it for the ccl::toplevel-function at startup. My main problem
> is that with this class 'ccl::terminate' is not executed and the
> "main" process/thread is needed to execute it. To speak frankly I do
> not really understand why, SBCL, for example, can populate a threaded
> compatible FIFO queue in a garbage collector thread.
> 
> I so cleaned/uniformized the FriCAS on CCL startup not to use this
> class which apparently runs in another thread than the "main" thread.
> Uniformized in the sense that the other CL implementations do not need
> a particular class for FriCAS. The modification is very simple (also
> attached):
> 
> ===
> diff --git a/src/lisp/fricas-lisp.lisp b/src/lisp/fricas-lisp.lisp
> index bf46a61..4e7a222 100644
> --- a/src/lisp/fricas-lisp.lisp
> +++ b/src/lisp/fricas-lisp.lisp
> @@ -64,24 +64,10 @@ with this hack and will try to convince the GCL
> crowd to fix this.
>  ;;
>  #+:openmcl
>  (progn
> -
> -(defclass fricas-application (ccl::application) ())
> -
> -(defvar *my-toplevel-function* nil)
> -
>  (defvar *ccl-default-directory* nil)
> -
> -(defmethod ccl::toplevel-function ((app fricas-application) init-file)
> -(declare (ignore init-file))
> -(call-next-method) ; this is critical, but shouldn't be.
> -(funcall *my-toplevel-function*)
> -(let ((ap (make-instance 'ccl::lisp-development-system)))
> -(ccl::toplevel-function ap init-file)))
> -
>  ;;; Disable default argument processing
>  (defmethod ccl::process-application-arguments
> -   ((app fricas-application) error-flag opts args) nil)
> -
> +((app ccl::application) error-flag opts args) nil)
>  )
> 
>  ;;; Disable argument processing in GCL
> @@ -143,12 +129,11 @@ with this hack and will try to convince the GCL
> crowd to fix this.
> #'(lambda () nil)))
>   (top-fun #'(lambda ()
> (set-initial-parameters)
> -   (funcall restart-fun
> +   (funcall restart-fun)
> +   (ccl::toplevel-loop
>  (setf *ccl-default-directory* ccl-dir)
> -(setf *my-toplevel-function* top-fun)
> -(CCL::save-application core-image
> -   :PREPEND-KERNEL t
> -   :application-class 
> 'fricas-application)
> +(CCL::save-application core-image :toplevel-function top-fun
> +   :PREPEND-KERNEL t)
>  (QUIT))
>  #+:lispworks
>(progn
> ===
> 
> And as you can see with '(ccl::toplevel-loop)' in 'top-fun', this
> allows the user to enter in the Clozure CL REPL with ')fin' in a
> relatively clean manner. I tested this code with SBCL and Clozure CL,
> tests passed. That also solves my issues and, how I view this, this is
> cleaner.
> 
> Thoughts?

When this code was 

Re: [fricas-devel] )fin, restart, (|spad|) with Clozure CL based FriCAS

2024-05-22 Thread Grégory Vanuxem
CTRL-C is not affected in fact. This is the usual behavior of FriCAS
with Clozure CL.
Sorry for the noise.

Le mer. 22 mai 2024 à 22:08, Grégory Vanuxem  a écrit :
>
> Oh, zut! (responding to myself)
>
> > (there are several use of 'CATCH' and there is 'handler-bind').
>
> Badly handled. CTRL-C for example.
>
> More work needed in this regard.
>
> Le mer. 22 mai 2024 à 22:03, Grégory Vanuxem  a écrit :
> >
> > Hello Waldek, hello all,
> >
> > First, thanks for your response, it was very instructive it leads me
> > to solve this long outstanding issue with my FriCAS copy.
> >
> > Le mar. 21 mai 2024 à 20:32, Waldek Hebisch  a écrit :
> > >
> > > On Tue, May 21, 2024 at 01:57:45PM +0200, Grégory Vanuxem wrote:
> > > > Hello,
> > > >
> > > > I try to understand why a Clozure CL 'terminate' method is not called
> > > > from the interpreter. I have a CL class jlref, when a jlref object is
> > > > no longer referenced the CL garbage collector reclaims it. It is
> > > > possible in different CL implementations to add a 'hook' to do some
> > > > job at that time. Personally I then unreference the real Julia object
> > > > in such a way it can be GC reclaimed in Julia, jlref is just a class
> > > > that holds information about it.
> > > >
> > > > For SBCL I have no problem, but 'ccl:terminate' which should be
> > > > automatically called is never called. But, and this is the main point,
> > > > following an advice in a Clozure mailing list, I tried to use/define
> > > > this method directly at execution time using ')fin', and surprisingly,
> > > > using ')fin' automatically triggers 'terminate' on every objects that
> > > > are/(were ?) reclaimed.
> > > >
> > > > So my question, what does ')fin' do? And do you happen to know where I
> > > > need to look in the FriCAS source code to better understand its
> > > > effect?
> > >
> > > AFAIK ')fin' is doing "nothing", is just returns back to whatever Lisp
> > > was doing befor calling FriCAS.  To understand relation with Lisp,
> > > look at 'src/lisp/fricas-lisp.lisp', in particular 'save-core-restart'.
> >
> > Yes!!! This is what helped me. I looked more carefully at this function 
> > and..
> >
> > >
> > > > Furthermore, in src/interp/int-top.boot, the documentation says that
> > > > to return to the interpreterafer after ')fin'  '(restart)' should be
> > > > used. In fact, before some change in the FriCAS source I think, so I
> > > > used (|spad|). Again following an advice. And, again, with Clozure CL,
> > > > contrary to SBCL, that leads to strange things after returning to the
> > > > interpreter and executing foreign code (principally bad addresses and
> > > > therefore segfault).
> > >
> > > The function to start FriCAS is 'fricas_restart'.  'fricas_restart'
> > > is doing some initialization which may be unnecessary when executed
> > > second time.  OTOH re-doing initalization should be harmless and
> > > some probably is needed.
> >
> > I see that, and in fact only propog CL use (|spad|) directly in other
> > piece(s ?) of code. Using it is handy though, not everything is
> > reinitialized.
> >
> > > Note that ')fin' is really unsuppored by FriCAS, basically
> > > it is "pray that Lisp will do what you want".  In particular IIRC
> > > it simply quits FriCAS when using ECL and I think it never fully
> > > worked with Clozure CL.
> > >
> > > > So maybe I first need to know a better CL command, to return to the
> > > > interpreter? But also, of course, to know why the ccl:terminate is not
> > > > called in the interpreter. R. Munyer in the CCL mailing list found a
> > > > way, see the attached transcript file, but he uses ')fin' and no
> > > > Clozure CL FFI. I tried to use different (eva-when) to define the
> > > > ccl:terminate method without success since the code is build/compiled
> > > > (src/lisp).
> > >
> > > I think that ')fin' is irrelevant, you should get the same effect
> > > using ')lisp' or if that is inconvenient you can put code in the
> > > file and use ')read'.  The main difference is that FriCAS needs
> > > specific settings of several global variables and FriCAS catches
> > > errors (there are several use of 'CATCH' and there is 'handler-bind').
> > > This _should_ make no difference.  What _may_ matter is order of
> > > initialization.  In particular FriCAS performs some initializations
> > > before dumping image.  But several thing do not survive to
> > > restarted image, so need to be done later, after start of new image.
> >
> > I guessed after your email that the behavior of ')fin' is somewhat 
> > undefined.
> >
> > So now, my solution to my problem. A proposed diff is attached, it
> > uniformizes/simplifies the Clozure CL boot I think.
> >
> > Looking at the attached transcript in my previous email I was
> > surprised to see that the banner was displayed at that time, and
> > experimenting more with the pure CL interpreter after ')fin' I first
> > saw that calling Julia was not possible. When you embed Julia using
> > libjulia, Julia 

Re: [fricas-devel] )fin, restart, (|spad|) with Clozure CL based FriCAS

2024-05-22 Thread Grégory Vanuxem
Oh, zut! (responding to myself)

> (there are several use of 'CATCH' and there is 'handler-bind').

Badly handled. CTRL-C for example.

More work needed in this regard.

Le mer. 22 mai 2024 à 22:03, Grégory Vanuxem  a écrit :
>
> Hello Waldek, hello all,
>
> First, thanks for your response, it was very instructive it leads me
> to solve this long outstanding issue with my FriCAS copy.
>
> Le mar. 21 mai 2024 à 20:32, Waldek Hebisch  a écrit :
> >
> > On Tue, May 21, 2024 at 01:57:45PM +0200, Grégory Vanuxem wrote:
> > > Hello,
> > >
> > > I try to understand why a Clozure CL 'terminate' method is not called
> > > from the interpreter. I have a CL class jlref, when a jlref object is
> > > no longer referenced the CL garbage collector reclaims it. It is
> > > possible in different CL implementations to add a 'hook' to do some
> > > job at that time. Personally I then unreference the real Julia object
> > > in such a way it can be GC reclaimed in Julia, jlref is just a class
> > > that holds information about it.
> > >
> > > For SBCL I have no problem, but 'ccl:terminate' which should be
> > > automatically called is never called. But, and this is the main point,
> > > following an advice in a Clozure mailing list, I tried to use/define
> > > this method directly at execution time using ')fin', and surprisingly,
> > > using ')fin' automatically triggers 'terminate' on every objects that
> > > are/(were ?) reclaimed.
> > >
> > > So my question, what does ')fin' do? And do you happen to know where I
> > > need to look in the FriCAS source code to better understand its
> > > effect?
> >
> > AFAIK ')fin' is doing "nothing", is just returns back to whatever Lisp
> > was doing befor calling FriCAS.  To understand relation with Lisp,
> > look at 'src/lisp/fricas-lisp.lisp', in particular 'save-core-restart'.
>
> Yes!!! This is what helped me. I looked more carefully at this function and..
>
> >
> > > Furthermore, in src/interp/int-top.boot, the documentation says that
> > > to return to the interpreterafer after ')fin'  '(restart)' should be
> > > used. In fact, before some change in the FriCAS source I think, so I
> > > used (|spad|). Again following an advice. And, again, with Clozure CL,
> > > contrary to SBCL, that leads to strange things after returning to the
> > > interpreter and executing foreign code (principally bad addresses and
> > > therefore segfault).
> >
> > The function to start FriCAS is 'fricas_restart'.  'fricas_restart'
> > is doing some initialization which may be unnecessary when executed
> > second time.  OTOH re-doing initalization should be harmless and
> > some probably is needed.
>
> I see that, and in fact only propog CL use (|spad|) directly in other
> piece(s ?) of code. Using it is handy though, not everything is
> reinitialized.
>
> > Note that ')fin' is really unsuppored by FriCAS, basically
> > it is "pray that Lisp will do what you want".  In particular IIRC
> > it simply quits FriCAS when using ECL and I think it never fully
> > worked with Clozure CL.
> >
> > > So maybe I first need to know a better CL command, to return to the
> > > interpreter? But also, of course, to know why the ccl:terminate is not
> > > called in the interpreter. R. Munyer in the CCL mailing list found a
> > > way, see the attached transcript file, but he uses ')fin' and no
> > > Clozure CL FFI. I tried to use different (eva-when) to define the
> > > ccl:terminate method without success since the code is build/compiled
> > > (src/lisp).
> >
> > I think that ')fin' is irrelevant, you should get the same effect
> > using ')lisp' or if that is inconvenient you can put code in the
> > file and use ')read'.  The main difference is that FriCAS needs
> > specific settings of several global variables and FriCAS catches
> > errors (there are several use of 'CATCH' and there is 'handler-bind').
> > This _should_ make no difference.  What _may_ matter is order of
> > initialization.  In particular FriCAS performs some initializations
> > before dumping image.  But several thing do not survive to
> > restarted image, so need to be done later, after start of new image.
>
> I guessed after your email that the behavior of ')fin' is somewhat undefined.
>
> So now, my solution to my problem. A proposed diff is attached, it
> uniformizes/simplifies the Clozure CL boot I think.
>
> Looking at the attached transcript in my previous email I was
> surprised to see that the banner was displayed at that time, and
> experimenting more with the pure CL interpreter after ')fin' I first
> saw that calling Julia was not possible. When you embed Julia using
> libjulia, Julia does not support multithreaded code from the host
> process, I encountered this with SBCL, and it leads to segfault, bad
> stack etc. Only the thread that initialized Julia is able to use
> commands using the C interface. Experimenting some interruptions and
> backtraces I saw a thread started after ')fin'. Apparently the "main"
> process (not exactly in fact, the 

Re: [fricas-devel] )fin, restart, (|spad|) with Clozure CL based FriCAS

2024-05-22 Thread Grégory Vanuxem
Hello Waldek, hello all,

First, thanks for your response, it was very instructive it leads me
to solve this long outstanding issue with my FriCAS copy.

Le mar. 21 mai 2024 à 20:32, Waldek Hebisch  a écrit :
>
> On Tue, May 21, 2024 at 01:57:45PM +0200, Grégory Vanuxem wrote:
> > Hello,
> >
> > I try to understand why a Clozure CL 'terminate' method is not called
> > from the interpreter. I have a CL class jlref, when a jlref object is
> > no longer referenced the CL garbage collector reclaims it. It is
> > possible in different CL implementations to add a 'hook' to do some
> > job at that time. Personally I then unreference the real Julia object
> > in such a way it can be GC reclaimed in Julia, jlref is just a class
> > that holds information about it.
> >
> > For SBCL I have no problem, but 'ccl:terminate' which should be
> > automatically called is never called. But, and this is the main point,
> > following an advice in a Clozure mailing list, I tried to use/define
> > this method directly at execution time using ')fin', and surprisingly,
> > using ')fin' automatically triggers 'terminate' on every objects that
> > are/(were ?) reclaimed.
> >
> > So my question, what does ')fin' do? And do you happen to know where I
> > need to look in the FriCAS source code to better understand its
> > effect?
>
> AFAIK ')fin' is doing "nothing", is just returns back to whatever Lisp
> was doing befor calling FriCAS.  To understand relation with Lisp,
> look at 'src/lisp/fricas-lisp.lisp', in particular 'save-core-restart'.

Yes!!! This is what helped me. I looked more carefully at this function and..

>
> > Furthermore, in src/interp/int-top.boot, the documentation says that
> > to return to the interpreterafer after ')fin'  '(restart)' should be
> > used. In fact, before some change in the FriCAS source I think, so I
> > used (|spad|). Again following an advice. And, again, with Clozure CL,
> > contrary to SBCL, that leads to strange things after returning to the
> > interpreter and executing foreign code (principally bad addresses and
> > therefore segfault).
>
> The function to start FriCAS is 'fricas_restart'.  'fricas_restart'
> is doing some initialization which may be unnecessary when executed
> second time.  OTOH re-doing initalization should be harmless and
> some probably is needed.

I see that, and in fact only propog CL use (|spad|) directly in other
piece(s ?) of code. Using it is handy though, not everything is
reinitialized.

> Note that ')fin' is really unsuppored by FriCAS, basically
> it is "pray that Lisp will do what you want".  In particular IIRC
> it simply quits FriCAS when using ECL and I think it never fully
> worked with Clozure CL.
>
> > So maybe I first need to know a better CL command, to return to the
> > interpreter? But also, of course, to know why the ccl:terminate is not
> > called in the interpreter. R. Munyer in the CCL mailing list found a
> > way, see the attached transcript file, but he uses ')fin' and no
> > Clozure CL FFI. I tried to use different (eva-when) to define the
> > ccl:terminate method without success since the code is build/compiled
> > (src/lisp).
>
> I think that ')fin' is irrelevant, you should get the same effect
> using ')lisp' or if that is inconvenient you can put code in the
> file and use ')read'.  The main difference is that FriCAS needs
> specific settings of several global variables and FriCAS catches
> errors (there are several use of 'CATCH' and there is 'handler-bind').
> This _should_ make no difference.  What _may_ matter is order of
> initialization.  In particular FriCAS performs some initializations
> before dumping image.  But several thing do not survive to
> restarted image, so need to be done later, after start of new image.

I guessed after your email that the behavior of ')fin' is somewhat undefined.

So now, my solution to my problem. A proposed diff is attached, it
uniformizes/simplifies the Clozure CL boot I think.

Looking at the attached transcript in my previous email I was
surprised to see that the banner was displayed at that time, and
experimenting more with the pure CL interpreter after ')fin' I first
saw that calling Julia was not possible. When you embed Julia using
libjulia, Julia does not support multithreaded code from the host
process, I encountered this with SBCL, and it leads to segfault, bad
stack etc. Only the thread that initialized Julia is able to use
commands using the C interface. Experimenting some interruptions and
backtraces I saw a thread started after ')fin'. Apparently the "main"
process (not exactly in fact, the actual boot process of FriCAS bypass
the CCL read-eval-print loop main thread) was at that time in a idle
state or not started or sleeping, I don't really know, and the
ccl::terminate method is then called on reclaimed CL objects. It's
another thread in fact. FriCAS on CCL is then a multithreaded app :-)

Diggering more in 'save-core-restart' I saw that only FriCAS on top of
CCL is using a 

Re: [fricas-devel] )fin, restart, (|spad|) with Clozure CL based FriCAS

2024-05-21 Thread Waldek Hebisch
On Tue, May 21, 2024 at 01:57:45PM +0200, Grégory Vanuxem wrote:
> Hello,
> 
> I try to understand why a Clozure CL 'terminate' method is not called
> from the interpreter. I have a CL class jlref, when a jlref object is
> no longer referenced the CL garbage collector reclaims it. It is
> possible in different CL implementations to add a 'hook' to do some
> job at that time. Personally I then unreference the real Julia object
> in such a way it can be GC reclaimed in Julia, jlref is just a class
> that holds information about it.
> 
> For SBCL I have no problem, but 'ccl:terminate' which should be
> automatically called is never called. But, and this is the main point,
> following an advice in a Clozure mailing list, I tried to use/define
> this method directly at execution time using ')fin', and surprisingly,
> using ')fin' automatically triggers 'terminate' on every objects that
> are/(were ?) reclaimed.
> 
> So my question, what does ')fin' do? And do you happen to know where I
> need to look in the FriCAS source code to better understand its
> effect?

AFAIK ')fin' is doing "nothing", is just returns back to whatever Lisp
was doing befor calling FriCAS.  To understand relation with Lisp,
look at 'src/lisp/fricas-lisp.lisp', in particular 'save-core-restart'.


> Furthermore, in src/interp/int-top.boot, the documentation says that
> to return to the interpreterafer after ')fin'  '(restart)' should be
> used. In fact, before some change in the FriCAS source I think, so I
> used (|spad|). Again following an advice. And, again, with Clozure CL,
> contrary to SBCL, that leads to strange things after returning to the
> interpreter and executing foreign code (principally bad addresses and
> therefore segfault).

The function to start FriCAS is 'fricas_restart'.  'fricas_restart'
is doing some initialization which may be unnecessary when executed
second time.  OTOH re-doing initalization should be harmless and
some probably is needed.

Note that ')fin' is really unsuppored by FriCAS, basically
it is "pray that Lisp will do what you want".  In particular IIRC
it simply quits FriCAS when using ECL and I think it never fully
worked with Clozure CL.

> So maybe I first need to know a better CL command, to return to the
> interpreter? But also, of course, to know why the ccl:terminate is not
> called in the interpreter. R. Munyer in the CCL mailing list found a
> way, see the attached transcript file, but he uses ')fin' and no
> Clozure CL FFI. I tried to use different (eva-when) to define the
> ccl:terminate method without success since the code is build/compiled
> (src/lisp).

I think that ')fin' is irrelevant, you should get the same effect
using ')lisp' or if that is inconvenient you can put code in the
file and use ')read'.  The main difference is that FriCAS needs
specific settings of several global variables and FriCAS catches
errors (there are several use of 'CATCH' and there is 'handler-bind').
This _should_ make no difference.  What _may_ matter is order of
initialization.  In particular FriCAS performs some initializations
before dumping image.  But several thing do not survive to
restarted image, so need to be done later, after start of new image.

> To resume, since I suspect that different thread issues may also
> occur, I would like to better understand the side effects of ')fin'
> and how to cleanly return to the interpreter after  'fin' session with
> Clozure CL.

If there are any side effects, they are purely due to Clozure CL.

-- 
  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 on the web visit 
https://groups.google.com/d/msgid/fricas-devel/ZkzoyJ93yR2Jhd1j%40fricas.org.


[fricas-devel] )fin, restart, (|spad|) with Clozure CL based FriCAS

2024-05-21 Thread Grégory Vanuxem
Hello,

I try to understand why a Clozure CL 'terminate' method is not called
from the interpreter. I have a CL class jlref, when a jlref object is
no longer referenced the CL garbage collector reclaims it. It is
possible in different CL implementations to add a 'hook' to do some
job at that time. Personally I then unreference the real Julia object
in such a way it can be GC reclaimed in Julia, jlref is just a class
that holds information about it.

For SBCL I have no problem, but 'ccl:terminate' which should be
automatically called is never called. But, and this is the main point,
following an advice in a Clozure mailing list, I tried to use/define
this method directly at execution time using ')fin', and surprisingly,
using ')fin' automatically triggers 'terminate' on every objects that
are/(were ?) reclaimed.

So my question, what does ')fin' do? And do you happen to know where I
need to look in the FriCAS source code to better understand its
effect?

Furthermore, in src/interp/int-top.boot, the documentation says that
to return to the interpreterafer after ')fin'  '(restart)' should be
used. In fact, before some change in the FriCAS source I think, so I
used (|spad|). Again following an advice. And, again, with Clozure CL,
contrary to SBCL, that leads to strange things after returning to the
interpreter and executing foreign code (principally bad addresses and
therefore segfault).

So maybe I first need to know a better CL command, to return to the
interpreter? But also, of course, to know why the ccl:terminate is not
called in the interpreter. R. Munyer in the CCL mailing list found a
way, see the attached transcript file, but he uses ')fin' and no
Clozure CL FFI. I tried to use different (eva-when) to define the
ccl:terminate method without success since the code is build/compiled
(src/lisp).

To resume, since I suspect that different thread issues may also
occur, I would like to better understand the side effects of ')fin'
and how to cleanly return to the interpreter after  'fin' session with
Clozure CL.

Regards,

- Greg

ccl:terminate mechanism:
https://ccl.clozure.com/manual/chapter13.12.html#f_terminate-when-unreachable

-- 
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 on the web visit 
https://groups.google.com/d/msgid/fricas-devel/CAHnU2dbj90tgj6N3ijM7LyhC__-opXfBjX0PfBfYqJH85c-B0A%40mail.gmail.com.
$ fricas
Checking for foreign routines
FRICAS="/usr/local/lib/fricas/target/x86_64-linux-gnu"
spad-lib="/usr/local/lib/fricas/target/x86_64-linux-gnu/lib/libspad.so"
foreign routines found
openServer result 0
   FriCAS Computer Algebra System
  Version: FriCAS 1.3.10 built with openmcl 1.12.2
 Timestamp: Mon 20 May 2024 02:34:03 AM UTC
-
   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) -> )lisp *package*
Value = #
(1) -> )lisp (defclass garbage-counter () ((n :initarg :n)))
Value = #
(1) -> )fin
Clozure Common Lisp Version 1.12.2  LinuxX8664

For more information about CCL, please see http://ccl.clozure.com.

CCL is free software.  It is distributed under the terms of the Apache
Licence, Version 2.0.
? *package*
#
?
(defmethod initialize-instance :after
((x garbage-counter)  initargs)
  (declare (ignore initargs))
  (ccl:terminate-when-unreachable x))
#
?
(let ((s *terminal-io*))
  (defmethod ccl:terminate ((x garbage-counter))
(let ((n (1+ (slot-value x 'n
  (make-instance 'garbage-counter :n n)
  (format s "~: ~s~%" n)
  (finish-output s
#
? (|spad|)
(1) -> )lisp (progn (make-instance 'garbage-counter :n 0) t)
Value = T
(1) -> )lisp (ccl:gc)
Value = NIL
(1) ->
garbage-counter: 1
)lisp (ccl:gc)
Value = NIL
(1) ->
garbage-counter: 2