本文整理汇总了Golang中github.com/JohnAnthony/goscm.Pair.ToSlice方法的典型用法代码示例。如果您正苦于以下问题:Golang Pair.ToSlice方法的具体用法?Golang Pair.ToSlice怎么用?Golang Pair.ToSlice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/JohnAnthony/goscm.Pair
的用法示例。
在下文中一共展示了Pair.ToSlice方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: scm_multiply
func scm_multiply(args *goscm.Pair, env *goscm.Environ) (goscm.SCMT, error) {
argss, err := args.ToSlice()
if err != nil {
return goscm.SCM_Nil, err
}
ret := 1
for i := 0; i < len(argss); i++ {
if reflect.TypeOf(argss[i]) != reflect.TypeOf(&goscm.PlainInt{}) {
return goscm.SCM_Nil, errors.New("Expected integer type")
}
ret *= argss[i].(*goscm.PlainInt).Value
}
return goscm.NewSCMT(ret), nil
}
示例2: scm_begin
func scm_begin(args *goscm.Pair, env *goscm.Environ) (goscm.SCMT, error) {
var result goscm.SCMT
argss, err := args.ToSlice()
if err != nil {
return goscm.SCM_Nil, err
}
for i := 0; i < len(argss); i++ {
result, err = argss[i].Eval(env)
if err != nil {
return goscm.SCM_Nil, err
}
}
return result, nil
}
示例3: scm_map
func scm_map(args *goscm.Pair, env *goscm.Environ) (goscm.SCMT, error) {
argss, err := args.ToSlice()
if err != nil {
return goscm.SCM_Nil, err
}
if len(argss) < 2 {
return goscm.SCM_Nil, errors.New("Too few arguments")
}
if len(argss) > 2 {
return goscm.SCM_Nil, errors.New("Too many arguments")
}
proc, ok := argss[0].(goscm.Func)
if !ok {
return goscm.SCM_Nil, errors.New("Non-function in first position")
}
if reflect.TypeOf(argss[1]) != reflect.TypeOf(&goscm.Pair{}) {
return goscm.SCM_Nil, errors.New("Expected pair")
}
tail, err := argss[1].(*goscm.Pair).ToSlice()
if err != nil {
return goscm.SCM_Nil, err
}
ret := goscm.SCM_Nil
for i := len(tail) - 1; i >= 0; i-- {
result, err := proc.Apply(goscm.NewList(tail[i]), env)
if err != nil {
return goscm.SCM_Nil, err
}
ret = goscm.Cons(result, ret)
}
return ret, nil
}
示例4: scm_divide
func scm_divide(args *goscm.Pair, env *goscm.Environ) (goscm.SCMT, error) {
argss, err := args.ToSlice()
if err != nil {
return goscm.SCM_Nil, err
}
if len(argss) == 0 {
return goscm.SCM_Nil, errors.New("Expected at least one argument")
}
if reflect.TypeOf(argss[0]) != reflect.TypeOf(&goscm.PlainInt{}) {
return goscm.SCM_Nil, errors.New("Expected integer type")
}
ret := argss[0].(*goscm.PlainInt).Value
for i := 1; i < len(argss); i++ {
if reflect.TypeOf(argss[i]) != reflect.TypeOf(&goscm.PlainInt{}) {
return goscm.SCM_Nil, errors.New("Expected integer type")
}
ret /= argss[i].(*goscm.PlainInt).Value
}
return goscm.NewSCMT(ret), nil
}
示例5: scm_apply
func scm_apply(args *goscm.Pair, env *goscm.Environ) (goscm.SCMT, error) {
argss, err := args.ToSlice()
if err != nil {
return goscm.SCM_Nil, err
}
if len(argss) < 2 {
return goscm.SCM_Nil, errors.New("Too few arguments")
}
if len(argss) > 3 {
return goscm.SCM_Nil, errors.New("Too many arguments")
}
f, ok := argss[0].(goscm.Func)
if !ok {
return goscm.SCM_Nil, errors.New("Attempt to apply non-function type")
}
if reflect.TypeOf(argss[1]) != reflect.TypeOf(&goscm.Pair{}) {
return goscm.SCM_Nil, errors.New("Non-list to apply to")
}
target := argss[1].(*goscm.Pair)
return f.Apply(target, env)
}
示例6: scm_numeq
func scm_numeq(args *goscm.Pair, env *goscm.Environ) (goscm.SCMT, error) {
if args == goscm.SCM_Nil {
return goscm.NewSCMT(true), nil
}
argss, err := args.ToSlice()
if err != nil {
return goscm.SCM_Nil, err
}
base := argss[0].(*goscm.PlainInt).Value
for i := 1; i < len(argss); i++ {
if reflect.TypeOf(argss[i]) != reflect.TypeOf(&goscm.PlainInt{}) {
return goscm.SCM_Nil, errors.New("Expected integer argument")
}
if argss[i].(*goscm.PlainInt).Value != base {
return goscm.NewSCMT(false), nil
}
}
return goscm.NewSCMT(true), nil
}