AI Zone Admin Forum Add your forum
Storing the variables in list
 
 

How can i store the $period values in a list or a String ?
The output should be of the following type:

The period stored in the facts were “weekly”, “monthly”,  “yearly” 

Here is my code:

if(^query(direct_s $brand ? ? )) {
@0 = ^query(direct_s $brand ? ? )
@1 = ^query(direct_s $brand ? ? )
^loop($$_len){
$period = next(FACT @0verb )
$time = next(FACT @1object )
if($period != $$type ){
$difference = %fulltime - $time
if($difference < 50){
$period
}
}
}
}

Help me resolve this

 

 
  [ # 1 ]

$text = null
if(^query(direct_s $brand ? ? )) {
@0 = ^query(direct_s $brand ? ? )
@1 = ^query(direct_s $brand ? ? )
^loop($$_len){
$period = next(FACT @0verb )
$time = next(FACT @1object )
if($period != $$type ){
$difference = %fulltime - $time
if($difference < 50){
$value = \" $period \"
$text = ^join($text "_" $value )
}
}
}
}
$text

Is this the right way to implement the above ?

 

 
  [ # 2 ]

a) rather than replicating your queries you can do this with a single query

loop() —no need for $$len which is never initiallized in our code
{
_0 = ^first(@0all)
$period = _1
$time = _2

b) you want a list of periods, the use of JOIN is reasonable, or equivalently a dynamic string like
$text = ^”$text $value”
But I wouldnt use underscore as the separator, i’d use a space.

 

 
  [ # 3 ]

Thanks Bruce, this was useful.

 

 
  login or register to react