Mercurial > hg > plml
changeset 37:89688ebc447f tip
Deprecating this repository.
author | samer |
---|---|
date | Mon, 05 Jan 2015 17:42:03 +0000 |
parents | a1094b51a6c4 |
children | |
files | NOTES cpp/plml.cpp prolog/plml.pl |
diffstat | 3 files changed, 50 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- a/NOTES Thu Feb 06 16:26:30 2014 +0000 +++ b/NOTES Mon Jan 05 17:42:03 2015 +0000 @@ -12,6 +12,9 @@ *** Dec 2004--Nov 2006 +NB. This repository is deprecated. Code is now maintained on GitHub at + https://github.com/samer--/plml + PLML is a foreign interface that enables Matlab to be used as a computational engine from within SWI Prolog. The basic idea is that instead of using the standard is/2 operator to evaluate a certain class of terms, we can
--- a/cpp/plml.cpp Thu Feb 06 16:26:30 2014 +0000 +++ b/cpp/plml.cpp Mon Jan 05 17:42:03 2015 +0000 @@ -260,32 +260,32 @@ } install_t install() { - PL_register_foreign("mlOPEN", 2, (void *)mlOpen, 0); - PL_register_foreign("mlCLOSE", 1, (void *)mlClose, 0); - PL_register_foreign("mlEXEC", 2, (void *)mlExec, 0); - PL_register_foreign("mlWSNAME", 3, (void *)mlWSName, 0); - PL_register_foreign("mlWSALLOC", 2, (void *)mlWSAlloc, 0); - PL_register_foreign("mlWSGET", 2, (void *)mlWSGet,0); - PL_register_foreign("mlWSPUT", 2, (void *)mlWSPut, 0); - PL_register_foreign("mlMX2ATOM", 2, (void *)mlMx2Atom, 0); - PL_register_foreign("mlMX2FLOAT", 2, (void *)mlMx2Float, 0); - PL_register_foreign("mlMX2LOGICAL", 2, (void *)mlMx2Logical, 0); - PL_register_foreign("mlMX2STRING", 2, (void *)mlMx2String, 0); - PL_register_foreign("mlMXINFO", 3, (void *)mlMxInfo, 0); - PL_register_foreign("mlSUB2IND", 3, (void *)mlMxSub2Ind, 0); - PL_register_foreign("mlGETFLOAT", 3, (void *)mlMxGetFloat, 0); - PL_register_foreign("mlGETLOGICAL", 3, (void *)mlMxGetLogical, 0); - PL_register_foreign("mlGETCELL", 3, (void *)mlMxGetCell, 0); - PL_register_foreign("mlGETFIELD", 4, (void *)mlMxGetField, 0); - PL_register_foreign("mlGETREALS", 2, (void *)mlMxGetReals, 0); - PL_register_foreign("mlCREATENUMERIC", 2, (void *)mlMxCreateNumeric, 0); - PL_register_foreign("mlCREATECELL", 2, (void *)mlMxCreateCell, 0); - PL_register_foreign("mlCREATESTRING", 2, (void *)mlMxCreateString, 0); - PL_register_foreign("mlPUTFLOAT", 3, (void *)mlMxPutFloat, 0); - PL_register_foreign("mlPUTFLOATS", 3, (void *)mlMxPutFloats, 0); - PL_register_foreign("mlPUTCELL", 3, (void *)mlMxPutCell, 0); - PL_register_foreign("mlCOPYNOGC", 2, (void *)mlMxCopyNoGC, 0); - PL_register_foreign("mlNEWREFGC", 2, (void *)mlMxNewRefGC, 0); + PL_register_foreign("mlOPEN", 2, (void (*)())mlOpen, 0); + PL_register_foreign("mlCLOSE", 1, (void (*)())mlClose, 0); + PL_register_foreign("mlEXEC", 2, (void (*)())mlExec, 0); + PL_register_foreign("mlWSNAME", 3, (void (*)())mlWSName, 0); + PL_register_foreign("mlWSALLOC", 2, (void (*)())mlWSAlloc, 0); + PL_register_foreign("mlWSGET", 2, (void (*)())mlWSGet,0); + PL_register_foreign("mlWSPUT", 2, (void (*)())mlWSPut, 0); + PL_register_foreign("mlMX2ATOM", 2, (void (*)())mlMx2Atom, 0); + PL_register_foreign("mlMX2FLOAT", 2, (void (*)())mlMx2Float, 0); + PL_register_foreign("mlMX2LOGICAL", 2, (void (*)())mlMx2Logical, 0); + PL_register_foreign("mlMX2STRING", 2, (void (*)())mlMx2String, 0); + PL_register_foreign("mlMXINFO", 3, (void (*)())mlMxInfo, 0); + PL_register_foreign("mlSUB2IND", 3, (void (*)())mlMxSub2Ind, 0); + PL_register_foreign("mlGETFLOAT", 3, (void (*)())mlMxGetFloat, 0); + PL_register_foreign("mlGETLOGICAL", 3, (void (*)())mlMxGetLogical, 0); + PL_register_foreign("mlGETCELL", 3, (void (*)())mlMxGetCell, 0); + PL_register_foreign("mlGETFIELD", 4, (void (*)())mlMxGetField, 0); + PL_register_foreign("mlGETREALS", 2, (void (*)())mlMxGetReals, 0); + PL_register_foreign("mlCREATENUMERIC", 2, (void (*)())mlMxCreateNumeric, 0); + PL_register_foreign("mlCREATECELL", 2, (void (*)())mlMxCreateCell, 0); + PL_register_foreign("mlCREATESTRING", 2, (void (*)())mlMxCreateString, 0); + PL_register_foreign("mlPUTFLOAT", 3, (void (*)())mlMxPutFloat, 0); + PL_register_foreign("mlPUTFLOATS", 3, (void (*)())mlMxPutFloats, 0); + PL_register_foreign("mlPUTCELL", 3, (void (*)())mlMxPutCell, 0); + PL_register_foreign("mlCOPYNOGC", 2, (void (*)())mlMxCopyNoGC, 0); + PL_register_foreign("mlNEWREFGC", 2, (void (*)())mlMxNewRefGC, 0); mx_blob.magic = PL_BLOB_MAGIC; mx_blob.flags = PL_BLOB_UNIQUE;
--- a/prolog/plml.pl Thu Feb 06 16:26:30 2014 +0000 +++ b/prolog/plml.pl Mon Jan 05 17:42:03 2015 +0000 @@ -36,8 +36,8 @@ , multiplot/2 , mhelp/1 - , op(650,fy,`) % quoting things - , op(160,xf,``) % postfix transpose operator + , op(650,fy,'`') % quoting things + , op(160,xf,'``') % postfix transpose operator , op(100,fy,@) % function handles % note slightly reduced precedence of array operators - @@ -57,6 +57,7 @@ % exported after being imported from ops , op(1100,xfx,::) % type specification (esp for arrays) + , op(550,xfx,..) % range of integers ]). @@ -218,11 +219,12 @@ Remove I from ml_expr//2 and add to mx type? */ -:- use_module(library(debug)). :- use_module(library(apply_macros)). -:- use_module(library(utils), [hostname/1]). -:- use_module(library(dcgu)). -:- use_module(library(ops)). +:- use_module(library(dcg_core)). +:- use_module(library(dcg_codes)). + +:- set_prolog_flag(back_quotes,symbol_char). +:- set_prolog_flag(double_quotes,codes). :- op(700,xfx,===). % variable binding/assignment in matlab query :- op(951,fx,??). % evaluate term as matlab @@ -246,6 +248,10 @@ forall(current_engine(Id), ml_close(Id)). +% from utils.pl +bt_call(Do,Undo) :- Do, (true ; once(Undo), fail). +user:goal_expansion( bt_call(Do,Undo), (Do, (true; once(Undo), fail))). + %% matlab_init( -Key, -Cmd:ml_expr) is nondet. % Each user-defined clause of matlab_init/2 causes Cmd to be executed % whenever a new Matlab session is started. @@ -285,7 +291,7 @@ % input and output to files In and Out respectively. (tbd) % * cmd(Cmd:atom) % Call Cmd as the matlab executable. Default is 'matlab' (i.e. search -% for matlab on the PATH).. Can be used to select a different executable +% for matlab on the PATH). Can be used to select a different executable % or to add command line options. % * awt(Flag:bool) % If false (default), call Matlab with -noawt option. Otherwise, Java graphics @@ -429,7 +435,7 @@ %% ml_expr(+Id:ml_eng,+X:ml_expr(A))// is nondet. % Convert Matlab expression as a Prolog term to string representation. -ml_expr(_,\X) --> !, X. +ml_expr(_,\X) --> !, phrase(X). ml_expr(I,$X) --> !, {pl2ml_hook(X,Y)}, ml_expr(I,Y). ml_expr(I,q(X)) --> !, q(stmt(I,X)). ml_expr(I,qq(X)) --> !, qq(stmt(I,X)). @@ -509,6 +515,7 @@ % these are the catch-all clauses which will deal with matlab names, and literals % should we filter on the head functor? +ml_expr(_,A) --> {string(A)}, !, q(str(A)). ml_expr(_,A) --> {atomic(A)}, !, atm(A). ml_expr(I,F) --> {F=..[H|AX]}, atm(H), arglist(I,AX). @@ -986,3 +993,9 @@ {compound(A), A=..[H|T] }, pl2tex(H), paren(seqmap_with_sep(", ",pl2tex,T)). +hostname(H) :- + ( getenv('HOSTNAME',H) -> true + ; setup_call_cleanup(open(pipe(hostname),read,S), + read_line_to_codes(S,Codes), + close(S)), atom_codes(H,Codes) + ).