Re: Java enum in JPL

Paul Singleton <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Organization Jambusters Ltd
Message-ID <[email protected]>
It seems Java 1.5+ enums are syntactic sugar for constructs which Java 
1.4 (and hence JPL) understands: given

public class Foo {
     public enum Bar {
         UP, DOWN
     }
     public static String legend(Bar x) {
         switch(x) {
             case UP:
                 return "upwards";
             case DOWN:
                 return "downwards";
             default:
                 return "?";
         }
     }
}

we can do

   1 ?- jpl_get('Foo$Bar', 'UP', X).
   X = @('J#00000000000056425292').

or

   1 ?- jpl_get('Foo$Bar', 'UP', X), jpl_call('Foo', legend, [X], S).
   X = @('J#00000000000056425292'),
   S = upwards.

where X is bound to the nominated enum constant (actually an object 
reference), then passed as an arg to legend/1

Paul Singleton


On 18/07/2013 12:14, Jerry wrote:
> All,
>
> I have been researching the web to find out how to create enum variables in
> JPL. So far I have found now examples and trial and error has been mostly
> error. Here is the fragment I need to emulate from SWI Prolog:
>
>
>      ArrayList< String > namesOfInterest = new ArrayList< String >();
>
>      AppTierSourceUsageRequestMessage.MessageType messageType =
>        getInvokeArgs( args, namesOfInterest );
>
>      ArrayList< String > result = null;
>
>      try {
>        result = invoke( messageType, namesOfInterest );
>      }
>      catch( CannotProcessException ex ) {
>        System.out.println( "MakeAppTierRequest.invoke() failed! Got ex=" +
> ex );
>        System.exit( 1 );
>      }
>
>
> MessageType is an enum. I know how to make an array of strings as needed
> for the 2nd argument of invoke but not so much luck with the first
> argument. I want to pass the constant enum value:
> GET_FILE_NAMES_AND_TOKEN_NAMES.
>
> My call so far looks like:
>
>      jpl_call( 'com.xxxxxx.xxxxx.messages.MakeAppTierRequest', invoke,
> ['????',Ac], F),
> Ac is an array of Strings and seems to be correct.
>
>
> Any thoughts or example uses of enum variables in JPL would be appreciated!
>
> Thanks!
>
> Jerry
> -------------- next part --------------
> HTML attachment scrubbed and removed
> _______________________________________________
> SWI-Prolog mailing list
> [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.