Serge D. Mechveliani wrote:
>
> At least Haskell has some interface to C.
> Maybe, you can describe a String interface of C to Axiom via a file?
> Imagine the following.
> (1) A C function char* axi(char* p)
> takes a string starting from the place p and ending at a certain
> `end' symbol
> (I am trying to recall C, fix this, please, if necessary).
> (2) It puts this string str to the file interf.input for Axiom.
> (3) Axiom inputs str from this file,
> parses it as a program call for the interpreter,
> runs the interpreter, writes the result to str'
> outputs str' to this file,
> (4) axi inputs str' from this file and returns the pointer to the
> head of str'.
>
> Probably,
> * axi must somehow open and close the file for output (?),
> open/close the file for input,
> * Axiom must apply )read "interf.input", )write "interf.input"
> (?),
> open/close the file for input, open/close the file for output (?)
> -- all this to be done in an appropriate sequence.
>
> How to arrange this?
> What needs to be written and called at the Axiom end?
>
> Maybe, if this works with a file, then one could think of a socket.
I am not sure why you keep talking about files. To know _when_
to read file you need some "side chanell" of comunication. Once
you have such chanell, you can simply use it for all comunitations.
Below outine of versy naive interface:
1) Create process conected via pipes:
a) create two pipes (done via pipe system call)
b) fork
c) in the child set pipes, one as standard input and the
other as standart output (via dup2 syctem call)
4) close unneded ends of pipes
5) in the child start 'fricas -nosman' (via exec system call)
2) Wait for FriCAS propt
3) Initialize output markers
4) In your axi:
a) write string to the first pipe
b) read from second pipe waiting for start of output marker
c) collect output up to end of output marker
d) resturn it
Notes:
1) You can see how markers work by trying the following at FriCAS
prompt:
)lisp (defun ppp(x y) (format t "~S" x))
)boot $ioHook := FUNCTION PPP
2) You probably need to read and write to pipes in parallel, using
select system call. Otherwise, you may get deadlock, because
FriCAS will block echoing your input (if nobody reads from the
second pipe) and then you will block (because FriCAS being blocked
will not read from its end of the first pipe).
3) Instead of pipes you can use pseudo-tty-s, but pipes seem easier.
4) That outline will need about 100-200 lines of C code to implement
which will take few hours. Unfortunatly, today I am in a hurry,
so I can not give you detailed code.
--
Waldek Hebisch
[email protected]
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/fricas-devel?hl=en.