Check-in [c1f2717799]
Not logged in
Overview
SHA1 Hash:c1f27177990de5aec2a9e320a884f045b34cc785
Date: 2010-11-21 23:47:32
User: kinaba
Comment:readme on primitives and pattern-matching
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes

Modified readme.txt from [adcd1590f6f5bc80] to [d36ee595e22be49c].

113 113 def f(x) { if(x==0){1}else{x*f(x-1)} } in f(10) #=> 3628800 114 114 yet still the code below also works 115 115 def x=21 in def x=x+x in x #=> 42. 116 116 The internal scoping mechanism is a little tricky (this is for coping with 117 117 the "layer" feature explained below), but I hope that it works as everyone 118 118 expects in most cases, as long as you don't use the same-name-variables heavily :). 119 119 120 +(Experimental) pattern matching is also available. Here is an example. 121 + 122 + def adjSum(lst) 123 + { 124 + case( lst ) 125 + when( {car:x, cdr:{car: y, cdr:z}} ) { {car: x+y, cdr: adjSum(z)} } 126 + when( {car:x, cdr:{}} ) { {car: x, cdr: {}} } 127 + when( {} ) { {} } 128 + }; 129 + 130 +It is expanded to a sequence of if-then-elses prefering the first-match. 131 +Note that {a: _} pattern matches all the tables that have the .a field. 132 +It also matches to {a: 123, b: 456} having extra .b field. So, changing the 133 +order of "when"s in the above code changes the behavior. 134 + 135 + 120 136 121 137 122 138 <<Basic Features>> 123 139 124 140 Polemy is an untyped functional programming language that has 125 141 - integers: 0, 123, 456666666666666666666666666666666666666789, ... 126 142 - strings: "hello, world!\n", ... ................................................................................ 143 159 144 160 Here you can see that @LayerName( Expression ) executes the inner Expression in 145 161 the @LayerName layer. Other than @value, one other predefined layer exists: @macro. 146 162 147 163 >> @macro( 1+2 ) 148 164 {pos@value:{lineno@value:3, column@value:9, filename@value:<REPL>}, 149 165 is@value:app, 150 - arg@value:{car@value:{pos@value:{lineno@value:3, column@value:9, filename@value:<REPL>}, 166 + args@value:{car@value:{pos@value:{lineno@value:3, column@value:9, filename@value:<REPL>}, 151 167 is@value:int, 152 168 data@value:1}, 153 169 cdr@value:{ 154 170 car@value:{pos@value:{lineno@value:3, column@value:11, filename@value:<REPL>}, 155 171 is@value:int, 156 172 data@value:2}, 157 173 cdr@value:{}}}, ................................................................................ 351 367 pow(@macro(x),10) 352 368 ) 353 369 }; 354 370 355 371 Here, x is a syntax tree but n is an actual integer. If you read carefully, 356 372 you should get what is going on. Basically, @macro can be considered like 357 373 quasiquoting and @value to be an escape from it. 374 + 375 + 376 + 377 +<<Primitives>> 378 + 379 + {} 0-ary create-empty-table 380 + . 2-ary table-get 381 + .? 2-ary table-has? 382 + .= 3-ary table-set 383 + 384 + if 3-ary if-then-else 385 + 386 + + - * / % || && 2-ary integer-operations (no short-circuit!) 387 + < > <= >= == != 2-ary generic comparison 388 + 389 + print 1-ary print-to-stdout 390 + 391 + _isint _isstr _isfun _isundefined _istable 1-ary dynamic-type-test 392 +