简体   繁体   中英

collapse a list of unevaluated expressions to single expression

Having the following list of unevaluated expressions.

l = list(quote(f()),quote(g()),quote(h()))
str(l)
#List of 3
# $ : language f()
# $ : language g()
# $ : language h()

I would like to collapse the list using & function so I would get following r result.

r = quote(f() & g() & h())
str(r)
# language f() & g() & h()

Of course the point is to handle list of any length.

您可以为此使用Reduce

Reduce(function(a,b) bquote(.(a) & .(b)), l)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM