#!/usr/bin/newlisp

# method call  - benchmark
#
# this is almost identical to objinst.lsp
# but here method call is measured instead of
# object creation / instantiation

# 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 n)
		(toggle:activate)
		(set 'val toggle:value))
		
	(if (toggle:value) (println "true") (println "false"))

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

	(dotimes (x n)
		(ntoggle:activate)
		(set 'val ntoggle:value))
		
	(if (ntoggle:value) (println "true") (println "false"))
	)

(main)
(exit)




syntax highlighting with newLISP and syntax.cgi