Index: readme.txt ================================================================== --- readme.txt +++ readme.txt @@ -115,10 +115,26 @@ def x=21 in def x=x+x in x #=> 42. The internal scoping mechanism is a little tricky (this is for coping with the "layer" feature explained below), but I hope that it works as everyone expects in most cases, as long as you don't use the same-name-variables heavily :). +(Experimental) pattern matching is also available. Here is an example. + + def adjSum(lst) + { + case( lst ) + when( {car:x, cdr:{car: y, cdr:z}} ) { {car: x+y, cdr: adjSum(z)} } + when( {car:x, cdr:{}} ) { {car: x, cdr: {}} } + when( {} ) { {} } + }; + +It is expanded to a sequence of if-then-elses prefering the first-match. +Note that {a: _} pattern matches all the tables that have the .a field. +It also matches to {a: 123, b: 456} having extra .b field. So, changing the +order of "when"s in the above code changes the behavior. + + <> Polemy is an untyped functional programming language that has @@ -145,11 +161,11 @@ the @LayerName layer. Other than @value, one other predefined layer exists: @macro. >> @macro( 1+2 ) {pos@value:{lineno@value:3, column@value:9, filename@value:}, is@value:app, - arg@value:{car@value:{pos@value:{lineno@value:3, column@value:9, filename@value:}, + args@value:{car@value:{pos@value:{lineno@value:3, column@value:9, filename@value:}, is@value:int, data@value:1}, cdr@value:{ car@value:{pos@value:{lineno@value:3, column@value:11, filename@value:}, is@value:int, @@ -353,5 +369,24 @@ }; Here, x is a syntax tree but n is an actual integer. If you read carefully, you should get what is going on. Basically, @macro can be considered like quasiquoting and @value to be an escape from it. + + + +<> + + {} 0-ary create-empty-table + . 2-ary table-get + .? 2-ary table-has? + .= 3-ary table-set + + if 3-ary if-then-else + + + - * / % || && 2-ary integer-operations (no short-circuit!) + < > <= >= == != 2-ary generic comparison + + print 1-ary print-to-stdout + + _isint _isstr _isfun _isundefined _istable 1-ary dynamic-type-test +