From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Noah Lavine Newsgroups: gmane.lisp.guile.user Subject: Re: Request for help Qt, C++ and guile REPL. Date: Thu, 20 Jun 2013 10:52:01 -0700 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=bcaec5299df5ac5ce004df999bb0 X-Trace: ger.gmane.org 1371751592 13396 80.91.229.3 (20 Jun 2013 18:06:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 20 Jun 2013 18:06:32 +0000 (UTC) Cc: Guile Mailing List To: =?ISO-8859-1?Q?Eduardo_Acu=F1a?= Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Thu Jun 20 20:06:34 2013 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UpjFh-0007wB-Hq for guile-user@m.gmane.org; Thu, 20 Jun 2013 20:06:33 +0200 Original-Received: from localhost ([::1]:59662 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpjFh-0003gV-2t for guile-user@m.gmane.org; Thu, 20 Jun 2013 14:06:33 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60829) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Upj3i-000277-2Q for guile-user@gnu.org; Thu, 20 Jun 2013 13:54:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Upj3g-0004Y8-45 for guile-user@gnu.org; Thu, 20 Jun 2013 13:54:09 -0400 Original-Received: from mail-pb0-x232.google.com ([2607:f8b0:400e:c01::232]:37031) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Upj1z-00044g-8V for guile-user@gnu.org; Thu, 20 Jun 2013 13:52:23 -0400 Original-Received: by mail-pb0-f50.google.com with SMTP id wz7so6471828pbc.9 for ; Thu, 20 Jun 2013 10:52:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=sJzgeAarOt+v3oiO9M2RNXqY2RkWQnlmNc2kEx+Fcuo=; b=fX+qsGjdeyOnsL2xLQerqy51fEh6q+8x2IHW/KJlCpH1J0H8/fyJWo+/8pISBSo5nP AMdwE6jYYyInYF3+ukegX7E6HE+qRdJ7HOkkk87eMHlr7jj7TqBGoXYAiJS3tsPUU8FR LVGlmCKu6KA27F4VQ3cBfMMUq4Op2KYUj//c997RFcgESwx337ctVCFRL1dJd4EzcNPI 26rTuQ7sx3C5fZUmceo9fKRdfsLmEIPTs8y8vJgBK/wKiNHMTMFI1R92sERdHZ2XeKI5 O/nESsw5DRlU8fSFDwrh0fy1AEfZf3DLjRM6IxdrZBnrSm6eet2iV48xNSaiNnk8x8V+ JQvw== X-Received: by 10.66.26.179 with SMTP id m19mr12933240pag.4.1371750741593; Thu, 20 Jun 2013 10:52:21 -0700 (PDT) Original-Received: by 10.68.91.1 with HTTP; Thu, 20 Jun 2013 10:52:01 -0700 (PDT) In-Reply-To: X-Google-Sender-Auth: LzX3GCuI0ftHKO6oxy0G81ENbUM X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c01::232 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:10485 Archived-At: --bcaec5299df5ac5ce004df999bb0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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. Best, Noah On Thu, Jun 20, 2013 at 9:04 AM, Eduardo Acu=F1a wr= ote: > Hello! > > 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 question= s > 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=F1a Yeomans. > > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > the class declaration is this: > > class GUIrepl : public QDialog > { > Q_OBJECT > > QTextBrowser *output_text_browser; > QLineEdit *input_line_edit; > QPushButton *evaluate_btn; > > SCM my_output_port; > public: > explicit GUIrepl(QWidget *parent =3D 0); > ~GUIrepl(); > 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 =3D this->input_line_edit->text(); > > result_obj =3D scm_c_eval_string(input.toStdString().data()); > result_str =3D scm_object_to_string(result_obj, SCM_UNDEFINED); > to_print =3D scm_to_locale_string(result_str); > > SCM out =3D scm_get_output_string(this->my_output_port); > QString out_str =3D scm_to_locale_string(out); > > input =3D "> "+input; > this->output_text_browser->append(input); > if(out_str !=3D "") > this->pantalla->append(out_str); > if(to_print !=3D "#") > this->output_text_browser->append(to_print); > > this->input_line_edit->setText(""); > scm_truncate_file(this->my_output_port, scm_from_uint16(0)); > } > > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > and in the GUIrepl class constructor i have this: > > my_output_port =3D scm_open_output_string(); > scm_set_current_output_port(my_output_port); > > > The entire proyect is in here:https://github.com/eduardoacye/Automaton > 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++. > > > --bcaec5299df5ac5ce004df999bb0 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
It seems to me that the right way to handle this is to eva= luate the Scheme code in a different thread than the user interface, then h= ave the interface continually pull from Scheme's output port.

The other way to do it would be to notice if the Scheme co= de is a `begin' or similar form and execute the forms (and print the re= sult) 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 use= r types (sleep 2). But maybe that's all right.

Best,
Noah


On Thu, Jun 20, 20= 13 at 9:04 AM, Eduardo Acu=F1a <eduardo.acye@gmail.com>= wrote:
Hello!

I have found the archives of this mailing list ver= y 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 libra= ry Qt.

The program in question is a little gui repl, where the user can type g= uile code in a 'QLineEdit' widget and the evaluation gets printed i= n 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 pri= nted after the 2 seconds. What can i do to get the gui repl more like que s= tandard guile repl?

Thank you in advanc= e.

=
Eduardo Acu=F1a Yeomans.

= ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
the class declaration is this:

class GUIrepl : public QDialog
{=A0 =A0 Q_OBJECT

=A0 =A0 QTextBrowser *output_text_browser;
=A0= =A0 QLineEdit =A0 =A0*input_line_edit;
=A0 =A0 QPushButton =A0*evaluate= _btn;

=A0 =A0 SCM my_output_port;
public:
=A0 =A0 explicit GUIrepl(QWidget *parent =3D 0);
=A0 =A0 ~GUI= repl();
private slots:
=A0 =A0 void evaluate_expression();
};

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;= ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;=
the function that handles the evaluation is this:

void GUIrepl::eval= uate_expression()
{
=A0 =A0 QString input;
=A0 =A0 SCM result_obj;=
=A0 =A0 SCM result_str;
=A0 =A0 QString to_print;
=A0 =A0
=A0 = =A0 input =3D this->input_line_edit->text();
=A0 =A0
=A0 =A0 result_obj =3D scm_c_eval_string(input.toStdString().dat= a());
=A0 =A0 result_str =3D scm_object_to_string(result_obj, SCM_UNDEFI= NED);
=A0 =A0 to_print =3D scm_to_locale_string(result_str);

=A0 = =A0 SCM out =3D scm_get_output_string(this->my_output_port);
=A0 =A0 QString out_str =3D scm_to_locale_string(out);
=A0 =A0
=A0 = =A0 input =3D "> "+input;
=A0 =A0 this->output_text_brow= ser->append(input);
=A0 =A0 if(out_str !=3D "")
this->= ;pantalla->append(out_str);
=A0 =A0 if(to_print !=3D "#<unspecified>")
this->outp= ut_text_browser->append(to_print);

=A0 =A0 this->input_line_ed= it->setText("");
=A0 =A0 scm_truncate_file(this->my_outp= ut_port, scm_from_uint16(0));
}

;;;;;;;;;;;;;;;;;;;;;;= ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
and in the GUIrepl class constructor i have this:

my_output_port =3D= scm_open_output_string();
scm_set_current_output_port(my_output_port);<= /font>


The entire proyect is in here= :htt= ps://github.com/eduardoacye/Automaton
Its very basic= and most of it is in spanish. Its going to be a program where you can writ= e algorithms in scheme for finite state machines, graph theory, grammars an= d cellular automata and the graphic representation is in c++.



--bcaec5299df5ac5ce004df999bb0--