thoughts: script language for term browser
Bert THOMPSON
aet at cs.mu.OZ.AU
Fri Aug 28 16:01:03 AEST 1998
People,
I'd appreciate it if you could me thoughts on the following...
In order to display terms in as flexible a manner as possible,
we need a scripting language. This would allow the display
of the list ["this", "is", "a", "list"] as, say:
[
"this",
"is",
"a",
"list"
]
and the map { 1 -> "this", 2 -> "is", 3 -> "a", 4 -> "map"} as, say:
{
1 -> "this"
2 -> "is"
3 -> "a"
4 -> "map"
}
And, of course, nested data structures, such as lists of maps, should
also be dealt with.
We could make the term browser explicitly handle such types specially,
however it's neater to have a simple scripting language. Commonly
used types from the library could have a script that's preloaded.
I'm currently implementing such a scripting language. Initially I
considered a simple Mirandese language, but a Prolog syntax is better:
a) easier to parse (given that the technology's already in the library).
b) needs no culture-shift on the programmer's behalf.
c) Prolog interpreters are easy to implement, especially as one's
already written.
Specifically, what I'm doing is:
- a simple Prolog-ese interpreter
- a library of Mercury predicates called from the Prolog
interpreter which do the following:
- decompose terms
- match terms against patterns
- build frames (currently ASCII pictures)
The primitives are:
% match term with pattern
:- pred matches(term::in, pattern::in) is semidet.
% extract nth arg of term
:- pred nth_arg(term::in, int::in, term::out) is semidet.
% name of topmost constructor (fails if not atom)
:- pred cons_name(term::in, string::out) is semidet.
% make a frame from a string
:- pred frame(string::in, frame::out) is det.
% put a visible box around a frame
:- pred box(frame::in, frame::out) is det.
% vertically stack two frames (left-aligned)
:- pred stack(frame::in, frame::in, frame::out) is det.
% horizontally juxtapose two frames (centred)
:- pred juxtapose(frame::in, frame::in, frame::out) is det.
% indent a frame (put some whitespace on the left)
:- pred indent(frame::in, frame::out) is det.
% A handful of others as the need becomes apparent.
% The set is kept small enough to demo a prototype.
I'd appreciate feedback on the following:
- is this idea fundamentally sound?
- can anyone think of a more reasonable approach?
- are there any things people would really like the
browser to do that the above seems incapable of?
I don't need the following feedback:
- you need to add <insert primitive>:
The above should suffice as a proof-of-concept.
The prototype is in the pipeline and if anyone raises issues that
suggest this is not the way to go, I'll take a different tack.
Cheers,
Bert
More information about the developers
mailing list