This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
| /** | |
| * If applicable, deducts the rewards amount from the current price, | |
| * rewards points on the booking and returns the charge amount for the user's card. | |
| */ | |
| public CCAmt doRewards(String pos, CCAmt currentCCAmt, | |
| rewardsInfo rewardsInfo, | |
| String PNR, | |
| XFactor xFactor, | |
| boolean isSpecialInventory, | |
| Money sellRateForSpecialInventory |
| stmt can have id, comment and fact attached | |
| function can have same, but is a collection of stmts | |
| program can have same, but is a collection of functions | |
| built into the language def is a list creator | |
| also built in is a hierarchical fact analyzer, ie, all facts | |
| presented at a collection level are taken to represent reality | |
| at that level. higher levels areexpected to have a "higher" understanding and therefore not applicable; similarly lower | |
| list-of(XXX) := <list containing objects of type XXX> |
| ometa JackParser { | |
| id = string, | |
| comment = string, | |
| fact = string, | |
| name = string, | |
| operator = name, | |
| arg = name | expr, | |
| header = [id:id comment:comment fact:fact] -> { id:id, comment:comment, fact:fact}, |
| // yaml version of the same | |
| - object: function | |
| id: | |
| comment: | |
| fact: 'multiplies(x,y)' | |
| name: multipliesTwo | |
| expr: | |
| - object: expr | |
| id: | |
| comment: |
| public static int maxProd(int[] input){ | |
| int max1 = max2 = max3 = java.lang.Integer.MIN_VALUE; | |
| int min1 = min2 java.lang.Integer.MAX_VALUE; | |
| for(int i=0; i<input.length;i++){ | |
| // recalc the new max3 numbers | |
| int val= input[i]; | |
| if(val > max1){ | |
| max2 = max1; // dont lose the old max1 | |
| max1=val; |
| public static int maxProd(int[] input){ | |
| int max1 = max2 = max3 = java.lang.Integer.MIN_VALUE; | |
| int min1 = min2 java.lang.Integer.MAX_VALUE; | |
| for(int i=0; i<input.length;i++){ | |
| int val= input[i]; | |
| range calcmax{ | |
| if(val > max1){ | |
| max2 = max1; // dont lose the old max1 |
| Object.metaClass.of = { delegate[0](delegate[1](it))} | |
| Object.metaClass.the = { clos -> [delegate[0], clos]} | |
| show = [ {println it} ] | |
| square_root = { Math.sqrt(it) } | |
| please = {it} | |
| please show the square_root of 100 |
| //try1 | |
| println please.class.name | |
| println please.delegate | |
| println show | |
| println show.class.name | |
| println show.delegate | |
| println please(show).delegate | |
| println please(show).the(square_root) |
| please(show).the(square_root).of(100) | |
| ={it}([{println it}]).{clos -> [delegate[0],clos]}(square_root).{delegate[0](delegate[1](it))}(100) | |
| =[{println it}].[delagate[0], square_root].[delegate[0](delegate[1](100))] | |
| = [{println it}, square_root].[delegate[0](delegate[1](100))] | |
| =println(square_root(100)) | |