Re: Prolog as a scripting language



Ah, yes. Looks like I'm still thinking procedurally. Thanks.

On Feb 27, 8:04 am, Markus Triska <tri...@xxxxxxxx> wrote:
ashley.fernan...@xxxxxxxxx wrote:
Not looking to replace something that's missing ... looking to write
cleaner code. Something that people might look to Python for. Also,
coming from a background of procedural languages, I'm looking to learn
better techniques. Besides, I found Prolog very interesting, but none
of the tutorials I saw on the web mentions the use of Prolog in this
domain.

What about a domain-specific language, consisting of the shell commands:

shell_commands(
[
"echo a",
"echob",
"echo c"
]).

and a simple interpreter for it:

exec_commands :-
shell_commands(SCs),
exec_commands(SCs).

exec_commands([]).
exec_commands([S|Ss]) :-
( shell(S, 0) ->
exec_commands(Ss)
; format("failed."),
fail
).

Now we have:

%?- exec_commands.
%@% a
%@% sh: echob: not found
%@% failed.
%@% No

All the best,
Markus

--
comp.lang.prolog FAQ:http://www.logic.at/prolog/faq/

.