使用嵌套槽 (#) [英] Using nested slots (#)

查看:24
本文介绍了使用嵌套槽 (#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我想构造类似

Array[#1^#2 == 3 &, {3, 3}] 

现在我想用一个变量替换3".我可以做,例如:

And now I want to replace the "3" with a variable. I can do, for example:

f[x_] := Array[#1^#2 == x &, {x, x}]  

问题是:有没有办法使用插槽和 &作为功​​能符号?

The question is: Is there a way using only slots and & as the functional notation?

推荐答案

怎么样

Map[Last, #] & /@ Array[#1^#2 == #3 &, {#, #, #}] &[3]

非常丑陋的元素提取,非常有趣的是 Map[Last, #]& 给了我与 Last/@ 不同的结果.这是因为 Map& 具有不同的属性吗?

Horrendously ugly element extraction, and very interestingly Map[Last, #]& gives me a different result than Last /@. Is this due to the fact that Map has different attributes than &?

这篇关于使用嵌套槽 (#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆