Differences From Artifact [adcd1590f6f5bc80]:
- File
readme.txt
- 2010-11-21 09:53:17 - part of checkin [435fa085ec] on branch trunk - refactored predefined layer names, and filled readme.txt. (user: kinaba) [annotate]
To Artifact [d36ee595e22be49c]:
- File
readme.txt
- 2010-11-21 14:47:32 - part of checkin [c1f2717799] on branch trunk - readme on primitives and pattern-matching (user: kinaba) [annotate]
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 +