Forums

get/set/pro

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

get/set/pro

Postby relez » Thu Nov 06, 2008 10:22 am

another of my doubts....

this code, using get

Code: Select all
class Punto
   var _xcoor as int
   var _ycoor as int
   var _zcoor as int

   def init(x as int, y as int, z as int)
      _xcoor = x
      _ycoor = y
      _zcoor = z

   get xcoor from var


and this, using pro

Code: Select all
class Punto
   var _xcoor as int
   var _ycoor as int
   var _zcoor as int

   def init(x as int, y as int, z as int)
      _xcoor = x
      _ycoor = y
      _zcoor = z

   pro xcoor from var


are absolutely equivalent or is there some deep difference?
relez
 
Posts: 69

Re: get/set/pro

Postby Charles » Thu Nov 06, 2008 5:23 pm

"pro" is a read/write property. You can assign to it.

"get" is a read-only property. You cannot assign to it.

class X

# example 1

pro y from var
# is short for the explicit declaration:
pro y as <type of var>
get
return var
set
var = value
# from outside the class you could say:
x = X()
x.y = <expr>
# or within the class:
.y = <expr>

# example 2

get y from var
# is short for the explicit declaration:
pro y as <type of var>
get
return var
# notice the missing "set" part
# you cannot assign to .y
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 20 guests

cron