Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.prolog > #14497
| From | Mild Shock <janburse@fastmail.fm> |
|---|---|
| Newsgroups | comp.lang.prolog |
| Subject | Code Generation with write/[1,2] [Some Testcases] (Was: Streamable DOM and obsolete put_code/[1,2]) |
| Date | 2025-04-07 09:58 +0200 |
| Message-ID | <vt00jk$sg63$1@solani.org> (permalink) |
| References | <vsj1an$m6gi$1@solani.org> |
Hi,
One of the dirty tricks, I use in the Dogelog Player
backend for code generation. I do generate JavaScript,
Python and Java code via write/[1,2].
How does it work. Here an example: Wanna write a BigInt
from JavaScript, like for example 123n. No problem put
it into an atom and use unquoted write:
/* JavaScript Generator */
?- write('123n').
123n
Now there are some nasty things. Like for example
this test case. Very interesting behaviour:
/* Dogelog Player 1.3.2 */
?- write(- '123n').
- 123n
/* SWI-Prolog 9.3.22 */
?- write(- '123n').
- 123n
On the other hand:
/* Trealla Prolog 2.67.27 */
?- write(- '123n'), nl.
-123n
/* Scryer Prolog 0.9.4 */
?- write(- '123n'), nl.
-123n
See the difference? A space inserted or not. Its quite
some twilight zone, the behaviour of unquoted atoms.
Bye
Mild Shock schrieb:
> Hi,
>
> The development of Novacore takes interesting turns.
> Originally more accidentially, because I observed it
> can serve a few interesting use cases, like atomic
>
> logging with some unspoken or spoken gurantees,
> I introduced put_atom/[1,2] in Novacore streams:
>
> > put_atom(S, A):
> > The built-in succeeds. As a side effect, it adds
> > the atom to the stream S.
>
> Now because I am revising my streamable DOMs, the
> "HTML writer" part, I even went so far as to
> bootstrap put_code/[1,2] from it:
>
> > put_code(Stream, Code) :-
> > char_code(Atom, Code),
> > put_atom(Stream, Atom).
>
> One can eliminate each put_code/[1,2] call such
> as put_code(S, 0'\n) by a put_atom/[1,2] call
> such as put_atom(S, '\n'). The performance is the
>
> same, in my case can be slighly better since under
> the hood put_code and put_atom called the same
> stream meachnism.
>
> But the main reason I eliminate put_code was
> to have a single point. Because the Prolog
> write_term/1 is 100% written in Prolog, in the
>
> end it only only uses put_atom.
>
> Bye
Back to comp.lang.prolog | Previous | Next — Previous in thread | Find similar
Streamable DOM and obsolete put_code/[1,2] Mild Shock <janburse@fastmail.fm> - 2025-04-02 11:51 +0200
Re: Streamable DOM and obsolete put_code/[1,2] Mild Shock <janburse@fastmail.fm> - 2025-04-02 11:56 +0200
Re: Streamable DOM and obsolete put_code/[1,2] Mild Shock <janburse@fastmail.fm> - 2025-04-02 12:03 +0200
Space Junk might fall on your head [Scryer Prolog WASM] (Was: Streamable DOM and obsolete put_code/[1,2]) Mild Shock <janburse@fastmail.fm> - 2025-04-05 18:33 +0200
Editor’s Draf, 10 January 2025 - Trusted Types (Was: Space Junk might fall on your head [Scryer Prolog WASM]) Mild Shock <janburse@fastmail.fm> - 2025-04-05 19:00 +0200
*** 2025 Prolog Awards *** (Was: Space Junk might fall on your head [Scryer Prolog WASM]) Mild Shock <janburse@fastmail.fm> - 2025-05-25 13:48 +0200
Scryer Prolog has dethroned SWI-Prolog (Was: *** 2025 Prolog Awards ***) Mild Shock <janburse@fastmail.fm> - 2025-05-26 12:22 +0200
Nevertheless I have bad news for Prolog (Was: Scryer Prolog has dethroned SWI-Prolog) Mild Shock <janburse@fastmail.fm> - 2025-05-26 12:31 +0200
Cannot consult/1 after listing/1 (Was: Scryer Prolog has dethroned SWI-Prolog) Mild Shock <janburse@fastmail.fm> - 2025-05-28 12:09 +0200
Tau-Prolog Code Mirror Integration has Flaws (Was: Space Junk might fall on your head) Mild Shock <janburse@fastmail.fm> - 2025-06-05 09:54 +0200
Code Generation with write/[1,2] [Some Testcases] (Was: Streamable DOM and obsolete put_code/[1,2]) Mild Shock <janburse@fastmail.fm> - 2025-04-07 09:58 +0200
csiph-web