1

I am trying to programmatically construct arguments to functional select call having the form:

?[ `t; () ; groupBy; ()]

The problematic part is groupBy, which should be a dictionary.

Suppose the objective is to arrive at the parse tree in the form:

parse "select by sym,month:`date$dt.month from t"

I start constructing the by part with:

groupBy: enlist[`sym]!enlist(`sym)

Then I try to append the month part of the group by statement (note that periodicity is parameterised):

per: `month / monthly periodicity
groupBy,: {enlist[x]!enlist[ $[x = `day; 
                               `dt; 
                               $[x=`month;
                                 ((parse "select by month:`date$dt.month from x")@3)@`month
                                 ;` sv (`dt,x)]
                               ]]
          }[per]

However, that throws type error. What goes wrong?

Daniel Krizian
  • 4,586
  • 4
  • 38
  • 75
  • 2
    I think it doesn't like the compound assignment "groupBy,:{...}". Try "groupBy:groupBy,{...} – terrylynch May 12 '15 at 12:08
  • Indeed, `groupBy:groupBy,{...} ` works. Strange, as I thought the two are equivalent. Thank you very much! Would you mind copying that into the answer, and I will accept it. – Daniel Krizian May 12 '15 at 12:15

1 Answers1

3

I think it doesn't like the compound assignment

groupBy,:{...} 

Try

groupBy:groupBy,{...}

The difference is that in the first case it's trying to directly alter the data in memory without creating a copy, whereas in the second case it is creating a copy of the data in memory and then re-assigning it to that variable. Perhaps the compound assignment only works when the types are uniform

terrylynch
  • 11,844
  • 13
  • 21
  • 2
    I think that is because of type difference in value of groupy and new temp dictionary. As per wiki: "Amend enforces strict type matching with simple lists, since the result must be placed back into the list". value (groupby) has symbol list type and new dict has general type. If you do it reverse (temp dict,:groupby) it will work but results might be different. – Rahul May 12 '15 at 13:31