mark richardson wrote :
Hi,

I have been trying to understand something unusual and I wonder if anyone can shed any light on this.

If I feed this program

declare
{Browse {Plus 5 5}}
fun {Plus A B} A+B end

by buffer, the program blocks on the Browse procedure (I assume because 'Plus' has not yet been determined?)

If however, I now feed a new line

fun {Plus A B} A+B+A end

I get an error saying that Plus has already been defined (which initially seems sensible)

Tell: <P/3 Plus> = <P/3 Plus>

but, and here is the confusing thing, the browser now displays the result from the second function????

There are a couple of contradictions I don't understand here:-

1 . Browse can't display the result of {Plus} because it hasn't been determined yet - {Plus} has been determined enough to tell me I've made an error when I try to redefine it. 2. If redefining {Plus} is an error why does Browse show the result from the new function?

If anyone can help I'd be most appreciative.

Regards

Mark

Hello,

Let's consider the Core syntax (kernel language) translation of your experiment.
The first part translates to:

declare Plus in
local UnnestApply1 UnnestApply2 UnnestApply3 in
  UnnestApply2 = 5
  UnnestApply3 = 5
  {Plus UnnestApply2 UnnestApply3 UnnestApply1} %1
  {Browse UnnestApply1}
  proc {Plus A B Result1}
     Result1 = A + B
  end
end


And the second to:

proc {Plus A B Result1}
  local UnnestApply1 in
     UnnestApply1 = A + B
     Result1 = UnnestApply1 + A
  end
end


Now, when you feed the first part, it blocks on the line marked %1
since Plus is unbound. But note that the variable Plus is declared.

When you feed the second part, it binds the variable Plus to the second procedure. This allows the first feed to continue execution, browsing the result 15. Only then is the definition of the second procedure executed, which of course fail since the variable is already bound (to the second procedure).

Yves
_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to