[comp.lang.prolog] PROLOG Digest V5 #62

PROLOG-REQUEST@SUSHI.STANFORD.EDU (Chuck Restivo, The Moderator) (09/21/87)

PROLOG Digest            Tuesday, 22 Sep 1987      Volume 5 : Issue 62

Today's Topics:
                      Implementation - MU Note,
               LP Library - ansi_io.pro & env_funt.pro
----------------------------------------------------------------------

Date: 19 Sep 87 04:09:51 GMT
From: Lee Naish <munnari!mulga!lee@uunet.uu.net>  
Subject: MU

MU-Prolog and (some versions of) CProlog also have foreign function
interfaces (though not quite as easy to use).

-- Lee Naish

------------------------------

Date: Sun, 13 Sep 87 22:38:46 PDT
From: Edouard Lagache <lagache@violet.Berkeley.EDU> 
Subject: PROLOG library file: ansi_io.pro

/* File: ANSI_IO.PRO */
/******************************************************************************/
/*                                                                            */
/*          ANSI standard terminal input/output predicate definition file     */
/*                                                                            */
/*          This file contains predicates and data which provide commonly     */
/*      needed input/output capabilities for interactive programming.  It also*/
/*      contains predicates to control any terminal which supports the ANSI   */
/*      standard terminal type.  For IBM PC's and compatibles these commands  */
/*      will work only if the systems is booted up the the ANSI.SYS device    */
/*      driver.                                                               */
/*                                                                            */
/*               E. Lagache,  Version - 1.00,  February - 1987                */
/*                   Copyright(C) 1987, ALL RIGHTS RESERVED                   */
/*                                                                            */
/*                                                                            */
/*       NOTE: This file has been designed for use with ADA PROLOG.           */
/*             Also these predicates were developed for use with a Texas      */
/*             Instruments Professional computer.  Some adjustment of the     */
/*             screen attributes may be necessary for other machines.         */
/*                                                                            */
/******************************************************************************/

/* * * * * * * * * * * * * * * * * * * * * * * */
/*  'center_stg' prints out a string centered  */
/*  on an 80 column terminal screen.           */
/*                                             */
/*     E. Lagache,  Vers. - 1.00, Nov - 86     */
/* * * * * * * * * * * * * * * * * * * * * * * */
center_stg(String):- comp_tabs(String,Tabs), tab(Tabs),prtstr(String), nl.

/*##> 'comp_tabs' computes the number of    <##*/
/*##> spaced needed to center the string.   <##*/
/*##>                                       <##*/
/*##> Used by Predicate: 'center_stg'       <##*/
comp_tabs(String,Tabs):- length(String,Length), X is 80-Length, evenp(X),
                         Tabs is X/2, !.
comp_tabs(String,Tabs):- length(String,Length), X is 79-Length, evenp(X),
                         Tabs is X/2, !.

/* * * * * * * * * * * * * * * * * * * * * * * */
/*  'clear_end' deletes all characters after   */
/*  the cursor to the end of the screen        */
/*                                             */
/*     E. Lagache,  Vers. - 1.00, Feb - 87     */
/* * * * * * * * * * * * * * * * * * * * * * * */
clear_end:- prtstr("[J").

/* * * * * * * * * * * * * * * * * * * * * * * */
/*  'clear_line' deletes all characters after  */
/*  the cursor on a given line                 */
/*                                             */
/*     E. Lagache,  Vers. - 1.00, Feb - 87     */
/* * * * * * * * * * * * * * * * * * * * * * * */
clear_line:- prtstr("[K").

/* * * * * * * * * * * * * * * * * * * * * * * */
/*  'clear_screen' send the required escape    */
/*  sequence to the terminal.                  */
/*                                             */
/*     E. Lagache,  Vers. - 1.00, Feb - 87     */
/* * * * * * * * * * * * * * * * * * * * * * * */
clear_screen:- prtstr("[2J").

/* * * * * * * * * * * * * * * * * * * * * * * */
/*  'locate_cursor' moves the cursor to the    */
/*  desired location on the screen             */
/*                                             */
/*     E. Lagache,  Vers. - 1.00, Feb - 87     */
/* * * * * * * * * * * * * * * * * * * * * * * */
locate_cursor(Row, Column):- prtstr("["),write(Row),write(';'),
                             write(Column),prtstr("H"),!.

/* * * * * * * * * * * * * * * * * * * * * * * */
/*  'prtstr' sends a string to the current     */
/*  output string by converting the string to  */
/*  a name and using the 'write' predicate.    */
/*                                             */
/*     E. Lagache,  Vers. - 1.00, Feb - 87     */
/*                                             */
/*  Note: 'prtstr' is builtin to ADA VML       */
/*        PROLOG.                              */
/* * * * * * * * * * * * * * * * * * * * * * * */
/* prtstr(String) :- name(Atom,String), write(Atom). */

/* * * * * * * * * * * * * * * * * * * * * * * */
/*  'push_up' sends the requested number of    */
/*  newlnes to the output stream.              */
/*                                             */
/*     E. Lagache,  Vers. - 1.00, Dec - 86     */
/* * * * * * * * * * * * * * * * * * * * * * * */
push_up(0):- !.
push_up(I):- J is I-1, nl, push_up(J).

/* * * * * * * * * * * * * * * * * * * * * * * */
/*  'set_attribute' sets the charactaristics  */
/*  of characters after command.  Argument     */
/*  specifies attribute                        */
/*                                             */
/*     E. Lagache,  Vers. - 1.00, Feb - 87     */
/* * * * * * * * * * * * * * * * * * * * * * * */
set_attribute(reset):- prtstr("[1m").     /* Reset to default setup */
set_attribute(underline):-prtstr("[4;m").  /* underline characters */
set_attribute(blink):-prtstr("[5;m").      /* blinking characters  */
set_attribute(reverse):-prtstr("[7;m").    /* reverse video characters */
/*  Set character color */
set_attribute(black):-prtstr("[30m").     /* black characters */
set_attribute(red):-prtstr("[31m").       /* red characters */
set_attribute(green):-prtstr("[32m").     /* green characters */
set_attribute(yellow):-prtstr("[33m").    /* yellow characters */
set_attribute(blue):-prtstr("[34m").      /* blue characters */
set_attribute(magenta):-prtstr("[35m").   /* magenta characters */
set_attribute(cyan):-prtstr("[36m").      /* cyan characters */
set_attribute(white):-prtstr("[37m").      /* white characters */

/* End file: ANSI_IO.PRO */

------------------------------

Date: Sun, 13 Sep 87 22:39:13 PDT
From: Edouard Lagache <lagache@violet.Berkeley.EDU> 
Subject: PROLOG library file: env_funt.pro

/*  File: 'env-funt.pro' */
/***************************************************************************/
/*                                                                         */
/*                PROLOG environment enrichment functions                  */
/*                                                                         */
/*    This function library contains a number of predicates and operators  */
/*that make the process or developing PROLOG programs under VML PROLOG     */
/* more pleasant and productive.                                           */
/*                                                                         */
/*                                                                         */
/*                                                                         */
/*              E. Lagache,  Version - 1.10,  July - 1987                  */
/*         (C) Copyright 1987, Edouard Lagache, All Rights Reserved        */
                                                                           */
/*  Note: To use these predicates with your favorite editor, replace       */
/*        the 'edit' name in the functor and operator with the name of     */
/*        your editor.  Use whatever convention you like on the predicate  */
/*        of edit and load a file.                                         */
/*                                                                         */
/***************************************************************************/
?- op(255, fx, edit).    /* define operators to reduce typing */
?- op(255, fx, ledit).
?- op(255, fx, run).    /* Define shortcut for executing a shell command */

/* * * * * * * * * * * * * * * * * * * * * * * */
/*  'edit' calls up the editor to edit a file  */
/*                                             */
/*     E. Lagache,  Vers. - 1.10, Jul - 87     */
/*                                             */
/* Note: 'concat' is specific to ADA PROLOG    */
/* * * * * * * * * * * * * * * * * * * * * * * */
edit(Filename) :-   name(Filename,Filestg), append(Filestg,".pro",Filext),
                    append("edit ",Filext,Command),name(Form,Command),
                    exec(Form),!.

/*      Solution using ADA specific predicates */
/*edit(Filename):- concat(Command,['Edit ',Filename,'.pro']),exec(Command).*/

/* * * * * * * * * * * * * * * * * * * * * * * */
/*  'dos' invokes the operating system shell   */
/*                                             */
/*     E. Lagache,  Vers. - 1.00, Feb - 87     */
/* * * * * * * * * * * * * * * * * * * * * * * */
dos :-   exec(command).

/* * * * * * * * * * * * * * * * * * * * * * * */
/*  'ledit' calls up the editor to edit a file */
/*  and then loads it into the system.         */
/*                                             */
/*     E. Lagache,  Vers. - 1.10, Jul - 87     */
/*                                             */
/* Note: 'concat' is specific to ADA PROLOG    */
/* * * * * * * * * * * * * * * * * * * * * * * */
ledit(Filename) :-  name(Filename,Filestg), append(Filestg,".pro",Filext),
                    append("edit ",Filext,Command),name(Form,Command),
                    exec(Form),forget(Filename),consult(Filename),!.

/*      Solution using ADA specific predicates */
/* ledit(Filename) :- concat(Command,['Edit ',Filename,'.pro']),        */
/*                    exec(Command),forget(Filename),consult(Filename). */

/* * * * * * * * * * * * * * * * * * * * * * * */
/*  'run' runs passes a command to the         */
/*  operating system for execution.            */
/*                                             */
/*     E. Lagache,  Vers. - 1.00, Feb - 87     */
/* * * * * * * * * * * * * * * * * * * * * * * */
run(Command) :-    exec(Command).

/* End file: ENV_FUNT.PRO */

------------------------------

End of PROLOG Digest
********************