在序言中没有和没有call / 2的目标之间有什么区别?

时间:2020-10-19 17:54:23

标签: prolog gnu-prolog

这两个目标有什么区别?

<html>
 <head>
    <script src="https://apis.google.com/js/client.js?onload=onGAPILoad"></script>
  <title></title>
  <script src="background.js"></script>
 </head>
 <body></body>
 </script>
</html>
// Client ID and API key from the Developer Console
var CLIENT_ID = '<my client id>';
var API_KEY = '<my api_key>';

// Array of API discovery doc URLs for APIs used by the quickstart
var DISCOVERY_DOCS = ["https://www.googleapis.com/discovery/v1/apis/drive/v3/rest"];

// Authorization scopes required by the API; multiple scopes can be
// included, separated by spaces.
var SCOPES = 'https://www.googleapis.com/auth/drive.file';

/**
 *  On load, called to load the auth2 library and API client library.
 */

function handleClientLoad() {
  gapi.load('client:auth2', initClient);
}

handleClientLoad();
console.log('test');

/**
 *  Initializes the API client library and sets up sign-in state
 *  listeners.
 */
function initClient() {
    gapi.client.init({
      // Don't pass client nor scope as these will init auth2, which we don't want
      apiKey: API_KEY,
      discoveryDocs: DISCOVERY_DOCS,
    }).then(function () {
      console.log('gapi initialized')
      chrome.identity.getAuthToken({interactive: true}, function(token) {
        gapi.auth.setToken({
          'access_token': token,
          'fields': "nextPageToken, files(id, name)"
        }); 
        console.log(gapi.client.drive)
        gapi.client.drive.files.list({
            'pageSize': 1000,
          }).then(function(response, err) {
            var files = response;
            console.log(files);
            if (files && files.length > 0) {
            console.log(files)
            }
            if(err) {
                console.log(err);
            } 
            else {
              console.log('No files found.');
            }
          });
      })
    }, function(error) {
      console.log('error', error)
    });
  }

它们似乎表现相同? foo(A) :- A, !, fail. foo(A). 的目的是什么?何时有一个重要的例子?

1 个答案:

答案 0 :(得分:1)

由这些代码段生成的输出WAM代码没有差异,如通过发行所证明的那样

gplc -w snippet1.pl
gplc -w snippet2.pl

并检查生成的wbc文件(其中snippetN.pl包含示例代码)。 因此,似乎选择使用哪个程序员。出于可移植性的原因,使用call/1可能会有用。

请回想一下存在{> {1}}且N> 1的情况,如果您要调用一个有参数的目标,这很有用。

出于好奇,这是生成的wam文件: 谓词(foo / 1,1,static,private,monofile,global,2)。

call/N

唯一的区别是该子句的标题,在另一个代码段中读取:

clause(:-(foo(A),','(A,','(!,fail))),[
    allocate(1),
    get_variable(y(0),1),
    put_atom(foo,1),
    put_integer(1,2),
    put_atom(true,3),
    call(('$call')/4),
    cut(y(0)),
    fail]).


clause(foo(_),[
    proceed]).