guile-user
[Top][All Lists]
Advanced

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

simple example to evaluate strings


From: Josh Stratton
Subject: simple example to evaluate strings
Date: Fri, 20 Dec 2013 19:57:41 -0800

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

reply via email to

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