TeXmacs format contribution

75 views
Skip to first unread message

Alexander Solovets

unread,
Dec 26, 2010, 5:11:50 PM12/26/10
to fricas...@googlegroups.com
Hi!

Some month ago I had started to develop TeXmacs format output for
fricas. Now it's completed and I want to ask how should I prepare my
contribution (big patch, a series of patches, etc)?

Regards, Alexander.

Bill Page

unread,
Dec 29, 2010, 12:28:49 AM12/29/10
to fricas...@googlegroups.com
If it affects other parts of Fricas why not create a new branch for testing?

> --
> You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
> To post to this group, send email to fricas...@googlegroups.com.
> To unsubscribe from this group, send email to fricas-devel...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/fricas-devel?hl=en.
>
>

Ralf Hemmecke

unread,
Dec 29, 2010, 6:17:25 AM12/29/10
to fricas...@googlegroups.com
Good suggestion. And you don't really need write access to the fricas
svn repo. Just use github. It's easy to rebase to trunk from there.

See
https://sites.google.com/site/hemmecke/fricas-svn
for more details.

I think a series of carefully crafted patches (each handling one idea at
a time) would be nice. But since your work seemingly adds _one_ new
feature, namely the TeXmacs connection, it's probably also OK if it just
lives in _one_ big patch.

My suggestion would be, make it first public on github as described
above, then it is easier to say how to integrate your work.

Ralf

Alexander Solovets

unread,
Dec 31, 2010, 12:33:39 AM12/31/10
to fricas...@googlegroups.com

Ralf Hemmecke

unread,
Dec 31, 2010, 8:28:49 AM12/31/10
to fricas...@googlegroups.com
commit-4192a3a

Ralf Hemmecke

unread,
Dec 31, 2010, 12:37:54 PM12/31/10
to fricas...@googlegroups.com
On 12/31/2010 06:33 AM, Alexander Solovets wrote:
> https://github.com/mbait/fricas

Hi Alexander,

from what I see, you basically adapted the mathml output. And I quite
like your _series_ of patches. So I am more in favour of several patches
instead of one big patch.

I had a little problem during rebasing your patches onto trunk, but the
conflict in src/algebra/boo-dom1.input was easily resolvable.

No problem with compilation and ")set output texmacs on" seems to work
as proposed.

Aleander, maybe you should revise texmacs.spad.pamphlet a bit more in
order to mention your name in the "++ Author:" information, correcting
year etc. You should probably also try

build/scripts/document texmacs.spad.pamphlet

in order to check whether your file compiles correctly. At the moment it
doesn't.

I am in favour of supporting texmacs and volunteer to commit to trunk.
Waldek, do you give green light for the commit?

Ralf

PS: Alexander, I've installed TeXmacs 1.0.7.4 via apt-get in Maverick.
There appears an "Axiom" session type, but that doesn't work for me.
What would be the new texmacs-way to take advantage of your new feature
of fricas?

Alexander Solovets

unread,
Jan 2, 2011, 12:59:26 AM1/2/11
to fricas...@googlegroups.com
Hello, Ralf!

Thanks for the review! I am glad you appreciate that. However there
are still a few things to fix.

> Aleander, maybe you should revise texmacs.spad.pamphlet a bit more in order
> to mention your name in the "++ Author:" information, correcting year etc.
> You should probably also try
>
>  build/scripts/document texmacs.spad.pamphlet
>
> in order to check whether your file compiles correctly. At the moment it
> doesn't.

Sure, I'll make it. I just wanted to be sure that my changes are at
most acceptable.

> PS: Alexander, I've installed TeXmacs 1.0.7.4 via apt-get in Maverick. There
> appears an "Axiom" session type, but that doesn't work for me. What would be
> the new texmacs-way to take advantage of your new feature of fricas?

Yeah, that problem isn't solved yet. We have had a little discussion
about proper way of implementing that. The main idea of my work is let
TeXmacs to communicate with Fricas directly. So I guess to use here
some kind of command line switches that would enable TeXmacs format as
default at start. More common way is to add optional argument that
will run external script.

At the moment I use additional plugin(in attachment) in couple with .axiom.input

fricas-plugin.tgz

Ralf Hemmecke

unread,
Jan 2, 2011, 5:17:24 AM1/2/11
to fricas...@googlegroups.com
>> PS: Alexander, I've installed TeXmacs 1.0.7.4 via apt-get in Maverick. There
>> appears an "Axiom" session type, but that doesn't work for me. What would be
>> the new texmacs-way to take advantage of your new feature of fricas?
>
> Yeah, that problem isn't solved yet. We have had a little discussion
> about proper way of implementing that. The main idea of my work is let
> TeXmacs to communicate with Fricas directly. So I guess to use here
> some kind of command line switches that would enable TeXmacs format as
> default at start. More common way is to add optional argument that
> will run external script.

> At the moment I use additional plugin(in attachment) in couple with .axiom.input

Can you be a little more precise of how exactly I can use your
fricas-plugin. I'm not familiar with texmacs and thus have no idea of
how and where to install the plugin. Perhaps somewhere inside ~/.TeXmacs ?

Ralf

Alexander Solovets

unread,
Jan 2, 2011, 6:58:13 AM1/2/11
to fricas...@googlegroups.com
Exactly =) Just put "fricas" in .TeXmacs/plugins and two other scripts in "~".

Ralf Hemmecke

unread,
Jan 2, 2011, 12:42:23 PM1/2/11
to fricas...@googlegroups.com
On 01/02/2011 12:58 PM, Alexander Solovets wrote:
> Exactly =) Just put "fricas" in .TeXmacs/plugins and two other scripts in "~".

Oh, not quite...

I had to execute the commands appearing at the top of the fricas shell
script, namely

AXIOM='/home/hemmecke/software/lib/fricas/target/i686-pc-linux'
export AXIOM
PATH=${AXIOM}/bin:${PATH}
export PATH

otherwise the FriCAS menu item doesn't appear in the session menu of
texmacs.

But you cannot require someone to set the AXIOM variable manually. So
you better change fricas/progs/init-fricas.scm to something like this:

(plugin-configure fricas
(:require (url-exists-in-path? "fricas"))
;(:initialize (fricas-initialize))
(:launch "fricas -nosman")
(:session "FriCAS"))

Calling "fricas -nosman" has the same effect as calling AXIOMsys with
the AXIOM and PATH env variables set appropriately.

Second, you provided .axiom.input and texmacs.input. The standard init
script for Fricas is ~/.fricas.input . So I've now created this file
with content:

)set output algebra off
)set output texmacs on
)lisp (setf |$ioHook| (lambda (x &optional args) (cond ((eq x
'|startPrompt|) (princ (concat (code-char 2) "prompt#") )) ((eq x
'|endOfTeXmacsOutput|) (princ (concat (code-char 5) (code-char 10))))
((eq x '|startTeXmacsOutput|) (princ (code-char 2))) ((eq x
'|startKeyedMsg|) (princ (concat (code-char 2) "verbatim:"))) ((eq x
'|endOfKeyedMsg|) (princ (code-char 5))) ((eq x '|endOfPrompt|) (princ
(code-char 5) )) )))
)lisp (setf |$inputPromptType| '|plain|)

With the above modifications I can report to have a FriCAS running
inside TeXmacs. Nice!

There are a few issues remaining, though.
1) Since you don't start the sman process, there is no graphics
and no hyperdoc.
2) Globally changing ~/.fricas.input is not a good idea in my opinion.

As for 1) I have no idea why starting "fricas" instead of "fricas
-nosman" does not work. Maybe, because sman is starting AXIOMsys and
texmacs simply does not realize that sman is not giving back control.

For 2), I wish FriCAS had a way to run scripts specified on the command
line, i.e. something like "fricas -read texmacs.input".

hemmecke

unread,
Jan 2, 2011, 5:27:45 PM1/2/11
to FriCAS - computer algebra system
> There are a few issues remaining, though.
...
> 2) Globally changing ~/.fricas.input is not a good idea in my opinion.
...
> For 2), I wish FriCAS had a way to run scripts specified on the command
> line, i.e. something like "fricas -read texmacs.input".

I still would like something like a -read option or even something
like

fricas -c "fricas commands here"

but concerning .fricas.input file, one could use pipes. Just something
like

(plugin-configure fricas
(:require (url-exists-in-path? "fricas"))
(:launch "cat ~/.TeXmacs/plugins/fricas/.fricas.input - | fricas -
nosman")
(:session "FriCAS"))

as ~/.TeXmacs/plugins/fricas/progs/init-fricas.scm .
I have no file ~/.fricas.input. This file lives inside the
~/.TeXmacs/plugins/fricas/ subdir.

The only problem I can see at the moment is that typing ")quit" inside
a texmacs fricas session will hang the fricas session, since the
fricas
process is terminated but the cat command (and therefore texmacs)
doesn't recognise that fricas is now dead and so will wait for further
input.
It shows "Busy..." and the session cannot be restarted.

That looks like a corner case, but I'd rather like a proper solution.

Ralf

Waldek Hebisch

unread,
Jan 3, 2011, 10:29:57 AM1/3/11
to fricas...@googlegroups.com
Ralf Hemmecke wrote:
>
> On 12/31/2010 06:33 AM, Alexander Solovets wrote:
> > https://github.com/mbait/fricas
>
> Hi Alexander,
>
> from what I see, you basically adapted the mathml output. And I quite
> like your _series_ of patches. So I am more in favour of several patches
> instead of one big patch.
>
> I had a little problem during rebasing your patches onto trunk, but the
> conflict in src/algebra/boo-dom1.input was easily resolvable.
>
> No problem with compilation and ")set output texmacs on" seems to work
> as proposed.
>
> Aleander, maybe you should revise texmacs.spad.pamphlet a bit more in
> order to mention your name in the "++ Author:" information, correcting
> year etc. You should probably also try
>
> build/scripts/document texmacs.spad.pamphlet
>
> in order to check whether your file compiles correctly. At the moment it
> doesn't.
>
> I am in favour of supporting texmacs and volunteer to commit to trunk.
> Waldek, do you give green light for the commit?
>

I think it make sense to wait few days to resolve problem that
are likely to show up. Today I am in a hurry but tomorrow I will
take look at the code.

--
Waldek Hebisch
heb...@math.uni.wroc.pl

Alexander Solovets

unread,
Jan 4, 2011, 2:40:51 AM1/4/11
to fricas...@googlegroups.com
>> 2) Globally changing ~/.fricas.input is not a good idea in my opinion.
>> For 2), I wish FriCAS had a way to run scripts specified on the command
>> line, i.e. something like "fricas -read texmacs.input".

I think either script or command sequence is fine, but it seems that
AXIOMsys doesn't receive command line argument at all. If there are
any they are processed either by "axiom" script or by "sman".
Therefore I need some help in this question.

Ralf Hemmecke

unread,
Jan 4, 2011, 5:29:19 AM1/4/11
to fricas...@googlegroups.com

Oh, maybe it is easier than I thought. The file .fricas.input is not
only tried from the path $HOME, but first from the current directory.
In other words writing something like ...

(plugin-configure fricas
(:require (url-exists-in-path? "fricas"))

(:launch "cd ~/.TeXmacs/plugins/fricas; fricas -nosman")
(:session "FriCAS"))

in ~/.TeXmacs/plugins/fricas/progs/init-fricas.scm tries to read
~/.TeXmacs/plugins/fricas/.fricas.input.

Ralf

Waldek Hebisch

unread,
Jan 4, 2011, 4:15:49 PM1/4/11
to fricas...@googlegroups.com
First comment: I see that TexmacsFormat (like MathMLFormat) uses
'sayTeX'. This is wrong, TexmacsFormat should use its own
function, logically it should be called 'sayTexmacs'. Namely,
'sayTeX' sends its output to $texOutputStream. Texmacs output
should go to a separate stream (so that it is possible to send
TeX output to a file via Texmacs interface). In TexmacsFormat
the minmal change could be addition of line:

sayTeX ==> sayTexmacs

but global renaming may be good for readability. In particular,
the '$Lisp' part is better hidden in a macro.

Of course, we need to add code to create appropriate stream
and define the 'sayTexmacs' function, I will do this.

BTW: I wonder if I am looking at correct file. Github shows
me date 2010-11-04 and I still see a lot of MathML stuff
in the file.

BTW2: IIUC texmacs.spad.pamphlet compared to MathML version
is changed so much that it is better to treat it as new file.
But for other files I would like to see just the diff as
a single patch, so that I can see all changes and only the
changes. How can I get such diff?

--
Waldek Hebisch
heb...@math.uni.wroc.pl

Ralf Hemmecke

unread,
Jan 4, 2011, 5:05:55 PM1/4/11
to fricas...@googlegroups.com
> BTW: I wonder if I am looking at correct file. Github shows
> me date 2010-11-04 and I still see a lot of MathML stuff
> in the file.

This is Alexander's last commit
https://github.com/mbait/fricas/commit/bec51d296ffb9872713600067536d3be3103c9ae
and it indeed has a commit date 05-Nov-2010.

Judging from where he branched, I guess he used git even before I told
him around Christmas.

https://github.com/mbait/fricas/network

> BTW2: IIUC texmacs.spad.pamphlet compared to MathML version
> is changed so much that it is better to treat it as new file.
> But for other files I would like to see just the diff as
> a single patch, so that I can see all changes and only the
> changes. How can I get such diff?

Use the above (network) URL. You can click on any of these bullets and
see the respective commit. Also at the first above URL you find a
"parent" link and thus can go back in time.

Easier, of course, is if you do everything locally.
There are two ways to get the patches to your computer.
Preferred way should be (1).

(1) You follow https://sites.google.com/site/hemmecke/fricas-svn to
create your own clone and then fetch the changes of Alexander to your
local git repo as described here
https://sites.google.com/site/hemmecke/fricas-svn#collaborating-with-other-people

Create an account whebisch on github and follow the steps at
https://sites.google.com/site/hemmecke/fricas-svn#how-to-work-with
at least until (including) step 3. The rest you can do later.

I assume now, you have done

git clone g...@github.com:whebisch/fricas.git

Add Alexander's repository as a "remote" and fetch his branches.
cd fricas
git remote add alex git://github.com/mbait/fricas.git
git fetch alex
git checkout alex/texmacs-format

(2) Without creating a github account you directly get Alexander's
repository.
git clone git://github.com/mbait/fricas.git
cd fricas
git checkout texmacs-format

Now, the best way to look at the patches is with

gitk --all

And if you want patch files, try

git format-patch -k18

this will create the 18 commits that Alexander is proposing.

But actually it's easier (in case (1)) with
git rebase master
(Unfortunately, it is not totally trivial, since as I wrote some days
ago, it involves resolving a simple merge conflict.)

Hope that helps.

Ralf

Ralf Hemmecke

unread,
Jan 4, 2011, 5:15:13 PM1/4/11
to fricas...@googlegroups.com
> First comment: I see that TexmacsFormat (like MathMLFormat) uses
> 'sayTeX'. This is wrong, TexmacsFormat should use its own
> function, logically it should be called 'sayTexmacs'. Namely,
> 'sayTeX' sends its output to $texOutputStream. Texmacs output
> should go to a separate stream (so that it is possible to send
> TeX output to a file via Texmacs interface). In TexmacsFormat
> the minmal change could be addition of line:
>
> sayTeX ==> sayTexmacs
>
> but global renaming may be good for readability. In particular,
> the '$Lisp' part is better hidden in a macro.

Yes, there are still a few issues. But now we can look at them and improve.

> Of course, we need to add code to create appropriate stream
> and define the 'sayTexmacs' function, I will do this.

For me it looks as if Alexander has already considered it here.
https://github.com/mbait/fricas/commit/23fe66bb3f85905ca1189006bc2bc1cf54bb50d7#diff-5

> BTW2: IIUC texmacs.spad.pamphlet compared to MathML version
> is changed so much that it is better to treat it as new file.
> But for other files I would like to see just the diff as
> a single patch, so that I can see all changes and only the
> changes. How can I get such diff?

To me it looks pretty similar.

Ralf

Arthur Ralfs

unread,
Jan 5, 2011, 7:53:02 PM1/5/11
to fricas...@googlegroups.com
On 01/04/2011 01:15 PM, Waldek Hebisch wrote:
> First comment: I see that TexmacsFormat (like MathMLFormat) uses
> 'sayTeX'. This is wrong, TexmacsFormat should use its own
> function, logically it should be called 'sayTexmacs'.

Thanks for pointing this out.

I've replaced all occurrences of 'sayTeX' with 'sayMml' in my posted
version mathml.spad.pamphlet. To make it work requires also executing

)lisp (defun |sayMml| (x) (if (null x) nil (sayBrightly1 x
|$mathmlOutputStream|)))

Arthur

Alexander Solovets

unread,
Jan 7, 2011, 5:11:31 AM1/7/11
to fricas...@googlegroups.com
I've found the most neutral solution. TeXmacs plugin interface
supports middleware, which can be any executables =) So I can add such
a program. All that will remain is to send ")set output texmacs on"
and other commands at initialization.

Ralf Hemmecke

unread,
Jan 7, 2011, 5:26:35 AM1/7/11
to fricas...@googlegroups.com
On 01/07/2011 11:11 AM, Alexander Solovets wrote:
> I've found the most neutral solution. TeXmacs plugin interface
> supports middleware, which can be any executables =) So I can add such
> a program. All that will remain is to send ")set output texmacs on"
> and other commands at initialization.

>> (plugin-configure fricas


>> (:require (url-exists-in-path? "fricas"))
>> (:launch "cd ~/.TeXmacs/plugins/fricas; fricas -nosman")
>> (:session "FriCAS"))

If you mean that you can call any program in the ":launch" part, then
this is not the problem. The problem is that your "middleware" will have
to kill all respective processes if the user types ")quit" inside
fricas. But if you know how to do that, then maybe you can even start
"fricas" instead of "fricas -nosman".

Ralf

Alexander Solovets

unread,
Jan 7, 2011, 6:02:26 AM1/7/11
to fricas...@googlegroups.com
Just take a look at the current axiom plugin implementation. If you
have TeXmacs sources there will be C program that reads fricas output,
processes and sends result to texmacs.

Andrey G. Grozin

unread,
Jan 7, 2011, 6:40:25 AM1/7/11
to fricas...@googlegroups.com
On Fri, 7 Jan 2011, Alexander Solovets wrote:
> I've found the most neutral solution. TeXmacs plugin interface
> supports middleware, which can be any executables =) So I can add such
> a program. All that will remain is to send ")set output texmacs on"
> and other commands at initialization.
Having a separate process exclusively for sending a few lines to fricas is
an overkill, I think. It would be much better to have a method to read an
extra file before starting an interactive session. For example, just after
.fricas.input. Is it too difficult to find the place in the sources which
reads .fricas.input, and to duplicate it, with the file name taken from
the command line?

Andrey

Ralf Hemmecke

unread,
Jan 7, 2011, 7:00:14 AM1/7/11
to fricas...@googlegroups.com
http://groups.google.com/group/fricas-devel/msg/fb70de61dd951c92
I've already described how to work around.

The problem is more that fricas starts several processes (hyperdoc,
graphics) itself. Usually that all is managed by sman. If one calles
"fricas -sman", one either has no hyperdoc or starts it from the fricas
input via ")hd". But such a process is then not killed if you quit
fricas. That's at least what I experienced.

Reading of the .fricas.input is started from here.
https://github.com/hemmecke/fricas-svn/blob/master/src/interp/i-toplev.boot#L63
It's in the functions readSpadProfileIfThere. I have, however no idea,
how to pass command line arguments to AXIOMsys.

Ralf

Alexander Solovets

unread,
Jan 7, 2011, 7:01:28 AM1/7/11
to fricas...@googlegroups.com
It is not easy for me, because AXIOMsys doesn't take command line
arguments and I don't know how to access them =( As for the overkill I
am at the same point here. Therefore I've asked texmacs developers
about the way to send some data to opened session at startup.

Andrey G. Grozin

unread,
Jan 7, 2011, 8:04:58 AM1/7/11
to fricas...@googlegroups.com
On Fri, 7 Jan 2011, Ralf Hemmecke wrote:
> Reading of the .fricas.input is started from here.
> https://github.com/hemmecke/fricas-svn/blob/master/src/interp/i-toplev.boot#L63
> It's in the functions readSpadProfileIfThere. I have, however no idea, how
> to pass command line arguments to AXIOMsys.
The fricas script can do something like

EXTRAFILE=<something>
export EXTRAFILE

Each supported lisp has a method to get values of environment variables.
The only drawback is that this method is different in each lisp :-( So, we
can abstract details like

(defun (getenv name)
#+gcl (...)
#+ecl (...)
#+sbcl (...)
...
)

and then just call getenv from i-toplev.boot.

Andrey

Waldek Hebisch

unread,
Jan 7, 2011, 9:19:28 AM1/7/11
to fricas...@googlegroups.com

We already have getEnv function. Each supported Lisp allows getting
command line arguments and I have code to get them. The problem
is that some Lisps will interpret arguments before we can do
anything. So we need a protocol to make sure that arguments
intended for AXIOMsys do not have some unexpected effect on
host Lisp. Unfortunatly, this means analysing argument handling code
in each Lisp and it takes time.


--
Waldek Hebisch
heb...@math.uni.wroc.pl

Ralf Hemmecke

unread,
Jan 7, 2011, 9:27:20 AM1/7/11
to fricas...@googlegroups.com
> So we need a protocol to make sure that arguments
> intended for AXIOMsys do not have some unexpected effect on
> host Lisp. Unfortunatly, this means analysing argument handling code
> in each Lisp and it takes time.

Isn't that easy? Each command line that is intended for AXIOMsys is
called something like --axiomsys-initfile --axiomsys-lisp-expr. I am
sure no LISP is looking for an option starting with --axiomsys-*.

Anyway, since we start AXIOMsys always via the fricas script, that
script could just put the command like arguments into an environment
variable (FRICASARGS, say) and pass it over to AXIOMsys as Andrey
suggested. Then picking out the arguments and react to them
appropriately should be easy.

Ralf

Waldek Hebisch

unread,
Jan 7, 2011, 10:31:02 AM1/7/11
to fricas...@googlegroups.com
>
> > So we need a protocol to make sure that arguments
> > intended for AXIOMsys do not have some unexpected effect on
> > host Lisp. Unfortunatly, this means analysing argument handling code
> > in each Lisp and it takes time.
>
> Isn't that easy? Each command line that is intended for AXIOMsys is
> called something like --axiomsys-initfile --axiomsys-lisp-expr. I am
> sure no LISP is looking for an option starting with --axiomsys-*.
>

Not that easy:

bash-3.2$ clisp --axiomsys-initfile
GNU CLISP: invalid argument: '--axiomsys-initfile'
GNU CLISP: use '-h' for help


With clisp '-- --axiomsys-initfile' works, but I need to make
sure that there are no unexpected interactions with other Lisps.



> Anyway, since we start AXIOMsys always via the fricas script, that
> script could just put the command like arguments into an environment
> variable (FRICASARGS, say) and pass it over to AXIOMsys as Andrey
> suggested. Then picking out the arguments and react to them
> appropriately should be easy.

Yes, we can pass arguments via environment. I am looking at
command line in case somebody wants to start AXIOMsys directly
and does not want to mess with environment. To say the truth
since passing arguments via environment works fine I cosidered
command line of very low priority. But apparently command
line is first thing that somebody new to FriCAS wants to
use so it would be good to have something working.

--
Waldek Hebisch
heb...@math.uni.wroc.pl

Ralf Hemmecke

unread,
Jan 7, 2011, 10:54:14 AM1/7/11
to fricas...@googlegroups.com
> But apparently command line is first thing that somebody new to
> FriCAS wants to use so it would be good to have something working.

Not only that. I think sooner or later the necessity of X for graphics
should be dropped. I don't know how much the work of Martin Baker helps
here, but I heard rumours that X will be replaced by something else in
Ubuntu 11.04. (Although there will probably still be a way to run X
programs.)

I'd somehow find it better if graphics worked through the browser and
the same for hyperdoc.

That's probably lots of work, but there seem to be people around that
can actively help here.

Ralf

Ralf Hemmecke

unread,
Jan 7, 2011, 10:59:04 AM1/7/11
to fricas...@googlegroups.com
> I am looking at command line in case somebody wants to start AXIOMsys
> directly and does not want to mess with environment.

I must say, I am not in favour of starting AXIOMsys directly. AXIOMsys
requires the AXIOM environment variable to be set. Furthermore, in an
installation of FriCAS, it is not clear where exactly AXIOMsys is.

I'd rather think that the fricas script should be the _only_ way to talk
to fricas.

Ralf

Waldek Hebisch

unread,
Jan 7, 2011, 12:24:39 PM1/7/11
to fricas...@googlegroups.com

As a soft rule yes. But starting AXIOMsys directly is essential
for debugging, so I want to keep this easy. Also, shell script
are not allowed as interpreters for '#!' scripts, so there
may be requirement for true binary.

--
Waldek Hebisch
heb...@math.uni.wroc.pl

Andrey G. Grozin

unread,
Jan 9, 2011, 12:32:49 AM1/9/11
to fricas...@googlegroups.com
On Fri, 7 Jan 2011, Waldek Hebisch wrote:
> We already have getEnv function.
I think we can postpone design and implementation of a general mechanism
for passing command-line arguments. Now there is a pressing need, for
starting FriCAS from TeXmacs, to do something like that:

* TeXmacs calls
fricas -pre texmacs.input

* fricas script does
export FRICAS_PRE=texmacs.input

* i-toplev.boot calls getEnv("FRICAS_PRE") and, if this variable is set,
reads the file after .fricas.input but before starting the interactive
session

This mechanism is quite useful in itself, without TeXmacs. Any user can
have several files with initial settings for different kinds of sessions,
and using just one init file .fricas.input for temporary needs is
inconvenient because it's too permanent.

What do you think about this specific proposal? Of course, the names (-pre
and FRICAS_PRE) can be replaced by something better.

Andrey

Alexander Solovets

unread,
Jan 9, 2011, 2:47:16 AM1/9/11
to fricas...@googlegroups.com
I think a code alone would be better, because if someone wants to run
fricas in such a way, he'll have to care about coresponding working
dir value (or provide absolute file path).

Ralf Hemmecke

unread,
Jan 9, 2011, 6:40:20 AM1/9/11
to fricas...@googlegroups.com
I don't understand you guys. Of course, it would be good to have a
commandline way to start arbitrary code before the fricas input line
appears, but isn't

(:launch "cd ~/.TeXmacs/plugins/fricas; fricas -nosman")

enough to start FriCAS from TeXmacs in an appropriate way?
http://groups.google.com/group/fricas-devel/msg/34dca31edc6621a8

I suppose if all the parts are distributed with TeXmacs, the :launch
path will be something like "/usr/share/texmacs/TeXmacs/plugins/fricas".
Is that a problem?

Of course a fricas user might expect that the current working directory
does not change, i.e. he might expect that the fricas working directory
is the same as from where he started texmacs. But honestly, I wouldn't
trust that assumption if I start another program (fricas) from within a
program (texmacs). Furthermore, doing in fricas something that involves
interaction with the filesystem is probably not the primary use case.

And the advantage of my suggestion from above is that you can do it even
with current (unpatched versions of fricas) no need to wait. And it is
probably also not going away in any future version of fricas.

Ralf

Andrey G. Grozin

unread,
Jan 9, 2011, 7:05:36 AM1/9/11
to fricas...@googlegroups.com
On Sun, 9 Jan 2011, Ralf Hemmecke wrote:
> I don't understand you guys. Of course, it would be good to have a
> commandline way to start arbitrary code before the fricas input line
> appears, but isn't
>
> (:launch "cd ~/.TeXmacs/plugins/fricas; fricas -nosman")
>
> enough to start FriCAS from TeXmacs in an appropriate way?
The user will expect that his normal .fricas.input is loaded before the
session, but it is not.

> Of course a fricas user might expect that the current working directory
> does not change, i.e. he might expect that the fricas working directory is
> the same as from where he started texmacs.

Exactly!

> But honestly, I wouldn't trust
> that assumption if I start another program (fricas) from within a program
> (texmacs).

Only if the implementation is broken.

> Furthermore, doing in fricas something that involves interaction
> with the filesystem is probably not the primary use case.

I think it is. A user edits some file in emacs, and than from fricas
(inside texmacs) says

)read myfile.input

Isn't this a typical use case?

Andrey

Ralf Hemmecke

unread,
Jan 9, 2011, 7:42:30 AM1/9/11
to fricas...@googlegroups.com
> The user will expect that his normal .fricas.input is loaded before the
> session, but it is not.

If you think that this is a problem, then what about adding

)cd
)read ".fricas.input"

at the end of texmacs.input?

>> Of course a fricas user might expect that the current working
>> directory does not change, i.e. he might expect that the fricas
>> working directory is the same as from where he started texmacs.
> Exactly!

>> But honestly, I wouldn't trust that assumption if I start another
>> program (fricas) from within a program (texmacs).
> Only if the implementation is broken.

Well, of course, you are right. Currently, it's not perfect. I am just
suggesting something that you can use *now*.

>> Furthermore, doing in fricas something that involves interaction with
>> the filesystem is probably not the primary use case.
> I think it is. A user edits some file in emacs, and than from fricas
> (inside texmacs) says
>
> )read myfile.input
>
> Isn't this a typical use case?

Yep. But as above, I wouldn't necessarily trust that the current
directory is the same as the one I started texmacs from. Let's say, I
started Maxima inside TeXmacs and (I am now assuming that Maxima can
change the current directory---don't know if that is true) change the
current directory to something else and then start FriCAS. Is there a
clear statement in the TeXmacs documentation that a former "cd" does not
influence other sessions?

Ralf

Waldek Hebisch

unread,
Jan 10, 2011, 1:52:34 PM1/10/11
to fricas...@googlegroups.com

Yes, that is useful. I think that 'pre' is too unspecific, what
about 'FRICAS_PREINIT' and '--preinit'? Also I similar way we can
add 'FRICAS_EVAL_LISP' and '--eval-lisp' to evaluate arbitrary
piece of Lisp code. And maybe 'FRICAS_EVAL' and '--eval' for
interpreter input. The execution order would be Lisp, then
preinit then eval.

--
Waldek Hebisch
heb...@math.uni.wroc.pl

Martin Rubey

unread,
Jan 10, 2011, 2:01:21 PM1/10/11
to fricas...@googlegroups.com
Waldek Hebisch <heb...@math.uni.wroc.pl> writes:

> Yes, that is useful. I think that 'pre' is too unspecific, what
> about 'FRICAS_PREINIT' and '--preinit'? Also I similar way we can
> add 'FRICAS_EVAL_LISP' and '--eval-lisp' to evaluate arbitrary
> piece of Lisp code.

This would help fricas.el quite a bit, actually, if it takes lisp code
on the command line!

However, I think it's not so useful to have an extra variable for
executing a file containing lisp code, since we could put it into an
ordinary input file with )lisp prepended.

Martin

Waldek Hebisch

unread,
Jan 10, 2011, 2:10:25 PM1/10/11
to fricas...@googlegroups.com

My understanding is that preinit is FriCAS file, like .fricas.input,
only with arbitrary name and executed earlier. Of course given
eval one can use ')read somefile.input' as an argument, but
it is more convenient to have both eval and file input.

--
Waldek Hebisch
heb...@math.uni.wroc.pl

Alexander Solovets

unread,
Jan 10, 2011, 4:50:42 PM1/10/11
to fricas...@googlegroups.com
By the way, I've updated my branch at github.

Andrey G. Grozin

unread,
Jan 11, 2011, 10:10:34 AM1/11/11
to fricas...@googlegroups.com
On Mon, 10 Jan 2011, Waldek Hebisch wrote:
> Yes, that is useful. I think that 'pre' is too unspecific, what
> about 'FRICAS_PREINIT' and '--preinit'? Also I similar way we can
> add 'FRICAS_EVAL_LISP' and '--eval-lisp' to evaluate arbitrary
> piece of Lisp code. And maybe 'FRICAS_EVAL' and '--eval' for
> interpreter input. The execution order would be Lisp, then
> preinit then eval.
It seems that --eval provides all the necessary functionality.
--eval ')lisp (lisp-code)'
--eval ')read something.input'
The file something.input can contain )lisp lines
All possibilities are covered.

This should be evaluated after .fricas.input but before an interactive
session, so that something.input could adjust things from .fricas.input
for the purpose of the present session (for example, a session from
TeXmacs or from emacs).

Andrey

Ralf Hemmecke

unread,
Jan 11, 2011, 10:26:08 AM1/11/11
to fricas...@googlegroups.com
I tend to agree with Andrey. Let's not make the interface too complicated.

Another point for not providing '--eval-lisp' is that we should not burn
it to much into the API that LISP is the underlying system (although it
will be for many years from now).
The option --eval ')lisp ...' is good enough if needed.

I would, however, allow multiple appearances of --eval so that one is
not forced to create a file if one just wants to execute two system
commands like ")cd" or ")read" etc.

Piled syntax in --eval would be a problem anyway and should be rewritten
into a non-piled form. I just don't know exactly whether current fricas
allows such a transformation for every possible source code. However,
Code in --eval should not be too long anyway.

Ralf

Waldek Hebisch

unread,
Jan 11, 2011, 12:52:14 PM1/11/11
to fricas...@googlegroups.com

The following (minimally tested) patch implements 'FRICAS_EVAL' in
AXIOMsys:


Index: src/interp/int-top.boot
===================================================================
--- src/interp/int-top.boot (revision 972)
+++ src/interp/int-top.boot (working copy)
@@ -93,11 +93,17 @@
$ncmMacro := NIL
$ncmPhase := NIL

+do_pre_eval() ==
+ ec := getEnv('"FRICAS__EVAL")
+ if ec then
+ CATCH('SPAD__READER, CATCH('top__level, parseAndEvalStr ec))
+
spad() ==
-- starts the interpreter, read in profiles, etc.
$PrintCompilerMessageIfTrue: local
setOutputAlgebra "%initialize%"
readSpadProfileIfThere()
+ do_pre_eval()
runspad()
'EndOfSpad

--
Waldek Hebisch
heb...@math.uni.wroc.pl

Alexander Solovets

unread,
Jan 11, 2011, 7:20:33 PM1/11/11
to fricas...@googlegroups.com
Here is the patch providing access to command-line arguments for
various Lisp-s(excluding poplog)
https://github.com/mbait/fricas/commit/488721e72aa495103cfc09475a0e4a706ef682ac

Alexander Solovets

unread,
Jan 11, 2011, 7:27:24 PM1/11/11
to fricas...@googlegroups.com
I'd wirte "--eval" argument extraction too if I knew how to process
lists in Boot in terms of Lisp (car and cdr). Also, please, notice
that the various Lisp dialects may return CL list both with 0th
argument and without it, so extraction function should take that into
account.

Alexander Solovets

unread,
Jan 13, 2011, 3:12:07 AM1/13/11
to fricas...@googlegroups.com
Finally, I've implemented full support of eval in CL arguments. You
may find it here http://github.com/mbait/fricas/tree/arg_values Just
build and try "axiom -eval ")set" -nosman". However, one issue still
remains - at least sbcl doesn't allow to pass a string with spaces, it
splits the string onto separate args. I don't know whether this is the
same for all Lisp-s.

On Wed, Jan 12, 2011 at 10:27 AM, Alexander Solovets

Waldek Hebisch

unread,
Jan 13, 2011, 5:46:41 AM1/13/11
to fricas...@googlegroups.com
>
> Finally, I've implemented full support of eval in CL arguments. You
> may find it here http://github.com/mbait/fricas/tree/arg_values Just
> build and try "axiom -eval ")set" -nosman". However, one issue still
> remains - at least sbcl doesn't allow to pass a string with spaces, it
> splits the string onto separate args. I don't know whether this is the
> same for all Lisp-s.
>

Trying on sbcl-based FriCAS:

bash-3.2$ ax-build26/target/x86_64-unknown-linux/bin/AXIOMsys --eval "foo bar"
Checking for foreign routines
AXIOM=NIL
spad-lib="/lib/libspad.so"
FriCAS (AXIOM fork) Computer Algebra System
Version: FriCAS 2010-09-22
Timestamp: Saturday December 4, 2010 at 11:53:04
-----------------------------------------------------------------------------
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 sb-ext::*posix-argv*

Value = ("ax-build26/target/x86_64-unknown-linux/bin/AXIOMsys" "--eval"
"foo bar")

I see string with space inside, so something else is probably
responsible for splitting arguments.

Actually, sbcl seem to be easy case, it seems to behave better than
its docomentation suggests. clisp and Closuse CL are problematic.

AFAICS if you give only one argument Closuse CL treats it as name of
image (this make no sense for executable, but is still done...).
Also Closuse CL treats many things which start with '-' and single
letter as its option. In particluar it wants to take over '--eval'.
One has to put '--' on command line to stop Closuse CL from
searching the rest of command line for its arguments.

clisp seem to be worse (it signals errors for anyting it does not
recognize), but also for clisp '--' in command line protects rest
of command line form beeing treated as an argument.

To the moment I did not check ecl and gcl, but I think that we need
'--' in command line. Then command line parsing code in AXIOMsys
should remove '--'.

> On Wed, Jan 12, 2011 at 10:27 AM, Alexander Solovets
> <asol...@gmail.com> wrote:
> > I'd wirte "--eval" argument extraction too if I knew how to process
> > lists in Boot in terms of Lisp (car and cdr). Also, please, notice
> > that the various Lisp dialects may return CL list both with 0th
> > argument and without it, so extraction function should take that into
> > account.
> >
> > On Wed, Jan 12, 2011 at 10:20 AM, Alexander Solovets
> > <asol...@gmail.com> wrote:
> >> Here is the patch providing access to command-line arguments for
> >> various Lisp-s(excluding poplog)

> >> https://github.com/mbait/fricas/commit/488721e72aa495103cfc09475a0e4a706=


> ef682ac
> >>
> >> On Wed, Jan 12, 2011 at 3:52 AM, Waldek Hebisch
> >> <heb...@math.uni.wroc.pl> wrote:
> >>> Andrey G. Grozin wrote:
> >>>>
> >>>> On Mon, 10 Jan 2011, Waldek Hebisch wrote:

> >>>> > Yes, that is useful. =A0I think that 'pre' is too unspecific, what
> >>>> > about 'FRICAS_PREINIT' and '--preinit'? =A0Also I similar way we can


> >>>> > add 'FRICAS_EVAL_LISP' and '--eval-lisp' to evaluate arbitrary

> >>>> > piece of Lisp code. =A0And maybe 'FRICAS_EVAL' and '--eval' for
> >>>> > interpreter input. =A0The execution order would be Lisp, then


> >>>> > preinit then eval.
> >>>> It seems that --eval provides all the necessary functionality.
> >>>> --eval ')lisp (lisp-code)'
> >>>> --eval ')read something.input'
> >>>> The file something.input can contain )lisp lines
> >>>> All possibilities are covered.
> >>>>
> >>>> This should be evaluated after .fricas.input but before an interactive

> >>>> session, so that something.input could adjust things from .fricas.inpu=


> t
> >>>> for the purpose of the present session (for example, a session from
> >>>> TeXmacs or from emacs).
> >>>>
> >>>
> >>> The following (minimally tested) patch implements 'FRICAS_EVAL' in
> >>> AXIOMsys:
> >>>
> >>>
> >>> Index: src/interp/int-top.boot

> >>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> >>> --- src/interp/int-top.boot =A0 =A0 (revision 972)
> >>> +++ src/interp/int-top.boot =A0 =A0 (working copy)
> >>> @@ -93,11 +93,17 @@
> >>> =A0$ncmMacro :=3D =A0 =A0 =A0 =A0 =A0 =A0NIL
> >>> =A0$ncmPhase :=3D =A0 =A0 =A0NIL
> >>>
> >>> +do_pre_eval() =3D=3D
> >>> + =A0 =A0ec :=3D getEnv('"FRICAS__EVAL")
> >>> + =A0 =A0if ec then
> >>> + =A0 =A0 =A0 =A0CATCH('SPAD__READER, CATCH('top__level, parseAndEvalSt=
> r ec))
> >>> +
> >>> =A0spad() =3D=3D
> >>> =A0 -- starts the interpreter, read in profiles, etc.
> >>> =A0 $PrintCompilerMessageIfTrue: local
> >>> =A0 setOutputAlgebra "%initialize%"
> >>> =A0 readSpadProfileIfThere()
> >>> + =A0do_pre_eval()
> >>> =A0 runspad()
> >>> =A0 'EndOfSpad
> >>>
> >>>
> >>> --
> >>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Waldek Hebis=
> ch
> >>> heb...@math.uni.wroc.pl
> >>>
> >>> --
> >>> You received this message because you are subscribed to the Google Grou=


> ps "FriCAS - computer algebra system" group.
> >>> To post to this group, send email to fricas...@googlegroups.com.

> >>> To unsubscribe from this group, send email to fricas-devel+unsubscribe@=
> googlegroups.com.
> >>> For more options, visit this group at http://groups.google.com/group/fr=
> icas-devel?hl=3Den.
> >>>
> >>>
> >>
> >
>
> --=20
> You received this message because you are subscribed to the Google Groups "=


> FriCAS - computer algebra system" group.
> To post to this group, send email to fricas...@googlegroups.com.

> To unsubscribe from this group, send email to fricas-devel+unsubscribe@goog=
> legroups.com.
> For more options, visit this group at http://groups.google.com/group/fricas=
> -devel?hl=3Den.
>
>


--
Waldek Hebisch
heb...@math.uni.wroc.pl

Ralf Hemmecke

unread,
Jan 13, 2011, 7:59:47 PM1/13/11
to fricas...@googlegroups.com
Alexander,

look at the first line after invocation. I am at
fd9397585e98e72b718d5ce811af0c4812af290f.

>fricas -eval "a+b" -nosman
/home/hemmecke/software/bin/fricas: line 130: [: a+b: binary operator
expected
... snip ...

(1) b + a
Type:
Polynomial(Integer)


You should probably put quotes arout the argument of -z. At least it
works for me then.

if [ "$1" = "-eval" ] ; then
shift
if [ -z "$*" ] ; then
echo "Parameter -eval must be provided with a value"
ciao
else
otheropts="-eval $1"
shift
fi
fi

In my case /bin/sh -> bash.

Ralf

Andrey G. Grozin

unread,
Jan 14, 2011, 1:15:22 AM1/14/11
to fricas...@googlegroups.com
On Tue, 11 Jan 2011, Waldek Hebisch wrote:
> The following (minimally tested) patch implements 'FRICAS_EVAL' in
> AXIOMsys:
>
>
> Index: src/interp/int-top.boot
> ===================================================================
> --- src/interp/int-top.boot (revision 972)
> +++ src/interp/int-top.boot (working copy)
> @@ -93,11 +93,17 @@
> $ncmMacro := NIL
> $ncmPhase := NIL
>
> +do_pre_eval() ==
> + ec := getEnv('"FRICAS__EVAL")
> + if ec then
> + CATCH('SPAD__READER, CATCH('top__level, parseAndEvalStr ec))
> +
> spad() ==
> -- starts the interpreter, read in profiles, etc.
> $PrintCompilerMessageIfTrue: local
> setOutputAlgebra "%initialize%"
> readSpadProfileIfThere()
> + do_pre_eval()
> runspad()
> 'EndOfSpad

This is a patch for the fricas script to use this mechanism. It allows one
to have several -eval parameters.

================================
--- /usr/bin/fricas 2010-11-24 06:40:41.000000000 +0600
+++ fricas 2011-01-14 19:55:11.000000000 +0600
@@ -20,2 +20,3 @@
# [-list] list workspaces only
+# [-eval command] evaluate command before the session
# [-grprog fname] use named program for Graphics
@@ -63,2 +64,3 @@
echo " [-list] list workspaces only"
+echo " [-eval command] evaluate command before the session"
#echo " [-grprog fname] use named program for Graphics"
@@ -138,2 +140,3 @@
otheropts=""
+FRICAS_EVAL=""

@@ -164,2 +167,14 @@
;;
+
+ -eval)
+ if [ "$2" = "" ] ; then needsubopt "$1" ; fi
+ if [ "$FRICAS_EVAL" = "" ] ; then
+ FRICAS_EVAL="$2"
+ else
+ FRICAS_EVAL="$FRICAS_EVAL
+$2"
+ fi
+ shift
+ ;;
+
-clef|-noclef|-gr|-nogr|-ht|-noht|-iw|-noiw|-ihere|-noihere|-nox|-nag|-nonag)
@@ -215,2 +230,6 @@
fi
+
+if [ "$FRICAS_EVAL" != "" ] ; then
+ export FRICAS_EVAL
+fi

================================

Andrey

Alexander Solovets

unread,
Jan 14, 2011, 7:58:12 PM1/14/11
to FriCAS - computer algebra system
Ok, now I've realized the problem sources.

1. otheropts="-eval $1" must be changed to otheropts="-eval \"$1\"".
That will be anough to make axiom -eval "some code" -nosman workable
even with having spaces string.
2. There is already mechanism in sman.c to pass parameters to AXIOMsys
avoiding them to be captured by Lisp interpreter. So the fix is to put
"-eval" after "--" in sman.c . I could do it myself, but I am on a
little vacation now where internet connection is very slow. So I'll be
able to fix that only at the next weekend.

Alexander Solovets

unread,
Jan 15, 2011, 8:39:44 PM1/15/11
to FriCAS - computer algebra system
I got access to broadband and committed required changes =) Now axiom -
eval "the code" should work.

Ralf Hemmecke

unread,
Jan 16, 2011, 5:11:31 PM1/16/11
to fricas...@googlegroups.com
Hi Alexander,

I've merged, your two branches
https://github.com/hemmecke/fricas/commits/arg-texmacs
and put

(:launch "fricas -eval ')read
/home/hemmecke/.TeXmacs/plugins/fricas/.fricas.input' -nosman")

into ~/.TeXmacs/plugins/fricas/progs/init-fricas.

It seems to work well. It's only that I see the content of my input file
in texmacs at the time I start the FriCAS session.

What I don't find perfect is that

fricas -eval 'some code' -nosman

will word, while

fricas -nsman -eval 'some code'

will not. Since -eval must be given before -nosman is evalutated.
But maybe that's not overly important to be fixed.

What would be more important is that fricas should accept several -eval
options. Otherwise I wouldn't have any clue how to put your init code

------
)set output algebra off
)set output texmacs on
)lisp (setf |$ioHook| (lambda (x &optional args) (cond ((eq x
'|startPrompt|) (princ (concat (code-char 2) "prompt#") )) ((eq x
'|endOfTeXmacsOutput|) (princ (concat (code-char 5) (code-char 10))))
((eq x '|startTeXmacsOutput|) (princ (code-char 2))) ((eq x
'|startKeyedMsg|) (princ (concat (code-char 2) "verbatim:"))) ((eq x
'|endOfKeyedMsg|) (princ (code-char 5))) ((eq x '|endOfPrompt|) (princ
(code-char 5) )) )))
)lisp (setf |$inputPromptType| '|plain|)
-------

directly into the :launch specification above, i.e. no separate
.fricas.init file.

Anyway, independent from texmacs, it would be good to be able to pass
several lines to fricas, i.e. several -eval commands.

Ralf

Alexander Solovets

unread,
Jan 16, 2011, 6:29:45 PM1/16/11
to FriCAS - computer algebra system
I thought there was some kind of statements separator like ';' =) So,
indeed multiply -eval will help. "-eval" after "-nosman" doesn't work
as expected because of the strict condition: if $* = "-nosman" -> run
AXIOMsys and I tried to make as few changes as possible. I think I'll
be able to fix that both with implementing multiply evals.

On Jan 17, 7:11 am, Ralf Hemmecke <r...@hemmecke.de> wrote:
> Hi Alexander,
>
> I've merged, your two brancheshttps://github.com/hemmecke/fricas/commits/arg-texmacs

Alexander Solovets

unread,
Jan 22, 2011, 6:40:57 AM1/22/11
to FriCAS - computer algebra system
I had to change "eval" parsing a bit. Now "-eval" works only in normal
mode, i.e. neither of "axiom -nosman -eval" or "axiom -eval -nosman"
works. However, there is "-texmacs" option that does all required to
start communication with TeXmacs. "AXIOMsys -eval" works also.
Multiply eval-s are supported.

Alexander Solovets

unread,
Jan 25, 2011, 2:43:40 PM1/25/11
to FriCAS - computer algebra system
Can anyone review my branches and commit if they are ok?

Ralf Hemmecke

unread,
Jan 25, 2011, 5:10:22 PM1/25/11
to fricas...@googlegroups.com
Hello Alexander,

I don't quite understand what you are indending with this patch:

https://github.com/mbait/fricas/commit/35ff9a71b838440fcf16eee5aee14d5726086a09#diff-1

It is inherently unsafe when the -eval's become longer than 1024 bytes.

http://en.wikipedia.org/wiki/Strcpy#Buffer_overflows

Same problem for augmented_ws_path. There it's even only 256 bytes long.

Also

https://github.com/mbait/fricas/commit/81359c8186a4de6a3ee2d0d745328372c9f97de9#diff-1

can cause a buffer overflow.

Ralf

Ralf Hemmecke

unread,
Jan 25, 2011, 5:10:34 PM1/25/11
to fricas...@googlegroups.com
What happens when I start with

fricas -nosman -eval

i.e. no argument to eval?

https://github.com/mbait/fricas/blob/40903dce8f4be5cced0c9ba8c7fb0d8c41bb5dc3/src/interp/int-top.boot#L96

evalInlineCode() ==
args := getCLArgs()
while #args > 0 repeat
arg := CAR args
if arg = '"-eval" then
CATCH('SPAD__READER,CATCH('top__level,parseAndEvalStr CADR(args)))
args := CDDR args
else
args := CDR args


Ralf

Alexander Solovets

unread,
Jan 26, 2011, 6:44:04 PM1/26/11
to fricas...@googlegroups.com
Ok, I've fixed all. eval_code and augmented_path are dynamically
allocated and reallocated if it requires. AXIOMsys will do nothing if
meet empty eval argument.

> --
> You received this message because you are subscribed to the Google Groups


> "FriCAS - computer algebra system" group.
> To post to this group, send email to fricas...@googlegroups.com.
> To unsubscribe from this group, send email to

> fricas-devel...@googlegroups.com.


> For more options, visit this group at

> http://groups.google.com/group/fricas-devel?hl=en.
>
>

Waldek Hebisch

unread,
Feb 6, 2011, 4:00:48 PM2/6/11
to fricas...@googlegroups.com
>
> Can anyone review my branches and commit if they are ok?
>

I would like to get your code commited as soon as possible. However
IIUC command line arguments are currently needed by Texmacs, so
that should go in first. I had some trouble with command line
arguments. First, ECL needs more complicated code for getting
arguments and also in Closure CL variable containing command line
arguments has different name (you used name of _function_).
Next, by default Closure CL would try to interpret whole
command line and would complain if there were extra items
(worse, it would try to perform '-eval') -- I had to disable
default argument processing in Closure CL. Similarely gcl
would try to perform '-eval', I had to disable that too.
And we need '--' as first argument to AXIOMsys (just after
name of executable) to avoid problems with Closure CL
and clisp (otherwise clisp would complain that it does not
understand the whole command line).

Also, it is not enough to just use '"' for quoting, for example
'--eval "String with space"' would fail. AFAICS the only safe
way is to use backslashes to quote all potentially unsafe
characters. And we need to do quoting twice, once in axiom/fricas
script, the second time in sman (currently sman passes command
line to the shell).

One more remark: replacing 'exec' by 'eval' means that the shell
executing axiom/fricas script would wait for sman/AXIOMsys to
finish which uses unnecessary extra process. It is better to
use 'eval exec' to avoid extra process.

I have now comitted argument handling with fixes as above (without
the texmacs hunk as this one really belongs to the texmacs branch).

--
Waldek Hebisch
heb...@math.uni.wroc.pl

Alexander Solovets

unread,
Feb 7, 2011, 7:04:34 PM2/7/11
to fricas...@googlegroups.com
Waldek, thanks for doing that! I've really messed up with quoting and
eval/exec. Also I tried to insert "--" before arguments, but
|getCLArgs| returned then empty list. That might be because I used
sbcl.

One more thing I want to ask you about: can you compose some tests
which would produce expressions with INDEFINTEGRAL, VCONCAT, TAG,
EQUATNUM, ZAG, SIGMA/SIGMA2/PI/PI2(in terms of binary operation),
RARROW. Also I completely do not know how to get partial
derivatives(differentials).

P.S. What kind of output should be "ZAG" turned into? I look at it in
"alegebra" mode and really saw a big zig-zag. But what is the kind of
math operation it?

Ralf Hemmecke

unread,
Feb 7, 2011, 7:42:49 PM2/7/11