Re: internal vs external representation
Ross Boylan <[email protected]> Sun, 13 Apr 2014 12:56:11 -0700
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <1397418971.5844.32.camel@localhost> |
On Sun, 2014-04-13 at 11:07 -0700, 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? > > 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. > Here's some code for the slightly clunky version. Defining operators avoids the need to quote, and lets prolog do the parsing for me. :- op(400, yfx, #). make_when(M/D/Y1#S, when(date(Y2, M, D), seq(S))) :- Y2 is Y1 + 2000. make_when(M/D/Y1, when(date(Y2, M, D), seq(S))) :- make_when(M/D/Y1#0, when(date(Y2, M, D), seq(S))). % making ~ an operator didn't work make_path(A/B, path(PathList)) :- make_path(A, path(P2)), append(P2, [B], PathList), !. make_path(A, path([A])). When I tried declaring ~ an operator I got this: ?- make_path(os~/a/b/c, P). ERROR: Syntax error: Operator expected ERROR: make_path(os ERROR: ** here ** ERROR: ~/a/b/c, P) . So I'm just using slashes on input paths. Ross