YAPC::EU 2018 Glasgow Update!
This commit is contained in:
parent
22f33d4004
commit
4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions
44
Task/Delegates/Phix/delegates-1.phix
Normal file
44
Task/Delegates/Phix/delegates-1.phix
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
enum OTHER, OPERATION
|
||||
|
||||
function operation(object o)
|
||||
integer rid = o[OPERATION]
|
||||
if rid!=NULL then
|
||||
return call_func(rid,{})
|
||||
end if
|
||||
return "no implementation"
|
||||
end function
|
||||
|
||||
function xthing()
|
||||
return "default implementation"
|
||||
end function
|
||||
|
||||
function newX()
|
||||
return {1,routine_id("xthing"),2}
|
||||
end function
|
||||
|
||||
function newY()
|
||||
object res = newX()
|
||||
res[OTHER] = "something else"
|
||||
-- remove delegate:
|
||||
res[OPERATION] = NULL
|
||||
return res
|
||||
end function
|
||||
|
||||
function zthing()
|
||||
return "delegate implementation"
|
||||
end function
|
||||
|
||||
function newZ()
|
||||
object res = newX()
|
||||
-- replace delegate:
|
||||
res[OPERATION] = routine_id("zthing")
|
||||
return res
|
||||
end function
|
||||
|
||||
object x = newX(),
|
||||
y = newY(),
|
||||
z = newZ()
|
||||
|
||||
?operation(x)
|
||||
?operation(y)
|
||||
?operation(z)
|
||||
7
Task/Delegates/Phix/delegates-2.phix
Normal file
7
Task/Delegates/Phix/delegates-2.phix
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
?operation(x)
|
||||
try -- (since rid=NULL check commented out)
|
||||
?operation(y)
|
||||
catch e
|
||||
?"oops, no implementation"
|
||||
end try
|
||||
?operation(z)
|
||||
Loading…
Add table
Add a link
Reference in a new issue