On this page:
7.1 Checking for Variables
7.2 Preserving Variables

7 Manipulating Racklog Variables🔗ℹ

Racklog provides special predicates for probing logic variables, without risking their getting bound.

7.1 Checking for Variables🔗ℹ

The goal

(%== X Y)

succeeds if X and Y are identical objects. This is not quite the unification predicate %=, for %== doesn’t touch unbound objects the way %= does. Eg, %== will not equate an unbound logic variable with a bound one, nor will it equate two unbound logic variables unless they are the same variable.

The predicate %/== is the negation of %==.

The goal

(%var X)

succeeds if X isn’t completely bound — ie, it has at least one unbound logic variable in its innards.

The predicate %nonvar is the negation of %var.

7.2 Preserving Variables🔗ℹ

Racklog lets the user protect a term with variables from unification by allowing that term to be treated as a (completely) bound object. The predicates provided for this purpose are %freeze, %melt, %melt-new, and %copy.

The goal

(%freeze S F)

unifies F to the frozen version of S. Any lack of bindings in S are preserved no matter how much you toss F about. Frozen variables will only unify with themselves. For example, in the following query, even though x and y are unbound, their frozen counterparts a and b will not unify with each other:

> (%which (x y frozen a b)
    (%freeze (list x y) (list a b))
    (%= a b))

#f

However, we can unify a frozen variable with itself:

> (%which (x frozen y z)
    (%freeze (list x x) (list y z))
    (%= y z))

'((x . _) (frozen . _) (y . #<frozen>) (z . #<frozen>))

The goal

(%melt F S)

retrieves the object frozen in F into S; the variables in S will be identical to those in the original object. For example:

> (%which (x frozen melted)
    (%freeze (list x x) frozen)
    (%melt frozen melted)
    (%= melted (list 2 2)))

'((x . 2) (frozen #<frozen> #<frozen>) (melted 2 2))

The goal

(%melt-new F S)

is similar to %melt, except that when S is made, the unbound variables in F are replaced by brand-new unbound variables, respecting the existing equivalences between them, for example:

> (%which (x y frozen a b c)
    (%freeze (list x x y) frozen)
    (%melt-new frozen (list a b c))
    (%= a 'red)
    (%= c 'green))

'((x . _)

  (y . _)

  (frozen #<frozen> #<frozen> #<frozen>)

  (a . red)

  (b . red)

  (c . green))

The goal

(%copy S C)

is an abbreviation for (%freeze S F) followed by (%melt-new F C).