guile-user
[Top][All Lists]
Advanced

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

4 questions about error conditions.


From: 9
Subject: 4 questions about error conditions.
Date: Thu, 27 Sep 2001 23:02:54 +0900 (KST)

Hi, everyone.

My program reads a guile expression from STDIN and evaluate it using
gh_eval_str(). But if any user gives wrong expression (e.g. just ")"),
gh_eval_str() prints error message like below and *terminates* my program:

    ERROR: In procedure read:
    ERROR: unexpected ")"

What I want to know is:

(1) Is their any way to prevent gh_eval_str() or gh_eval_file() from
    terminating a program?

(2) If so, I suppose that gh_eval_str() or gh_eval_file() might return a
    error value. What is it, then? If there exists some constant like
    SCM_ERROR, I think that I could use them like this:

    if (gh_eval_str(line) == SCM_ERROR) {
        /* ignore any error message and read a next line. */
    }

    Is their any symbol like SCM_ERROR? I've read the guile info pages,
    but I couldn't find any mention about error conditions.

(3) `gh_eval_str()' will terminate my program if the evaluation is 
    interpreted to "(quit)" procedure. But that's not what I want because
    I want the guile interpreter come back to my program if an expression
    is evaluated (quit). So I programmed my code like this:

    printf("guile> ");
    while (fgets(line, LINE_MAX, stdin)) {
        if (strstr(line, "(quit)"))
            break;    /* finish evaluation and return to other stuff. */
        gh_eval_str(line);
        printf("guile> ");
    }

    But this is not perfect, since if user type like this:

    (define terminate (lambda () (quit)))
   
    It should not terminate interpretation.

    In this case, I want the guile interpreter to come back to my code
    if user typed "(quit)" or "(terminate)".

(4) My program reads a start-up script file and evaluate before doing
    anything.  And the start-up script file loads several other script
    files using (load ..) procedure. If one of the script file has an
    error, the guile interpreter just prints error messages like this:

    ERROR: In procedure read:
    ERROR: unexpected ")"

    Is there any way to provide malformed script filename and line number?

Any comment or advice is appriciated. and forgive my poor English. ;-)



-- 
C-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Korean version: http://pcrc.hongik.ac.kr/~cinsk/





reply via email to

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