Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save samaaron/50237 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)));
}
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment