#!/usr/bin/newlisp

# objectinstantiation - benchmark
#

# define class Toggle

(context 'Toggle)

(define (init start_state)
	(set 'bool start_state))

(define (value)
	bool)

(define (activate)
	(set 'bool (not bool)))

(context 'MAIN)

# subclass Toggle to NthToggle and overwrite methods
 
(new Toggle 'NthToggle)

(context NthToggle)

(define (init start_state max_counter)
	(set 'bool start_state)
	(set 'count_max max_counter)
	(set 'counter 0))

(define (activate)
	(inc 'counter)
	(if (>= counter count_max)
		(begin
			(set 'bool (not bool))
			(set 'counter 0)) 
                counter ))

(context 'MAIN)

# get n from command line

(set 'n (integer (main-args 2)))

(define (main)
	(new Toggle 'toggle)
	(toggle:init true)

	(dotimes (x 5)
		(toggle:activate)
		(if (toggle:value) (println "true") (println "false")))

	(dotimes (x n)
		(new Toggle 'toggle)
		(toggle:init true))

	(println)

	(new NthToggle 'ntoggle)
	(ntoggle:init true 3)

	(dotimes (x 8)
		(ntoggle:activate)
		(if (ntoggle:value) (println "true") (println "false")))

	(dotimes (x n)
		(new NthToggle 'ntoggle)
		(ntoggle:init true 3))
	)

(main)
(exit)




syntax highlighting with newLISP and syntax.cgi