view samples/hashset.tp @ 251:2557ce4e671f

Fix a couple of compiler bugs. topenv was getting initialized in multiple places. This resulted in multiple copies of modules getting created which caused problems for macro expansion. Additionally, arguments were not being marked as declared during code generation so assigning to an argument that was not closed over generated invalid C code.
author Michael Pavone <pavone@retrodev.com>
date Fri, 11 Apr 2014 22:29:32 -0700
parents cbc92ee13f35
children
line wrap: on
line source

#{
	main <- {
		inset <- #["foo" "bar" "foobar" 1 2 3]
		notin <- #["baz" "qux" "bazqux" 4 5 6]
		myset <- sets hash
		foreach: inset :idx el {
			myset add: el
		}
		foreach: inset :idx el {
			if: (myset contains?: el) {
				print: "set contains " . el . "\n"
			} else: {
				print: "set doesn't contain " . el . "\n"
			}
		}
		foreach: notin :idx el {
			if: (myset contains?: el) {
				print: "set contains " . el . "\n"
			} else: {
				print: "set doesn't contain " . el . "\n"
			}
		}
	}
}