Re: Difficulties with \
joel <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
On 26/10/2013 00:57, Pierpaolo Bernardi wrote: > On Sat, Oct 26, 2013 at 12:14 AM, joel<[email protected]> wrote: >> Hello all >> >> How can I create atom \sin ? > If you want the atom whose name is composed by the four characters \, > s, i, n, then the literal syntax is '\\sin' > >> I get for example >> >> ?- writef('%n%w', [92,sin]). >> \sin >> true. > You just wrote the characters. Yes, I understood that this morning, I think I was a little bit tired this night. >> ?- with_output_to(atom(A), writef('%n%w', [92,sin])). >> A = '\\sin'. > that's the atom you want. You can check with writeln: > > 16 ?- writeln('\\sin'). > \sin > true. > > or with atom_chars: > > 18 ?- atom_chars('\\sin',C). > C = [\, s, i, n]. > >> Idem : >> >> ?- A= \sin. >> A = \sin. > This is not an atom: > > 11 ?- atom(\sin). > false. > 12 ?- write_canonical(\sin). > \(sin) > true. Useful tip, I didn't think of that. > ?- A= \sin, atomic_list_concat([A, '(', 8, ')'], L). > ERROR: atomic_list_concat/2: Type error: `text' expected, found `\sin' > right. since A is not an atom. > >> ?- A= '\sin', atomic_list_concat([A, '(', 8, ')'], L). >> A = ' in', >> L = ' in(8)'. > now A is an atom, but \s in a quoted atom name is an escape sequence > for the space character. > >> ?- A= '\\sin', atomic_list_concat([A, '(', 8, ')'], L). >> A = '\\sin', >> L = '\\sin(8)'. >> >> Is it a bug ? > No. It's all working fine. Read section '2.15.1.2 Character Escape > Syntax' in the manual for the full details. > > P. > _______________________________________________ > SWI-Prolog mailing list > [email protected] > https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog > Thank you very much, I get it now ! Cheers Joël