Add new util vals.MakeListFromStrings.

This commit is contained in:
Qi Xiao 2021-12-30 13:09:18 +00:00
parent c46fd60270
commit de5f0e0d32
3 changed files with 12 additions and 11 deletions

View File

@ -186,9 +186,9 @@ type closureFields struct{ c *closure }
func (closureFields) IsStructMap() {}
func (cf closureFields) ArgNames() vals.List { return listOfStrings(cf.c.ArgNames) }
func (cf closureFields) ArgNames() vals.List { return vals.MakeListFromStrings(cf.c.ArgNames...) }
func (cf closureFields) RestArg() string { return strconv.Itoa(cf.c.RestArg) }
func (cf closureFields) OptNames() vals.List { return listOfStrings(cf.c.OptNames) }
func (cf closureFields) OptNames() vals.List { return vals.MakeListFromStrings(cf.c.OptNames...) }
func (cf closureFields) Src() parse.Source { return cf.c.SrcMeta }
func (cf closureFields) OptDefaults() vals.List {
@ -203,11 +203,3 @@ func (cf closureFields) Body() string {
func (cf closureFields) Def() string {
return cf.c.SrcMeta.Code[cf.c.DefRange.From:cf.c.DefRange.To]
}
func listOfStrings(ss []string) vals.List {
list := vals.EmptyList
for _, s := range ss {
list = list.Cons(s)
}
return list
}

View File

@ -280,7 +280,7 @@ func (ev *Evaler) addNumBgJobs(delta int) {
// the given slice. This method must be called before the Evaler is used to
// evaluate any code.
func (ev *Evaler) SetArgs(args []string) {
ev.Args = listOfStrings(args)
ev.Args = vals.MakeListFromStrings(args...)
}
// AddBeforeChdir adds a function to run before changing directory. This method

View File

@ -25,6 +25,15 @@ func MakeList(vs ...interface{}) vector.Vector {
return vec
}
// MakeListFromStrings creates a new List from strings.
func MakeListFromStrings(ss ...string) vector.Vector {
vec := vector.Empty
for _, s := range ss {
vec = vec.Cons(s)
}
return vec
}
// Map is an alias for the underlying type used for maps in Elvish.
type Map = hashmap.Map