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 Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/terms.js.

    30     30   /* Atom, Variable, Compound
    31     31    * Constructors for atoms, variables, and compound terms. */
    32     32   
    33     33   /* Atoms used to be a thing in their own right. Now they are just 0-arity
    34     34      compounds (for internal consistency), but we retain the constructor for them
    35     35      for convenience. */
    36     36   terms.Atom = function(a) { 
    37         -    if(typeof(a) !== "string")
    38         -        throw core.errors.InvalidTerm;
    39         -
    40         -    return new terms.Compound(a,[]);
           37  +    return new terms.Compound(a.toString(),[]);
    41     38   }
    42     39   
    43     40   
    44     41   // Note that variables are compared using *reference* equality, not name
    45     42   // equality. It is entirely possible for two variables to have the same name, 
    46     43   // and yet represent different variables.
    47     44   terms.Variable = function(v) { 
................................................................................
    76     73   };
    77     74   
    78     75   
    79     76   terms.Compound = function(head, body) {
    80     77   
    81     78       // Validate term structure. The body must already be terms, and thus will
    82     79       // already have been validated during their own construction.
    83         -    if(typeof head !== "string")
    84         -        throw core.errors.InvalidTerm;
           80  +    head = head.toString();
    85     81   
    86     82       // Normalize body to be a list.
    87     83       body = (body === undefined || body === null) ? [] : body;
    88     84   
    89     85       // Check the body for valid terms as well. Note that this is a single-level
    90     86       // check
    91     87       if(!body.every(terms.isTerm))
................................................................................
   310    306   
   311    307       function stringify(t) {
   312    308           if(t.isVariable())
   313    309               return " ' " + t.name + "' ";
   314    310           else if(t.isAtom())
   315    311               return " '" + t + "' ";
   316    312           else if(t.isList())
   317         -            return "[ " + stringify_list(l) + " ]";
          313  +            return "[ " + stringify_list(t) + " ]";
   318    314           else if(t.isCompound())
   319    315               return " '" + t.head + 
   320    316                      "'(" + t.body.map(stringify).join(" , ") + ") ";
   321    317       }
   322    318   
   323    319       return stringify(t);
   324    320   }