The following code shows the Pimp language output for some specific input, showing some of the benefits from using such a nice language.
an Account:owner, amount
is positive?
| [master!whatlang]$ rake | |
| (in /Users/administrator/src/whatlang) | |
| /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -Ilib:test "/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb" "test/unit/language_test.rb" "test/unit/sample_text_test.rb" | |
| Loaded suite /Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader | |
| Started | |
| .. | |
| Finished in 0.11417 seconds. | |
| 2 tests, 2 assertions, 0 failures, 0 errors | |
| /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -Ilib:test "/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb" "test/functional/languages_controller_test.rb" "test/functional/sample_texts_controller_test.rb" |
| graph = method( | |
| Origin mimic do( | |
| G = Origin mimic | |
| G {} = macro( | |
| msg = call arguments first | |
| until(msg nil?, | |
| left = msg arguments first name print | |
| connector = msg name print | |
| right = msg next name println | |
| [java] | |
| [java] 1) | |
| [java] Condition Error NoSuchCell in 'DefaultBehavior ? should be possible to create a new LexicalBlock with it' | |
| [java] couldn't find cell '?' on 'ISpec DescribeContext_0x1896D7' (Condition Error NoSuchCell) | |
| [java] | |
| [java] ? call should be nil [/Users/administrator/src/ioke/test/fn_spec.ik:7:6] | |
| [java] /Users/administrator/src/ioke/test/fn_spec.ik:7:6 | |
| [java] /Users/administrator/src/ioke/test/fn_spec.ik:7:6 | |
| [java] | |
| [java] 2) |
| [master!ioke]$ cat frequencies.ik | |
| scriptFrequency = method(text, | |
| count = {} withDefault(0) | |
| text chars each(char, | |
| count[char script] += 1 | |
| ) | |
| count | |
| ) | |
| scriptFrequency("Hi there, how are you?") println |
| ; I'm assuming the Java namespace will have a bunch of interesting utilities for Java interop - naming might change. | |
| Java method = dsyntax("", | |
| [javaCode] | |
| ; use ASM some other bytecode writing API to create a child of JavaMethod or JavaMethod.WithNoArguments, load it and return it | |
| ) | |
| Text lower = Java method("Returns a lower case version of this text", | |
| public Object activate(IokeObject method, IokeObject context, IokeObject message, Object on) throws ControlFlow { | |
| getArguments().getValidatedArgumentsAndReceiver(context, message, on, new ArrayList<Object>(), new HashMap<String, Object>()); |
| use("ispec") | |
| describe("Java", | |
| it("should create new methods on an object", | |
| Java compileMethod(Text, :disemvowel, #[{ | |
| return runtime.newText(Text.getText(on).replaceAll("a|e|i|o|u|A|E|I|O|U", "")); | |
| }]) | |
| "hello, world!" disemvowel should == "hll, wrld!" |
| Refactoring = Origin mimic do( | |
| ifToUnless = method("Returns a message with all the if statements converted to unless statements", message, | |
| unless(message kind == "Message", return) | |
| message each(i, | |
| Refactoring ifToUnless(i next) | |
| i arguments each(j, | |
| Refactoring ifToUnless(j) | |
| ) | |
| ) |
| iik> java:util:ArrayList new | |
| *** - java.lang.IllegalArgumentException: object is not an instance of declaring class (Condition Error JavaException) | |
| sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | |
| sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) | |
| sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) | |
| java.lang.reflect.Method.invoke(Method.java:585) | |
| ioke.lang.JavaMethodJavaMethod.activate(JavaMethodJavaMethod.java:45) | |
| ioke.lang.JavaMethodJavaMethod.activate(JavaMethodJavaMethod.java:38) | |
| ioke.lang.IokeObject.activate(IokeObject.java:932) |
| *.js |