Vaguery / klapaucius

A clean, tested, maintainable Push interpreter written in Clojure.
MIT License
31 stars 2 forks source link

:predicate type #149

Open Vaguery opened 6 years ago

Vaguery commented 6 years ago

The :predicate type is a tuple of

  1. a type (stack name here)
  2. a predicate function with one (or two) arguments of that type, returning a :boolean

For example, here are some one-argument :predicate definitions:

Here are some two-argument :predicates:

Making :predicate objects

For "predicatable" types:

Some special instructions for particular types are feasible (but not included), as well, such as:

What they do

Whenever these instructions fire, the top predicate may want one or two arguments. By convention a :boolean will be used to determine whether a constant will be in the first position or second if there are two arguments in the predicate.

Fancier stuff:

(and so on, by extension)

Vaguery commented 6 years ago

This will probably lead to some refactoring of the DSL, which is a good thing.

Consider bringing predicate functions up into a collection associated with each type, rather than being hard-coded inside the DSL definition. For instance, :scalar-≤ should probably invoke the :scalar type's predicate in its DSL definition. That way, the :predicate object has access to it as well. Also faster.

The comparable aspect might insert these predicates into the type.