Guest User

Untitled

a guest
Feb 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. Constant := Object clone do (
  2. with := method(msg,
  3. self msg := msg
  4. self activate := method(call message setName(msg asString); msg)
  5. )
  6. )
  7.  
  8. // Lets try it out:
  9. // Make PI a regular number
  10.  
  11. PI := 3.1415926
  12.  
  13. // Make b a method that uses it
  14.  
  15. b := method(PI+PI)
  16.  
  17. writeln(b) // -> 6.283185
  18.  
  19. // Inspect bs "source" code
  20.  
  21. writeln(getSlot("b") code) // -> block(PI +(PI))
  22.  
  23. // Make PI a constant
  24.  
  25. PI := Constant with(3.1415926)
  26.  
  27. writeln(b) // -> 6.283185
  28. writeln(getSlot("b") code) // -> block(3.141593 +(3.141593))
  29.  
  30. // Still works but when we look at the code of b we see that
  31. // the PIs have been replaced with PIs value!!!
Add Comment
Please, Sign In to add comment