All pastes #814019 Raw Edit

k4st

public text v1 · immutable
·published 2007-12-12 23:06 UTC
rendered paste body

/* very complicated idea, might not be possible! */
any {f:function, g:function}:
	(f+g)(...) => apply(f, args) + apply(g, args) /* addition */
	(f-g)(...) => f(x) - g(x) /* subtraction */
	(f.g)(...) => f(g(x)) /* composition */
;

/* syntax for quickly typed simple functions and more involved functions by
   returning a language construct 
 */

simple(x) => x+2

complex(x) => do:
	x = x+2
	return x
;

many_args(...) => do:
	return args /* array of arguments */
;

/* example of an iterator */
ArrayIterator(some_array) => for elem in some_array:
	yield elem
;

/* Object from dictionary, dictionaries can be accessed using the '.' if there
   are valid characters in them. Do not confuse this with real objects!
 */
Object(d:dict) => do:
	this = d
	
	if !this.construct:
		this.construct = ()=>null
	;
	
	return (...)=>do:
		apply(this.construct, args)
		return this
	;
;

Iterator = Object({
	construct: (ls:list)=> do:
		
	;,
	
})