String is not string in SWI prolog , part/2.



Last time , this topic was concluded that the string can't
be produced by directly written in the form of "...",
and it should be produced by procedures , eg
string_to_atom/2.

But the problem is not totally solved . Please look :
--------------------------------------------------------------------------------------
Welcome to SWI-Prolog (Multi-threaded, Version 5.2.13)
Copyright (c) 1990-2003 University of Amsterdam.
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

1 ?- string_to_atom(S,'This is a test').

S = "This is a test"

Yes
2 ?- string_to_atom(S,'This is a test'),
| assertz(db_string(S)),
| tell('c:\\test.txt'),
| listing(db_string/1),
| told.

S = "This is a test"

Yes
3 ?- db_string(S).

S = "This is a test"

Yes
4 ?- db_string(S),
| string_concat(S,S,S2).

S = "This is a test"
S2 = "This is a testThis is a test"

Yes
5 ?- retractall(db_string(_)).

Yes
6 ?- db_string(S).

No
7 ?- consult('c:\\test.txt').
% c:\test.txt compiled 0.00 sec, 520 bytes

Yes
8 ?- string_concat(S,S,S2).
ERROR: string_concat/3: Arguments are not sufficiently instantiated
9 ?- db_string(S),
| string_concat(S,S,S2).
ERROR: string_concat/3: Type error: `atomic' expected, found `[84, 104,
105, 115, 32, 105, 115, 32, 97, 32, 116, 101, 115, 116]'

---------------------------------------------------------------------------
You can see that , there is problem in the step 9 , although the
identical
codes get allright in the step 4.

For more clarification , just look the contents of c:\test.tx:
+++++++++++++++++++++++++++++++++++++++++

:- dynamic db_string/1.

db_string("This is a test").
++++++++++++++++++++++++++++++++++++++++++

It takes the form of db_string/1 with a parameter made of string .
But it just compiles to something that causes string_concat out of
order.
So weird !

Maybe that is because things chages if saved by listing and retrieved
by consult/1. For circumvention from such possibility ,
the following topic happens.

.



Relevant Pages

  • Re: Can someone splain why this regex wont work both ways?
    ... perl parses the regex itself, and compiles it into an internal form. ... Then it matches that regex against the string you provide. ... will backtrack, under some circumstances; ...
    (comp.lang.perl.misc)
  • Re: Does VBscript support " & _" for long strings?
    ... each concatenation involves the creation of a new string along with the ... Please reply to the newsgroup. ...
    (microsoft.public.scripting.vbscript)
  • Re: Calling a managed function from native code
    ... running on top of the CLR but which is isn't garbage collected. ... compiles to IL which is JIT compiled and runs on top of the CLR. ... void test() { ... You can't do that, String is not disposable, it doesn't have a destructor, it doesn't have a Dispose method. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Python Regex Question
    ... How can I just extract the real/integer number using regex? ... TypeError: expected string or buffer ... Does beautiful soup returns array of objects? ... compiles and searches every time. ...
    (comp.lang.python)
  • Re: improve strlen
    ... Faster way to implement strlenis to store the length of the string, ... int strlen ... Visual C++ 8.1 Beta 2 compiles it like this: ... Optimizing x86 code is much different than writing for the Pentium ...
    (comp.lang.asm.x86)