Skip to content

readme example hangs when storing intermediate #6

@anandijain

Description

@anandijain
; Counting with Combinators
; First we define the sk rules
(set sk_rules (list (rule (((s (pattern x (blank))) (pattern y (blank))) (pattern z (blank))) ((x z) (y z))) (rule ((k (pattern x (blank))) (pattern y (blank))) x)))

; now we define the rule for incrementing
(set succ (s ((s (k s)) k)))

; now we apply succ to (s k) 10 times
(Nest succ (s k) 10)

; now we apply [s][k] to the result and do fixed-point replacement using our SK-rules
(rr (((Nest succ (s k) 10) s) k) sk_rules)
; you should see:
; (s (s (s (s (s (s (s (s (s (s k))))))))))

the above works, but if we store the result of Nest in x and try to rr with x, it hangs indefinitely

(set sk_rules (list (rule (((s (pattern x (blank))) (pattern y (blank))) (pattern z (blank))) ((x z) (y z))) (rule ((k (pattern x (blank))) (pattern y (blank))) x)))

(set succ (s ((s (k s)) k)))

(set x (Nest succ (s k) 10))

(rr ((x s) k) sk_rules)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions