bugKawa - Bugs: bug #48652, Cannot run Scheme.eval multiple...

 
 

bug #48652: Cannot run Scheme.eval multiple times

Submitter:  Ronald Blaschke <rblasch>
Submitted:  Thu 28 Jul 2016 08:08:32 PM UTC
   
 
Category:  Code generation Severity:  3 - Normal
Item Group:  Run-time exception Status:  Fixed
Privacy:  Public Assigned to:  bothner
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 29 Jul 2016 10:03:28 AM UTC, comment #2: 

Wow, that was fast.  The fix works nicely, thank you very much!

Ronald Blaschke <rblasch>
Thu 28 Jul 2016 11:24:23 PM UTC, comment #1: 

There is actually code to deal with this, by call the setEvalName method in Language.eval.  Unfortunately, setEvalName is called too late ...

I checked in a fix.

Per Bothner <bothner>
Group administrator
Thu 28 Jul 2016 08:08:32 PM UTC, original submission:  

Consider the following example:

import kawa.standard.Scheme;

public class Test {
    public static void main(final String[] args) throws Throwable {
        final Scheme scheme = new Scheme();
        scheme.eval("(define a 1)");
        System.out.println(scheme.eval("a"));
    }
}

This fails with the following exception:

Exception in thread "main" java.lang.NoSuchFieldError: a
at \^string\_.run(<string>:1)
at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:293)
at gnu.expr.ModuleExp.evalModule(ModuleExp.java:212)
at gnu.expr.Language.eval(Language.java:1298)
at gnu.expr.Language.eval(Language.java:1237)
at gnu.expr.Language.eval(Language.java:1219)
at Test.main(Test.java:7)

The problem seems to be that eval first compiles the given String to a class,
which is then executed, but the class name is always "\^string\_".
(Probably derived from the constant "<string>" identifier?)

There are two workarounds that seem to work:

1) Use Scheme#eval(String, Environment), which seems to do things a little different.

2) Use Scheme#eval(InPort) with a unique Path:

import gnu.kawa.io.InPort;
import gnu.kawa.io.Path;
import kawa.standard.Scheme;

import java.io.StringReader;

public class Test {
    public static void main(final String[] args) throws Throwable {
        final Scheme scheme = new Scheme();
        scheme.eval(
            new InPort(new StringReader("(define a 1)"), Path.valueOf("1"))
        );
        System.out.println(scheme.eval(
            new InPort(new StringReader("a"), Path.valueOf("2"))
        ));
    }
}

Currently, I am considering the second workaround, with the String's SHA-1 as Path.

Ronald Blaschke <rblasch>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bothner (Posted a comment)
  • -email is unavailable- added by rblasch (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-07-30 bothner Open/ClosedOpen Closed
    2016-07-28 bothner StatusNone Fixed
        Assigned toNone bothner

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code