Re: internal vs external representation

Jan Wielemaker <[email protected]> Sun, 13 Apr 2014 20:45:27 +0200
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 13-04-14 20:07, Ross Boylan wrote:
> Essentially I'm looking for a kind of reverse of portray. Portray goes
> from an internal representation (for prolog) to an external
> representation (for a person).  I'd like to go from user input in the
> external form to the internal form.
> 
> Following Richard O'Keefe's advice I used structurally explicit forms
> for some of my constructs.  An auxiliary program (in python) converts
> from a friendlier form of input, so
> input (external representation) -> internal representation
> 3/1/12 -> when(date(2012, 3, 1), seq(0))
> myos~/a/b/c -> path([myos, a, b, c]).
> 
> portray then does the reverse mapping (even in the debugger, which is
> quite nice).
> 
> My question is how I can get the first mappings for interactive queries.
> E.g., now I must type
> deep_descendants(path([oscorn1, usr, local, root]), when(date(2011,12,
> 28), seq(999)), G)
> to get G (a graph).
> 
> I would like to be able to type
> deep_descendants(oscorn1~/usr/local/root, 12/28/11#9999, G).
> 
> Is there a way to do that, or something close to it?

I guess you have two options.  One is to use term/goal expansion to rewrite
an unambiguous defaulty Prolog representation to your internal form.  In
that
case, you are limited by the Prolog syntax and what you can achieve with
operators.  The second option is to use quasi quotations.  That allows you
to write {|mysyntax||Data|}, where you can define your own parser to parse
Data into your internal representation.

	Cheers --- Jan




> 
> Maybe with some kind of helpers, e.g.,
> make_when(12/28/11#9999, When), make_path(oscorn1~/usr/local/root,
> Path), deep_descendants(Path, When, Graph).
> But that's a little clunky, and maybe the arguments need to be strings.
> 
> Thanks.
> Ross Boylan
> 
> P.S. I see Richard has a whole chapter in his "Craft of Prolog" about
> findall, setof and bagof, which would have answered my earlier question
> about them if I'd seen it.
> 
> _______________________________________________
> SWI-Prolog mailing list
> [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>