I have improved my "SED command in SWI-Prolog" 1) variables for SED expressions are allowed.
2) "global variables" in SED expressions are allowed. Document in some details
should be prepared.
The following queries are real ones; outputs are edited for readability.
?- let_sed(F, w("e")/ =(`CC`)), phrase(F, `eaea`, R).
R => CCaCCa,
where let_sed/2 is a run-time compiler for sed expression.
?- F = (=(`EE`)), phrase( F >> (w("e") / F), `eaea`, R).
R ==> EEaEEa
where term F of the sed command of the form
F >> phrase / action
tells the sed compiler that the variables occurring on the term F are globals.
So, this is an error case.
?- let(F, =(`cc`)), sed(w("e")/F /* this F is local */ , `eaea`, R).
%@ ERROR: call/2: Arguments are not sufficiently instantiated
Commands s, a, b, t, w like in unix sed commands are defined directly based on this
in a uniform manner as a special case of our version.
?- phrase(@(s/ "e"/ "ccc"), `eaea`, R), smash(R).
R ==> cccaccca
The symbol @ indicates the expression is s, a, b, t, w comands.
The sed compiler does a very simple `partial evaluation` on list appending
to suppress generating list cells. All these features have been implemented on
my PAC library in short codes.
I am going to include these new commands to my private favorite toolbox for
editing emacs buffer. I would like to receive responses from those
who are doing similar things with Emacs buffer for sharing ideas.
Editing buffer with prolog has been a hobby for me.
I am not expert on emacs-lisp, but I like it also.