unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Josh Stratton <strattonbrazil@gmail.com>
To: guile-user@gnu.org
Subject: simple example to evaluate strings
Date: Fri, 20 Dec 2013 19:57:41 -0800	[thread overview]
Message-ID: <CAPVmgLgYTLByWjfHCZ-AfO_TJwo9umEA-wLUiViwik9P2kp1AA@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 898 bytes --]

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]);
}

[-- Attachment #2: Type: text/html, Size: 1164 bytes --]

             reply	other threads:[~2013-12-21  3:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-21  3:57 Josh Stratton [this message]
2013-12-21 13:06 ` simple example to evaluate strings Paul Emsley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPVmgLgYTLByWjfHCZ-AfO_TJwo9umEA-wLUiViwik9P2kp1AA@mail.gmail.com \
    --to=strattonbrazil@gmail.com \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).