guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Undefined simultaneous definitions


From: Utkarsh Singh
Subject: Undefined simultaneous definitions
Date: Mon, 20 Sep 2021 08:45:48 +0530

Hi Guilers,

First of all I would like to thank you for maintaining this wonderful
programming language.

SICP Section 4.3 defines a non-deterministic (or ambiguous) evaluator
which helps in non-deterministic computing.  In implementing such an
evaluator I am having difficulty in defining `letrec' special form and
procedure definition with simultaneous internal definition.  For
example, consider the following REPL session:

;;; Amb-Eval input:
(define (findout32 x)
  (letrec ((even?
            (lambda (n)
              (if (= n 0)
                  #t
                (odd? (- n 1)))))
           (odd?
            (lambda (n)
              (if (= n 0)
                  #f
                (even? (- n 1))))))
    (cond
     ((even? x) 20)
     ((odd? x) 30)
     (else 40))))

;;; Starting a new problem 
;;; Amb-Eval value:
ok

;;; Amb-Eval input:
(findout32 10)

;;; Starting a new problem ERROR: In procedure scm-error:
Unassigned variable -- LOOKUP-VARIABLE-VALUE odd?

I tried to debug this issue using `trace' command and it seems that my
evaluator is *not* correctly evaluating sequence of `set!' expression
generated by `scan-out-defines' (see source file for definition).

For now I am going to attach the following files in order to
sufficiently explain the problem:

1. ambeval.scm (Implementation of evaluator)
2. test-ambeval.scm (Test suite for evaluator)
3. test-letrec.log (Erroneous log generated by test suite for `letrec')

Thank you,
Utkarsh Singh

-- 
Utkarsh Singh
https://utkarshsingh.xyz/

Attachment: ambeval.scm
Description: Evaluator

Attachment: ambeval-test.scm
Description: Test suite

Attachment: test-letrec.log
Description: Letrec log


reply via email to

[Prev in Thread] Current Thread [Next in Thread]