Hi Shawn,
On Sep 23, 2012, at 12:43 , Shawn Morel wrote:
> (define make-higher-order (fn (predicate)
> (fn (arg)
> (if (not (predicate arg)) (print "FAILED higher-order function test")))))
>
> ((make-higher-order
> (fn (arg1)
> (= "hello higher-order" arg1)))
> "hello higher-order")
Which evaluator are you using to run your test? What is the definition of 'fn'?
I can't make this fail. Here's my program, which also tries to test the
intentional sharing or non-sharing of a variable between two closures.
(define-function make-higher-order (predicate)
(lambda (arg) (predicate arg)))
(if ((make-higher-order (lambda (arg1) (= "hello higher-order" arg1))) "hello
higher-order")
(println "result is true")
(println "result is false"))
(if ((make-higher-order (lambda (arg1) (= "hello higher-order" arg1))) "goodbye
higher-order")
(println "result is true")
(println "result is false"))
(let* ((n 0)
(f (make-higher-order (lambda (x) (= x (incr n)))))
(g (make-higher-order (lambda (x) (= x (incr n))))))
(println "A "(f 3)" "(g 3))
(println "A "(f 3)" "(g 3))
(println "A "(f 3)" "(g 3)))
(let* ((n 0)
(f (make-higher-order (lambda (x) (= x (incr n)))))
(g (let ((n 0)) (make-higher-order (lambda (x) (= x (incr n)))))))
(println "B "(f 3)" "(g 3))
(println "B "(f 3)" "(g 3))
(println "B "(f 3)" "(g 3))
(println "B "(f 3)" "(g 3))
(println "B "(f 3)" "(g 3)))
The output from which is:
result is true
result is false
A () ()
A t ()
A () ()
B () ()
B () ()
B t t
B () ()
B () ()
Regards,
Ian
_______________________________________________
fonc mailing list
[email protected]
http://vpri.org/mailman/listinfo/fonc