| Deutsch English Français Italiano |
|
<103c27c$169la$1@solani.org> View for Bookmarking (what is this?) Look up another Usenet article |
Path: news.eternal-september.org!eternal-september.org!feeder3.eternal-september.org!news.swapon.de!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: Mild Shock <janburse@fastmail.fm>
Newsgroups: comp.lang.prolog
Subject: maplist(char_code, Chars, Codes) is bidirectional (Was: The beauty of
a dual use hook)
Date: Mon, 23 Jun 2025 19:17:33 +0200
Message-ID: <103c27c$169la$1@solani.org>
References: <vpceij$is1s$1@solani.org> <103bos1$164mt$1@solani.org>
<103bpdh$164t1$1@solani.org> <103bqc8$165f2$1@solani.org>
<103c072$168hc$1@solani.org> <103c19r$1694v$1@solani.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 23 Jun 2025 17:17:32 -0000 (UTC)
Injection-Info: solani.org;
logging-data="1255082"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101
Firefox/128.0 SeaMonkey/2.53.21
Cancel-Lock: sha1:PAIWAb4TFYdkRRN3zM9s9qSJWvE=
X-User-ID: eJwNyskBwCAIBMCWVFiOcoDV/ktI5j0Q2zauBlM8vOyWpasiEt2UERWei6Q/9Sa3/WvAsktw1eliBJ1DpOUHaWUWkw==
In-Reply-To: <103c19r$1694v$1@solani.org>
Using again my super powered library(portray_text):
?- set_prolog_flag(double_quotes, codes).
true.
?- set_prolog_flag(back_quotes, chars).
true.
?- set_portray_text(enabled, true).
true.
?- maplist(char_code, `abc`, X).
X = "abc".
?- maplist(char_code, X, "abc").
X = `abc`.
So if you have a Prolog system that has chars, you
could bootstrap as follows:
atom_codes(X, Y) :-
var(X), !,
atom_chars(Z, Y),
maplist(char_code, X, Z).
atom_codes(X, Y) :-
atom_chars(X, Z),
maplist(char_code, Z, Y).
Or if you have a Prolog system that has codes, you
could bootstrap as follows:
atom_chars(X, Y) :-
var(X), !,
atom_codes(Z, Y),
maplist(char_code, Z, X).
atom_chars(X, Y) :-
atom_codes(X, Z),
maplist(char_code, Y, Z).
Mild Shock schrieb:
> Full source code here:
>
> swi2.pl.log
> https://github.com/SWI-Prolog/swipl-devel/issues/1373#issuecomment-2997214639
>
>
> Since it has a dual use hook, works fine simultaneously:
>
> ?- set_portray_text(enabled, false).
> true.
>
> ?- X = [a,b,c].
> X = [a, b, c].
>
> ?- X = [0'a,0'b,0'c].
> X = [97, 98, 99].
>
> And then:
>
> ?- set_prolog_flag(double_quotes, codes).
> true.
>
> ?- set_prolog_flag(back_quotes, chars).
> true.
>
> ?- set_portray_text(enabled, true).
> true.
>
> ?- X = [a,b,c].
> X = `abc`.
>
> ?- X = [0'a,0'b,0'c].
> X = "abc".
>
> Mild Shock schrieb:
>> Hi,
>>
>> Even the SWI-Prolog master not wide awake,
>> doing day-sleeping.
>>
>> > I don’t know whether they realised that you
>> > cannot meaningfully support both in the same
>> > system and surely not in the same application.
>>
>> Maybe you didn’t notice this nifty detail.
>> Thats all you need:
>>
>> > The ISO core standard is silent about a flag back_quotes
>>
>> > Its more a naming problem. Have two libraries
>> library(portray_codes) and library(portray_chars),
>> Or one library(portray_text).
>>
>> Just add one more rule:
>>
>> user:portray(Chars) :-
>> portray_text_option(enabled, true),
>> '$skip_list'(Length, Chars, _Tail),
>> portray_text_option(min_length, MinLen),
>> Length >= MinLen,
>> mostly_chars(Chars, 0.9),
>> portray_text_option(ellipsis, IfLonger),
>> quote2(C),
>> put_code(C),
>> maplist(char_code, Chars, Codes),
>> ( Length > IfLonger
>> -> First is IfLonger - 5,
>> Skip is Length - 5,
>> skip_first(Skip, Codes, Rest),
>> put_n_codes(First, Codes, C),
>> format('...', [])
>> ; Rest = Codes
>> ),
>> put_var_codes(Rest, C),
>> put_code(C).
>>
>> The use of maplist/3 is elegant, and works since we do
>> not print open lists, right?
>>
>> Mild Shock schrieb:
>>> Hi,
>>>
>>> The most radical approach is Novacore from
>>> Dogelog Player. It consists of the following
>>> major incisions in the ISO core standard:
>>>
>>> - We do not forbid chars, like for example
>>> using lists of the form [a,b,c], we also
>>> provide char_code/2 predicate bidirectionally.
>>>
>>> - We do not provide and _chars built-in
>>> predicates also there is nothing _strings. The
>>> Prolog system is clever enough to not put
>>> every atom it sees in an atom table. There
>>> is only a predicate table.
>>>
>>> - Some host languages have garbage collection that
>>> deduplicates Strings. For example some Java
>>> versions have an options to do that. But we
>>> do not have any efforts to deduplicate atoms,
>>> which are simply plain strings.
>>>
>>> - Some languages have constant pools. For example
>>> the Java byte code format includes a constant
>>> pool in every class header. We do not do that
>>> during transpilation , but we could of course.
>>> But it begs the question, why only deduplicate
>>> strings and not other constant expressions as well?
>>>
>>> - We are totally happy that we have only codes,
>>> there are chances that the host languages use
>>> tagged pointers to represent them. So they
>>> are represented similar to the tagged pointers
>>> in SWI-Prolog which works for small integers.
>>>
>>> - But the tagged pointer argument is moot,
>>> since atom length=1 entities can be also
>>> represented as tagged pointers, and some
>>> programming languages do that. Dogelog Player
>>> would use such tagged pointers without
>>> poluting the atom table.
>>>
>>> - What else?
>>>
>>> Bye
>>>
>>> Mild Shock schrieb:
>>>>
>>>> Technically SWI-Prolog doesn't prefer codes.
>>>> Library `library(pure_input)` might prefer codes.
>>>> But this is again an issue of improving the
>>>> library by some non existent SWI-Prolog community.
>>>>
>>>> The ISO core standard is silent about a flag
>>>> back_quotes, but has a lot of API requirements
>>>> that support both codes and chars, for example it
>>>> requires atom_codes/2 and atom_chars/2.
>>>>
========== REMAINDER OF ARTICLE TRUNCATED ==========