本文整理匯總了Golang中github.com/JohnAnthony/goscm.Pair類的典型用法代碼示例。如果您正苦於以下問題:Golang Pair類的具體用法?Golang Pair怎麽用?Golang Pair使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Pair類的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
}