This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GSOC | Extending Common Lisp support


On Jun 4, 2012, at 9:37 PM, Jamison Hope wrote:

I just whipped up part of a flet implementation and see the same thing you do
when running interactively in the REPL or with -f, but I see correct behavior
when running a file without -f


New data points:


1. I see the same behavior using regular from Scheme and the stock Kawa 1.12:


$ java -cp kawa-1.12.jar kawa.repl
#|kawa:1|# (define (myfun) 'myfun1)
#|kawa:2|# (define x myfun)
#|kawa:3|# (apply x ())
myfun1
#|kawa:4|# (myfun)
myfun1
#|kawa:5|# (let ((myfun (lambda () 'inner))) (display (myfun)) (display (apply myfun ())))
inner inner
#|kawa:6|# (myfun)
inner
#|kawa:7|# (apply x ())
inner

Hmm.. what if we shadow the variable and not the function:


$ java -cp kawa-1.12.jar kawa.repl
#|kawa:1|# (define (myfun) 'myfun1)
#|kawa:2|# (define x myfun)
#|kawa:3|# (apply x ())
myfun1
#|kawa:4|# (myfun)
myfun1
#|kawa:5|# (let ((x 100)) (display x))
100
#|kawa:6|# x
#<procedure myfun>
#|kawa:7|# (x)
myfun1
#|kawa:8|# (myfun)
myfun1
#|kawa:9|# (let ((x (lambda () 'inner))) (display (x)) (display (apply x ())))
inner inner
#|kawa:10|# (myfun)
inner
#|kawa:11|# (x)
inner

That's interesting. The inner binding only clobbers the original if it's also a procedure. What if we explicitly declare the top level x's type?


$ java -cp kawa-1.12.jar kawa.repl
#|kawa:1|# (define (myfun) 'myfun1)
#|kawa:2|# (define x ::object myfun)
#|kawa:3|# x
#<procedure myfun>
#|kawa:4|# (apply x ())
myfun1
#|kawa:5|# (set! x 100)
#|kawa:6|# x
100
#|kawa:7|# (set! x myfun)
#|kawa:8|# (apply x ())
myfun1
#|kawa:9|# (let ((x 100)) (display x))
100
#|kawa:10|# x
#<procedure myfun>
#|kawa:11|# (x)
myfun1
#|kawa:12|# (let ((x (lambda () 'inner))) (display (x)))
inner
#|kawa:13|# x
#<procedure myfun>
#|kawa:14|# (x)
myfun1

Aha! In that case, things work as we would expect. What if x is declared to be a procedure?


$ rlwrap java -cp kawa-1.12.jar kawa.repl
#|kawa:1|# (define (myfun) 'myfun1)
#|kawa:2|# (define x ::procedure myfun)
#|kawa:3|# myfun
#<procedure myfun>
#|kawa:4|# x
#<procedure myfun>
#|kawa:5|# (set! x (lambda () 'other))
#|kawa:6|# x
#<procedure /dev/stdin:5>
#|kawa:7|# (myfun)
myfun1
#|kawa:8|# (x)
other
#|kawa:9|# (set! x myfun)
#|kawa:10|# x
#<procedure myfun>
#|kawa:11|# (x)
myfun1
#|kawa:12|# (let ((x (lambda () 'inner))) (display x) (display (x)))
#<procedure x> inner
#|kawa:13|# myfun
#<procedure x>
#|kawa:14|# (myfun)
inner

Back through the looking glass. So: what is special about procedure bindings?



-- Jamison Hope The PTR Group www.theptrgroup.com




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]