JSPL

Description

JSPL is a Prolog implemented in JavaScript.

Features

Misfeatures

Source

Source: pl.js

Repo: darcs get http://hub.darcs.net/squirrel/seqcal

Types

Basic types

Compound types

Type name PLJS API type name Prolog type JavaScript type
list list .(_, list); [] array
association list assoc_list list of -(atom, _) object
string string list of number string
XML xml (TODO) DocumentFragment
JSON json (TODO) object or array
arithmetic expression expr (TODO) number

API

I/O

query(term): (varname -> term) | null
Executes the given query. Returns an object mapping variable names to expanded terms representing the first solution encountered, or null if no solution was found.
consult_file(filename): bool
Consult the given file and updates the database. Returns a boolean indicating success.

Special type checks

is_functor(term): bool
Atom / compound term check.
has_args(term {is_functor}): bool
Compound term check.
is_variable(term): bool
Variable check.
is_ground(term): bool
Ground check.

Special type accessors

term_type(term): 'functor' | 'number' | 'variable'
Type of term.
functor_head(term {is_functor}): string
Head of term.
functor_arity(term {is_functor}): integer
Arity of term.
functor_arg(term {is_functor}, integer): term
Argument of term.
functor_args(term {is_functor}): [term]
Arguments of term.
variable_name(term {is_variable}): number
Variable name.

Special type constructors

make_functor(string, [term]): term
Make a compound term.
make_variable(string): term
Make a variable.

Types

is_type(term): bool
Type check. is_assoc_list takes a second argument, which is the separator used.
type_value(term {is_type}): type
Value accessor.
make_type(type): term {is_type}
Term constructor. make_expr does not exist (use make_number instead).

Builtins

Control

,/2
Conjunction.
;/2
Disjunction.
->/2
“Hard” if/then (nonlogical).
*->/2
“Soft” if/then.
\+/1
Negation by failure.
true/0
Truth.
false/0
fail/0
Failure.

Unification

=/2
Unification.
\=/2
Negated unification.

Type checks

var/1
Variable check (nonlogical).
nonvar/1
Negation of var/1.
number/1
Number check.
atom/1
Atom check.
string/1
String check.
atomic/1
Atomic (atom or number) check.
compound/1
Compound term check.
callable/1
Callable (atom or compound term) check.
ground/1
Ground check (nonlogical).

Metaprogramming

=../2
Compound term construction/destruction.
call/n
Meta-call.
atom_codes/2
Atom construction/destruction.
atom_number/2
Number construction/destruction.
findall/3
Aggregation of solutions.
forall/2
Forall operator.
phrase/2
phrase/3
DCG interpreter.

Arithmetic

is/2
Arithmetic evaluation.
=:=/2
=\=/2
</2
>/2
=</2
>=/2
Arithmetic comparison.

I/O

consult/1
Consultation of Prolog code (non-logical). Should only be used at toplevel.
load_bytes(+URL, -Bytes)
Retreive binary resource (as list of numbers) at URL.
load_string(+URL, -String)
Retreive text resource at URL.
load_json(+URL, -JSON)
Retreive JSON resource at URL.
load_xml(+URL, -XML)
Retreive XML resource at URL.

Other

debug/n
Print a debug message using console.log().

Directives

[File0, File1, ].
Consult each listed file via consult/1.
table(Functor(Mode0, Mode1, )).
Table the given predicate in the given mode (each ModeN should be + for input or - for output). Tabling is currently not supported for modes with other than one input argument (though there is no technical reason it could not be). Tabling is implemented using physical, not structural, equality, and is thus only suitable as an optimization, and not for asymptotic speedups. If a predicate is tabled in multiple modes, the applicable mode with the leftmost input argument is favored.

Contact

Chris King