From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Josh Stratton Newsgroups: gmane.lisp.guile.user Subject: simple example to evaluate strings Date: Fri, 20 Dec 2013 19:57:41 -0800 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7b621d9caf1f3b04ee03666f X-Trace: ger.gmane.org 1387598286 30575 80.91.229.3 (21 Dec 2013 03:58:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 21 Dec 2013 03:58:06 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Dec 21 04:58:13 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 1VuDhd-0006R4-6S for guile-user@m.gmane.org; Sat, 21 Dec 2013 04:58:13 +0100 Original-Received: from localhost ([::1]:52745 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VuDhc-0003hU-DB for guile-user@m.gmane.org; Fri, 20 Dec 2013 22:58:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44152) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VuDhU-0003hP-CA for guile-user@gnu.org; Fri, 20 Dec 2013 22:58:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VuDhT-0003Bd-G7 for guile-user@gnu.org; Fri, 20 Dec 2013 22:58:04 -0500 Original-Received: from mail-ee0-x230.google.com ([2a00:1450:4013:c00::230]:61269) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VuDhT-0003As-8j for guile-user@gnu.org; Fri, 20 Dec 2013 22:58:03 -0500 Original-Received: by mail-ee0-f48.google.com with SMTP id e49so1356468eek.21 for ; Fri, 20 Dec 2013 19:58:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=kkz9DjCU+G8NpZyV2EJPj1QX+s9F/A0TrmFB5oWOJ0Q=; b=PzRa7ukhmM4keZ+KAwmM5Oe0/Bfp95INhLcyVpMp1IpQjPxGgJ6+hGcnij+wnPembG s/Loc5NMzNSQ8afE5PEKXDISiKXaQbrPjFMoLkqhr0b5AXP7XfQcWwcPxkL0mWJr6TzI JeFMn7faX06zsbixYbCiWqlAlbVDFK+RRdxdDFH8uH4FWd/Q3+SHBvyNeaRhvVuX+Hh9 7JPKUbUvvD8mhGjGaSMF42EGEl306ihAjsPrKhwjPZfabM9UgTosqYLYHt2DvhbhaPu9 5epN8Lic/928iMbb+a4r17Yk/5T9EDwrQ7oagKpSD6TPbIWRM2krEwSn+h3af8Wg2ljC HDsg== X-Received: by 10.14.211.69 with SMTP id v45mr927023eeo.75.1387598281906; Fri, 20 Dec 2013 19:58:01 -0800 (PST) Original-Received: by 10.15.76.132 with HTTP; Fri, 20 Dec 2013 19:57:41 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c00::230 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:10936 Archived-At: --047d7b621d9caf1f3b04ee03666f Content-Type: text/plain; charset=ISO-8859-1 I'm completely new to guile and am trying to find a simple example of evaluating a string inside C with some kind of context. I want to execute small self-contained strings provided by a user. I've looked at various examples, but everything I've seen seems uses the shell, which seems like more than I need. The context doesn't need to persist between evals. Is there an example that would allow me to do something like this? float evaluateExpression(char* expression) { if (!initialized) { scm_init_guile(); initialized = true; } // making stuff up here some_guile_context = ... some_guile_context.add("someDef", 5); // add some definitionos the expression might expect to be defined some_guile_response = some_guile_context.eval(expression); // expression might use "someDef" like (* someDef 8) return scm_arg_to_float(scm_guile_response[0]); } --047d7b621d9caf1f3b04ee03666f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
I'm completely new to guile and am trying to find a si= mple example of evaluating a string inside C with some kind of context. =A0= I want to execute small self-contained strings provided by a user. =A0I'= ;ve looked at various examples, but everything I've seen seems uses the= shell, which seems like more than I need. =A0The context doesn't need = to persist between evals. =A0

Is there an example that would allow me to do something like= this? =A0

float evaluateExpression(char* expressi= on)
{
=A0 =A0 if (!initialized) {
=A0 =A0 =A0= =A0 scm_init_guile();
=A0 =A0 =A0 =A0 initialized =3D true;
=A0 =A0 }
=A0 =A0 // making stuff up here
=A0 =A0 some_guile_c= ontext =3D ...
=A0 =A0 some_guile_context.add("someDef"= , 5); // add some definitionos the expression might expect to be defined
=A0 =A0 some_guile_response =3D some_guile_context.eval(expression); /= / expression might use "someDef" like (* someDef 8)
=A0 =A0 return scm_arg_to_float(scm_guile_response[0]); =A0
}
--047d7b621d9caf1f3b04ee03666f--