Highscalability is Up For Sale
Há 11 meses
Caché ObjectScript with a 2.0 attitude
Method f() {
set x = 6
set m = "write !,"_x ; difference
xecute m
}
class A :
def f(self) :
x = 6
m = "print x"
exec m
x = 9
a = A()
a.f()
set m = "write 2+2"
xecute m
set m = "2+2"
write @m
Class MY.ScopeGotcha Extends %Persistent [ ClassType = persistent, ProcedureBlock ]
{
Method f() {
set x = 6
set m = "write !,x"
xecute m
}
}
set x = 9
set y = ##class(MY.ScopeGotcha).%New()
do y.f()
Where are all the Caché blogs?
Class User.MultiIterator Extends %Persistent
{
Property i As %String;
Property j As %String;
Property k As %String;
Property val As %String;
Method startIterator()
{
set ..i=""
set ..j=""
set ..k=""
}
Method next()
{
if (..i="") {
set ..i=$order(^multi(..i))
quit ..next()
}
if (..j="") {
set ..j=$order(^multi(..i,..j))
quit ..next()
}
set ..k=$order(^multi(..i,..j,..k))
if ..k'="" {
set ..val = $get(^multi(..i,..j,..k))
quit 1
}
set ..j=$order(^multi(..i,..j))
if ..j'="" {
quit ..next()
}
set ..i=$order(^multi(..i))
if ..i'="" {
quit ..next()
}
quit 0
}
}
new it
set it= ##class(User.MultiIterator).%New()
do it.startIterator()
while it.next() {
write !,it.i_","_it.j_","_it.k_" : "_it.val
}
StartIterator(&i,&j,&k)
set i = ""
set j = ""
set k = ""
quit
Next(&i,&j,&k,&val)
if (i="") {
set i=$order(^multi(i))
quit $$Next(.i,.j,.k,.val)
}
if (j="") {
set j=$order(^multi(i,j))
quit $$Next(.i,.j,.k,.val)
}
set k=$order(^multi(i,j,k))
if k'="" {
set val = $get(^multi(i,j,k))
quit 1
}
set j=$order(^multi(i,j))
if j'="" {
quit $$Next(.i,.j,.k,.val)
}
set i=$order(^multi(i))
if i'="" {
quit $$Next(.i,.j,.k,.val)
}
quit 0
test()
new i,j,k,val
do StartIterator(.i,.j,.k)
while $$Next(.i,.j,.k,.val) {
write !, i_","_j_","_k_" = "_val
}
quit
order()
new i,j,k
set i=""
for {
set i=$order(^multi(i))
quit:i=""
set j=""
for {
set j=$order(^multi(i,j))
quit:j=""
set k=""
for {
set k=$order(^multi(i,j,k))
quit:k=""
write !,i_","_j_","_k_" = "_^multi(i,j,k)
}
}
}
quit
StartIterator(&i)
set i = ""
quit
Next(&i,&val)
set i=$order(^xs(i))
if i="" { quit 0 }
set val=$get(^xs(i))
quit 1
test()
new i,val
do StartIterator(.i)
while $$Next(.i,.val) {
write !, i_" : "_val ; example "do something"
}
quit
^Patient("general hospital",324542)=john~smith~malaria
set p = ^Patient("general hospital",324542)
merge gh = ^Patient("general hospital")
kill ^Patient("old hospital")
^PatientDiseaseIndex("malaria","general hospital",324542)
^Patient("general hospital",324542)=john~smith~malaria
^Patient("general hospital",324549)=martha~jones~measles
^Patient("local clinic",2323)=donna~noble~flu
$order(^Patient("general hospital",324542))
$order(^Patient("general hospital"))
$order(^Patient(""))
$order(^Patient("general hospital",""))
$order(^Patient("general hospital",324549))
set hospital=""
for {
set hospital=$order(^Patient(hospital))
quit:hospital=""
set id=""
for {
set id=$order(^Patient(hospital,id))
quit:id=""
set p = $get(^Patient(hospital,id))
... do something with patient p
}
}
for p in Patient {
... do something with patient p
}
^NewPatient(region,hospital,id)
$query(^Patient("general hospital",324542))
set q=$query(^Patient)
for {
if q '= "" {
set p = @q
... do something with patient p
}
set q=$query(@q)
quit:q=""
}
f()
new x
do g()
write x
quit
g()
set x = 5
quit
do f()
if x = 1 && y = 2 {
if (((x=1)&&y)=2) {
kill for { quit:'$data(x) }
kill for { quit:'$data(x) }