[Top][All Lists]

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

Re: Request for help Qt, C++ and guile REPL.

From: Noah Lavine
Subject: Re: Request for help Qt, C++ and guile REPL.
Date: Thu, 20 Jun 2013 10:52:01 -0700

It seems to me that the right way to handle this is to evaluate the Scheme code in a different thread than the user interface, then have the interface continually pull from Scheme's output port.

The other way to do it would be to notice if the Scheme code is a `begin' or similar form and execute the forms (and print the result) one at a time. That's doable (I would compile to Tree-IL first), but it'll still make your entire program sleep for 2 seconds if the user types (sleep 2). But maybe that's all right.


On Thu, Jun 20, 2013 at 9:04 AM, Eduardo Acuña <address@hidden> wrote:

I have found the archives of this mailing list very helpful in the development of a piece of software i'm writing. And i have a few questions about the integration between guile, c++ and the library Qt.

The program in question is a little gui repl, where the user can type guile code in a 'QLineEdit' widget and the evaluation gets printed in a 'QTextBrowser' widget.

I have done this in a very basic way. But the problem is that if the user types:

(begin (display "hello")(sleep 2))

the result gets printed after the 2 seconds. What can i do to get the gui repl more like que standard guile repl?

Thank you in advance.

Eduardo Acuña Yeomans.

the class declaration is this:

class GUIrepl : public QDialog

    QTextBrowser *output_text_browser;
    QLineEdit    *input_line_edit;
    QPushButton  *evaluate_btn;

    SCM my_output_port;
    explicit GUIrepl(QWidget *parent = 0);
private slots:
    void evaluate_expression();

the function that handles the evaluation is this:

void GUIrepl::evaluate_expression()
    QString input;
    SCM result_obj;
    SCM result_str;
    QString to_print;
    input = this->input_line_edit->text();
    result_obj = scm_c_eval_string(input.toStdString().data());
    result_str = scm_object_to_string(result_obj, SCM_UNDEFINED);
    to_print = scm_to_locale_string(result_str);

    SCM out = scm_get_output_string(this->my_output_port);
    QString out_str = scm_to_locale_string(out);
    input = "> "+input;
    if(out_str != "")
    if(to_print != "#<unspecified>")

    scm_truncate_file(this->my_output_port, scm_from_uint16(0));

and in the GUIrepl class constructor i have this:

my_output_port = scm_open_output_string();

The entire proyect is in here:
Its very basic and most of it is in spanish. Its going to be a program where you can write algorithms in scheme for finite state machines, graph theory, grammars and cellular automata and the graphic representation is in c++.

reply via email to

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