Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 球拍中foldr的列表操作_List_Functional Programming_Scheme_Racket_Fold - Fatal编程技术网

List 球拍中foldr的列表操作

List 球拍中foldr的列表操作,list,functional-programming,scheme,racket,fold,List,Functional Programming,Scheme,Racket,Fold,#郎拍 我需要从两个列表中创建一个列表 list1 => '(1 2 3) list2 => '(a b c) 期望的结果 (define (create-list l1 l2) ... ) 成为”((1A)(2B)(3C)) 必须使用foldr,不能使用递归 我在考虑运行一个计数器并使用list ref, 有更好的方法吗?在Racket中,高阶过程可以将多个列表作为参数,您只需创建一个lambda,根据需要处理它们: (define (create-list l1 l2)

#郎拍

我需要从两个列表中创建一个列表

list1 => '(1 2 3)
list2 => '(a b c)
期望的结果

(define (create-list l1 l2)
...
)
成为”((1A)(2B)(3C))

必须使用
foldr
,不能使用递归

我在考虑运行一个计数器并使用list ref, 有更好的方法吗?

在Racket中,高阶过程可以将多个列表作为参数,您只需创建一个
lambda
,根据需要处理它们:

(define (create-list l1 l2)
  (foldr (lambda (e1 e2 acc)
           (cons (list e1 e2) acc))
         '() l1 l2))
例如:

(create-list '(1 2 3) '(a b c))
=> '((1 a) (2 b) (3 c))
在Racket中,高阶过程可以将多个列表作为参数,您只需创建一个
lambda
,根据需要处理它们:

(define (create-list l1 l2)
  (foldr (lambda (e1 e2 acc)
           (cons (list e1 e2) acc))
         '() l1 l2))
例如:

(create-list '(1 2 3) '(a b c))
=> '((1 a) (2 b) (3 c))
在Racket中,高阶过程可以将多个列表作为参数,您只需创建一个
lambda
,根据需要处理它们:

(define (create-list l1 l2)
  (foldr (lambda (e1 e2 acc)
           (cons (list e1 e2) acc))
         '() l1 l2))
例如:

(create-list '(1 2 3) '(a b c))
=> '((1 a) (2 b) (3 c))
在Racket中,高阶过程可以将多个列表作为参数,您只需创建一个
lambda
,根据需要处理它们:

(define (create-list l1 l2)
  (foldr (lambda (e1 e2 acc)
           (cons (list e1 e2) acc))
         '() l1 l2))
例如:

(create-list '(1 2 3) '(a b c))
=> '((1 a) (2 b) (3 c))

@LenaBru这只是个名字。此参数用作累加器,在其中生成响应,并最终在末尾返回。@LenaBru它只是一个名称。此参数用作累加器,在其中生成响应,并最终在末尾返回。@LenaBru它只是一个名称。此参数用作累加器,在其中生成响应,并最终在末尾返回。@LenaBru它只是一个名称。此参数用作累加器,在这里生成响应,并最终在末尾返回。