Skip to content

Instantly share code, notes, and snippets.

@samaaron
Created January 21, 2009 22:13
Show Gist options
  • Select an option

  • Save samaaron/50243 to your computer and use it in GitHub Desktop.

Select an option

Save samaaron/50243 to your computer and use it in GitHub Desktop.
obj.registerMethod(obj.runtime.newJavaMethod("compares this symbol against the argument, returning -1, 0 or 1 based on which one is lexically larger", new TypeCheckingJavaMethod("<=>") {
private final TypeCheckingArgumentsDefinition ARGUMENTS = TypeCheckingArgumentsDefinition
.builder()
.receiverMustMimic(obj.runtime.symbol)
.withRequiredPositional("other")
.getArguments();
@Override
public TypeCheckingArgumentsDefinition getArguments() {
return ARGUMENTS;
}
@Override
public Object activate(IokeObject method, Object on, List<Object> args, Map<String, Object> keywords, IokeObject context, IokeObject message) throws ControlFlow {
Object arg = args.get(0);
if(!(IokeObject.data(arg) instanceof Symbol)) {
arg = IokeObject.convertToSymbol(arg, message, context, false);
if(!(IokeObject.data(arg) instanceof Symbol)) {
// Can't compare, so bail out
return context.runtime.nil;
}
}
return context.runtime.newNumber(Symbol.getText(on).compareTo(Symbol.getText(arg)));
}
}));
[javac] Compiling 121 source files to /Users/sam/Development/melwin/build/classes
[javac] /Users/sam/Development/melwin/src/main/ioke/lang/Symbol.java:55: local variable obj is accessed from within inner class; needs to be declared final
[javac] .receiverMustMimic(obj.runtime.symbol)
[javac] ^
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment