Check-in [808229ea10]

Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fixed a couple bugs in the handling of non-string atoms (coerce to string).
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:808229ea10a9ca07abebc79d96941e4e0bab6e20
User & Date: andy 2015-04-15 19:43:06
Context
2015-04-15
19:51
Fixed a bug in the conversion to Prolog of numeric atoms (0 vs. '0'). check-in: 76226466c7 user: andy tags: trunk
19:43
Fixed a couple bugs in the handling of non-string atoms (coerce to string). check-in: 808229ea10 user: andy tags: trunk
19:42
Fixed a bug in case analysis of atomic goals. check-in: afb3b37674 user: andy tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/terms.js.

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
..
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
...
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/* Atom, Variable, Compound
 * Constructors for atoms, variables, and compound terms. */

/* Atoms used to be a thing in their own right. Now they are just 0-arity
   compounds (for internal consistency), but we retain the constructor for them
   for convenience. */
terms.Atom = function(a) { 
    if(typeof(a) !== "string")
        throw core.errors.InvalidTerm;

    return new terms.Compound(a,[]);
}


// Note that variables are compared using *reference* equality, not name
// equality. It is entirely possible for two variables to have the same name, 
// and yet represent different variables.
terms.Variable = function(v) { 
................................................................................
};


terms.Compound = function(head, body) {

    // Validate term structure. The body must already be terms, and thus will
    // already have been validated during their own construction.
    if(typeof head !== "string")
        throw core.errors.InvalidTerm;

    // Normalize body to be a list.
    body = (body === undefined || body === null) ? [] : body;

    // Check the body for valid terms as well. Note that this is a single-level
    // check
    if(!body.every(terms.isTerm))
................................................................................

    function stringify(t) {
        if(t.isVariable())
            return " ' " + t.name + "' ";
        else if(t.isAtom())
            return " '" + t + "' ";
        else if(t.isList())
            return "[ " + stringify_list(l) + " ]";
        else if(t.isCompound())
            return " '" + t.head + 
                   "'(" + t.body.map(stringify).join(" , ") + ") ";
    }

    return stringify(t);
}







<
<
<
|







 







|
<







 







|







30
31
32
33
34
35
36



37
38
39
40
41
42
43
44
..
73
74
75
76
77
78
79
80

81
82
83
84
85
86
87
...
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/* Atom, Variable, Compound
 * Constructors for atoms, variables, and compound terms. */

/* Atoms used to be a thing in their own right. Now they are just 0-arity
   compounds (for internal consistency), but we retain the constructor for them
   for convenience. */
terms.Atom = function(a) { 



    return new terms.Compound(a.toString(),[]);
}


// Note that variables are compared using *reference* equality, not name
// equality. It is entirely possible for two variables to have the same name, 
// and yet represent different variables.
terms.Variable = function(v) { 
................................................................................
};


terms.Compound = function(head, body) {

    // Validate term structure. The body must already be terms, and thus will
    // already have been validated during their own construction.
    head = head.toString();


    // Normalize body to be a list.
    body = (body === undefined || body === null) ? [] : body;

    // Check the body for valid terms as well. Note that this is a single-level
    // check
    if(!body.every(terms.isTerm))
................................................................................

    function stringify(t) {
        if(t.isVariable())
            return " ' " + t.name + "' ";
        else if(t.isAtom())
            return " '" + t + "' ";
        else if(t.isList())
            return "[ " + stringify_list(t) + " ]";
        else if(t.isCompound())
            return " '" + t.head + 
                   "'(" + t.body.map(stringify).join(" , ") + ") ";
    }

    return stringify(t);
}