Home > Archive > Prolog > March 2008 > Re: splitting strings (swi-prolog) (got it (fix))
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: splitting strings (swi-prolog) (got it (fix))
|
|
| Markus Triska 2008-03-10, 7:46 pm |
| Dustin Kick<mac_vieuxnez@mac.com> writes:
> Is there a goal I can run DCGs through to see the expanded code?
Use clause/2 to access its term representation. Also try listing/[01]:
?- listing(tokens).
%@ tokens([], A, B, C) :-
%@ token(A, B, C).
%@ tokens([A|E], C, B, G) :-
%@ ( A==32,
%@ D=B
%@ -> token(C, D, F),
%@ tokens(E, [], F, G)
%@ ; tokens(E, [A|C], B, G)
%@ ).
%@ true.
--
comp.lang.prolog FAQ: http://www.logic.at/prolog/faq/
| |
| bart demoen 2008-03-10, 7:46 pm |
| On Mon, 10 Mar 2008 21:30:07 +0100, Markus Triska wrote:
> Dustin Kick<mac_vieuxnez@mac.com> writes:
>
>
> Use clause/2 to access its term representation. Also try listing/[01]:
>
> ?- listing(tokens).
> %@ tokens([], A, B, C) :-
> %@ token(A, B, C).
> %@ tokens([A|E], C, B, G) :-
> %@ ( A==32,
> %@ D=B
> %@ -> token(C, D, F),
> %@ tokens(E, [], F, G)
> %@ ; tokens(E, [A|C], B, G)
> %@ ).
> %@ true.
There are two things I can't grok:
1) the %@ : when I do ?- listing(tokens). those weird symbols don't show
up. We are using the same SWI, or not ?
2) why is there 32 in the output, while the original program had 0' ?
is this unavoidable, an SWI bug or an ISO Prolog inconsistency ?
Cheers
Bart Demoen
| |
| Jan Wielemaker 2008-03-11, 4:45 am |
| On 2008-03-10, bart demoen <bmd@cs.kuleuven.be> wrote:
> On Mon, 10 Mar 2008 21:30:07 +0100, Markus Triska wrote:
>
>
> There are two things I can't grok:
>
> 1) the %@ : when I do ?- listing(tokens). those weird symbols don't show
> up. We are using the same SWI, or not ?
I leave that to Markus
> 2) why is there 32 in the output, while the original program had 0' ?
> is this unavoidable, an SWI bug or an ISO Prolog inconsistency ?
You know the answer: as it stands in ISO, it is unavoidable. The
tokeniser must translate 0' into the character code of the space. In
general that is even undefined but SWI-Prolog is internally Unicode,
so it is defined as 32, regardless of the locale. characters codes
however are no special type and therefore cannot be distinguished from
integers. I'm not sure whether ISO would allow for a subtype of
integer that represents character codes. Possibly.
Same for [32] and " ", etc. To a certain extend this can be remedied
using ?- set_prolog_flag(double_quotes, chars). It doesn't fix all
issues though, and a global flag that introduces such big
incompatibilities causes more troubles than it solves. I never touch
that flag for any real programming task.
I once raised a similar issues about [] == [ ] == [/*empty list*/] == '[]'
It is fine for the first three to be equal, but I still have doubts on the
latter. Same for {}, though this causes less confusing on practice.
I don't think there is an easy fix to these issues without introducing
serious compatibility issues.
Cheers --- Jan
|
|
|
|
|