func MaybeArgumentParser(_ *gelo.VM, args *gelo.List, ac uint) gelo.Word { parser := extensions.MakeArgParser(_args_to_spec(args, ac)) return gelo.Alien(func(vm *gelo.VM, args *gelo.List, _ uint) gelo.Word { Args, ok := parser(args) if !ok { return gelo.NewList(gelo.False) } return gelo.NewList(gelo.True, gelo.NewDictFrom(Args)) }) }
func Zip_map(vm *gelo.VM, args *gelo.List, ac uint) gelo.Word { if ac != 2 { gelo.ArgumentError(vm, "zip-map", "key-list value-list", args) } keys := vm.API.ListOrElse(args.Value) values := vm.API.ListOrElse(args.Next.Value) m := make(map[string]gelo.Word) for ; keys != nil || values != nil; keys, values = keys.Next, values.Next { m[keys.Value.Ser().String()] = values.Value } return gelo.NewDictFrom(m) }
func Exportsx(vm *gelo.VM, args *gelo.List, ac uint) gelo.Word { lvls, args := _export_parser(vm, args) m := make(map[string]gelo.Word) for ; args != nil; args = args.Next { //Ns Ser's value anyway so no point in doing it twice k := args.Value.Ser() v := vm.Ns.LookupOrElse(k) m[k.String()] = v } d := gelo.NewDictFrom(m) if !vm.Ns.Inject(lvls, d) { gelo.RuntimeError(vm, "invalid namespace specified") } return d }
func Aggregate(items map[string]interface{}) gelo.Alien { Map := make(map[string]gelo.Word) for k, v := range items { Map[k] = gelo.Convert(v) } d := gelo.NewDictFrom(Map) return gelo.Alien(func(vm *gelo.VM, args *gelo.List, ac uint) gelo.Word { if ac == 0 { return d } item, there := Map[args.Value.Ser().String()] if !there { //XXX this error message could be comprehensible in theory //will fix itself when vm contains name, lineno, etc gelo.ArgumentError(vm, "<an aggregate>", "command args*", args.Next) } return vm.API.TailInvokeCmd(item, args.Next) }) }
func ArgumentParser(_ *gelo.VM, args *gelo.List, ac uint) gelo.Word { parser := extensions.MakeOrElseArgParser(_args_to_spec(args, ac)) return gelo.Alien(func(vm *gelo.VM, args *gelo.List, _ uint) gelo.Word { return gelo.NewDictFrom(parser(vm, args)) }) }