Exemple #1
0
        /// <summary>
        /// Enables MAP and FOREACH to be applied to AssocArrayItem.
        ///
        /// When mapping a word over an AssocArrayItem, the MAP word
        /// will call Items, push each item onto the stack, and then
        /// execute the mapping word. The items for an AssocArrayItem
        /// will be RecordItems with fields "key" and "value" corresponding
        /// to each record.
        /// </summary>
        public List <RecordItem> Items()
        {
            List <RecordItem> result = new List <RecordItem>();

            foreach (KeyValuePair <string, StackItem> entry in this.values)
            {
                RecordItem rec = new RecordItem();
                rec.SetValue("key", new StringItem(entry.Key));
                rec.SetValue("value", entry.Value);
                result.Add(rec);
            }
            return(result);
        }
Exemple #2
0
        // ( values fields -- record )
        public override void Execute(Interpreter interp)
        {
            ArrayItem fields = (ArrayItem)interp.StackPop();
            ArrayItem values = (ArrayItem)interp.StackPop();

            RecordItem result = new RecordItem();

            for (int i = 0; i < fields.ArrayValue.Count; i++)
            {
                StringItem keyItem = (StringItem)fields.ArrayValue[i];
                result.SetValue(keyItem.StringValue, values.ArrayValue[i]);
            }
            interp.StackPush(result);
        }