You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recently I discovered the power of read/1. Yes, Markus @triska mentioned read/1 on various occasions/places, but I wasn't prepared then. Now, at least, I can transform my Prolog factoids/datasets from one form to another in a direct way. Or, I can do some crazy, impulsive things...
I wanted to write something again, now in a style/spirit of a demoscene, and very quickly and playfully. Except, I'm only a naive Prolog user and a computing layman.
As an old personal "project" I have a small website "featuring" some Chinese characters (and words, even proverbs and old forms of characters).
And recently, partly to re-understand my Miranda code (how it works conceptually, in order to add new concepts, new relations/views between Chinese characters and words on my website, and to explore the relations in my datasets), I rewrote it in Prolog (my code works in Scryer and Trealla).
All of that after exposure to The Power of Prolog. And I was exposed to some parts/aspects more than to others. In fact, as I see it, I use only few things of Prolog for my Prolog programming. I can (thanks to the power) create something using "nothing" but few concepts. Though, I'm not saying that the concepts are obvious at first sight in all its beauty, as for me.
Almost non-programmer, but paradoxically interested in programming languages and in program design methodologies, I had working prototypes written in constraint handling rules and then in answer set programming, in combination with Prolog. It was exciting for me, I felt the power (and I still like those two formalisms), yet, at the end of the day, it taught me to appreciate Prolog more than before.
There are problems with Scryer when using Linux pipes: #2866, but my "demo" is possible:
h1("A demo page").
p("Grammars can be nested and a sequence of grammars/strings can be concatenated using parenthesis and commas: they are DCGs.").
div(
(
p( (link("https://en.wikipedia.org/wiki/Unix_philosophy","They"), " said: make every program a filter.") ),
p("Yes, but what about maps?"),
p("Or, is this a preprocessor? Small and useless...")
)
).
The pipe and output (can be redirected to a file):
<h1>A demo page</h1>
<p>Grammars can be nested and a sequence of grammars/strings can be concatenated using parenthesis and commas: they are DCGs.</p>
<div>
<p><a href="https://en.wikipedia.org/wiki/Unix_philosophy">They</a> said: make every program a filter.</p>
<p>Yes, but what about maps?</p>
<p>Or, is this a preprocessor? Small and useless...</p>
</div>
Two caveats:
run :- read(end_of_file). has to be second in this imperative definition of run/0. I know, I could use if_/3 from reif library, something like:
run :-
read(E),
if_(E = end_of_file,
true,
(phrase(E,Str),
format("~s",[Str]),
run)).
And it's still a quick, dirty, imperative I/O, not a bi-directional relation, so I could use the traditional If-Then-Else ( condition -> then_clause ; else_clause ) construct, but I like solutions without it more (I like you dif/2) and I don't have many situations, in my noncritical programming in small, where I definitely need to use that construct.
Not mentioning the cut, that I never use, because: 1. I'm not that clever programmer, 2. I don't write programs for situations where computational efficiency is important, 3. I try to use Prolog as a declarative/relational programming, when I can/know how to do it (and when I'm not doing "impulsive programming").
An input file has to end without empty lines.
Thank you.
P.S.: This is not how my website is generated. This is not how to write and use Prolog. This is a quick-dirty-crazy "micro-demo" to be criticized, and maybe I might learn something. This is a personal note and the "demo" is a MacGuffin, I'm afraid...
P.S.2: For example, when I'm generating pages for my website, to save one page (stránka) to a file (súbor), I use this:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Recently I discovered the power of
read/1
. Yes, Markus @triska mentionedread/1
on various occasions/places, but I wasn't prepared then. Now, at least, I can transform my Prolog factoids/datasets from one form to another in a direct way. Or, I can do some crazy, impulsive things...I wanted to write something again, now in a style/spirit of a demoscene, and very quickly and playfully. Except, I'm only a naive Prolog user and a computing layman.
As an old personal "project" I have a small website "featuring" some Chinese characters (and words, even proverbs and old forms of characters).
I wrote that in PHP (the first PHP versions of my web were in many ways my first steps in programming, using ideas from Jackson structured programming. Later, still PHP, using ideas from How to Design Classes (PDF, 2.8 MB)), then, after some exposure to htdp.org, in Miranda (generated as a static site).
And recently, partly to re-understand my Miranda code (how it works conceptually, in order to add new concepts, new relations/views between Chinese characters and words on my website, and to explore the relations in my datasets), I rewrote it in Prolog (my code works in Scryer and Trealla).
All of that after exposure to The Power of Prolog. And I was exposed to some parts/aspects more than to others. In fact, as I see it, I use only few things of Prolog for my Prolog programming. I can (thanks to the power) create something using "nothing" but few concepts. Though, I'm not saying that the concepts are obvious at first sight in all its beauty, as for me.
Almost non-programmer, but paradoxically interested in programming languages and in program design methodologies, I had working prototypes written in constraint handling rules and then in answer set programming, in combination with Prolog. It was exciting for me, I felt the power (and I still like those two formalisms), yet, at the end of the day, it taught me to appreciate Prolog more than before.
There are problems with Scryer when using Linux pipes: #2866, but my "demo" is possible:
My demo program:
My input file:
The pipe and output (can be redirected to a file):
cat input-file.pl | scryer-prolog -g 'run,halt' demo-program.pl
Two caveats:
run :- read(end_of_file).
has to be second in this imperative definition ofrun/0
. I know, I could useif_/3
fromreif
library, something like:And it's still a quick, dirty, imperative I/O, not a bi-directional relation, so I could use the traditional If-Then-Else
( condition -> then_clause ; else_clause )
construct, but I like solutions without it more (I like youdif/2
) and I don't have many situations, in my noncritical programming in small, where I definitely need to use that construct.Not mentioning the cut, that I never use, because: 1. I'm not that clever programmer, 2. I don't write programs for situations where computational efficiency is important, 3. I try to use Prolog as a declarative/relational programming, when I can/know how to do it (and when I'm not doing "impulsive programming").
Thank you.
P.S.: This is not how my website is generated. This is not how to write and use Prolog. This is a quick-dirty-crazy "micro-demo" to be criticized, and maybe I might learn something. This is a personal note and the "demo" is a MacGuffin, I'm afraid...
P.S.2: For example, when I'm generating pages for my website, to save one page (stránka) to a file (súbor), I use this:
Of course, before that, I need to process page data:
And (among other things) dictionary (slovník) data:
Speaking of
if_/3
and processing, at various places I useif_/3
(and other things), like here:Or:
Yes, I need to rewrite my code, like everything, one day; it was written quickly... I was afraid, whether I can write it in Prolog...
At first, I started slowly, with tests:
Beta Was this translation helpful? Give feedback.
All reactions