Re: what's the corresponding predcate as atomic_list_concat in swi
Daniel Diaz <[email protected]>
| Newsgroups | gmane.comp.gnu.prolog.general |
|---|---|
| Message-ID | <[email protected]> |
Le 28/06/2013 00:15, z_axis a écrit :
> Can it convert '1 2 3 4 5 6 7' to [1,2,3,4,5,6,7] ?
> IIRC,in swi, atomic_list_concat('1 2 3 4 5 6 7', ' ', X). => X =
> [1,2,3,4,5,6,7]
>
> Best Regards!
> 在 Thu, 27 Jun 2013 02:22:15 +0800,Daniel Diaz
> <[email protected]> 写道:
>
You need to program it. Here is a simple program that split an atom
(elements are separated by spaces). Each atom of an element is converted
to the final type with conv_elem/2. Here it is defined to convert atoms
to numbers. If you want atoms for elements simply define conv_elem(A, A).
atom_to_list('', []) :-
!.
atom_to_list(A, L) :-
sub_atom(A, Bef, _, Aft, ' '), !,
( Bef > 0 ->
L = [X|L1],
sub_atom(A, 0, Bef, _, A0),
conv_elem(A0, X)
;
L = L1
),
Bef1 is Bef + 1,
sub_atom(A, Bef1, Aft, 0, A1),
atom_to_list(A1, L1).
atom_to_list(A, [X]) :-
conv_elem(A, X).
conv_elem(A, X) :-
number_atom(X, A).
Run:
| ?- atom_to_list('1 2 3 4 5 6 7',L).
L = [1,2,3,4,5,6,7]
Daniel
>> Hi,
>>
>> the easiest way to convert numbers to atoms and then use
>> atom_concat/3. This should work:
>>
>> atomic_concat(X1, X2, A3) :-
>> to_atom(X1, A1),
>> to_atom(X2, A2),
>> atom_concat(A1, A2, A3).
>>
>> to_atom(A, A) :-
>> atom(A), !.
>>
>> to_atom(X, A) :-
>> number_atom(X, A).
>>
>>
>> Daniel
>>
>> Le 26 juin 2013 à 08:39, Sean Charles <[email protected]> a écrit :
>>
>>> Hi z_axis,
>>>
>>> I looked long and hard and I couldn't find anything suitably matched
>>> in the atom and character code sections … sorry.
>>>
>>> I think somebody that *knows* the language has an opportunity to
>>> hand-roll something at this point… I will also try to do this as an
>>> exercise, it will be good to try.
>>>
>>> My initial thought would be to use a stream writing to an atom, then
>>> write each atom in the original list plus the intervening comma for
>>> all but the last atom.
>>>
>>> open_output_atom_stream ...
>>> write_term_to_atom … each list member plus a comma
>>> close_output_atom_stream ...
>>>
>>> Simples. Except I just have to do it. And if it could be used
>>> "backwards" to split the atom then so much the better, like SWI.
>>>
>>> I am sure somebody else will do it first but I like the look of this
>>> so I shall try as well.
>>>
>>> Sean.
>>>
>>>
>>>
>>>
>>> On 26 Jun 2013, at 03:15, z_axis <[email protected]> wrote:
>>>
>>>> It seems there is just atomic_concat in gprolog ?
>>>> Mime-Version: 1.0
>>>> Content-Type: Text/Plain; charset=iso-8859-7
>>>> Content-Transfer-Encoding: base64
>>>> X-CM-TRANSID:C8CowEApvUUWT8pR28F5Cw--.21S2
>>>> X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73
>>>> VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjxU2t8nUUUUU
>>>> X-CM-SenderInfo: x2bd5xrv6rljoofrz/1tbiThZIZlEAFN07UAABsE
>>>>
>>>> ZV4o8C5pKSArIDEgPSAwDQo=
>>>>
>>>>
>>>> _______________________________________________
>>>> Users-prolog mailing list
>>>> [email protected]
>>>> https://lists.gnu.org/mailman/listinfo/users-prolog
>>>
>>>
>>> _______________________________________________
>>> Users-prolog mailing list
>>> [email protected]
>>> https://lists.gnu.org/mailman/listinfo/users-prolog
>>>
>>> --
>>> Ce message a ete verifie par MailScanner
>>> pour des virus ou des polluriels et rien de
>>> suspect n'a ete trouve.
>>>
>>
>>
>
>
--
Ce message a ete verifie par MailScanner
pour des virus ou des polluriels et rien de
suspect n'a ete trouve.
_______________________________________________
Users-prolog mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/users-prolog