Search code examples
javaeclipsefrege

How to call Frege from Java in Eclipse?


I couldn't find a single out-of-the-box example on this topic.

I succeeded in calling from Frege to Frege, as well as from Java to Java in the same project, but I couldn't get the .java-files to recognize the .fr-files

What steps should I follow to get the following code to work (in Consumer.java)

My basic setup looks like that:

I installed the eclipse-plugin and followed the instructions.

java version "1.7.0_79"

Project Builders in the following order:

Frege builder
Java Builder

Project path:

* src
      - package tutorials
        -- Consumer.java
        -- FregeProducer.fr

* Referenced Libraries
      - fregec.jar

* JRE System Library
      - ...

Consumer:

package tutorials;

public class Consumer {

    public static void main(String[] args) {
        System.out.println("This should be zero: " + FregeProducer.myZero);
    }   
}

FregeProducer:

module FregeProducer where

myZero = 0 

Solution

  • Your setup is all right, as far as I can see. However, it looks like you are running into a Java restriction that does not allow to use classes from the unnamed package in a class that is in a named package.

    What we have here is an attempt to use something in class FregeProducer from within tutorials.Consumer and this is not going to work by Java rules.

    You need to specify the module name as tutorials.FregeProducer. (It is not enough to merely place the source file in the tutorials directory.) Then your unaltered Java code should work, IMHO.

    You can, of course, produce Frege classes in any package you want. For this, you need to move the source file in the corresponding directory and choose an appropriate module name. Remember that the module name (and only the module name, and neither the source file name nor location) determines the fully qualified class name of the compiled class:

    module Foo where    -- creates class Foo in unnamed Java package
    module com.bar.Foo where -- creates class Foo in Java package com.bar