[英]In APL how to turn a string into a one cell vector
So, I have a function f that takes a string as input.所以,我有一个 function f 以字符串作为输入。 I want to create a function g that maps f to a vector of strings.
我想创建一个 function g 将 f 映射到字符串向量。 Ie
IE
g 'Hello' 'world'
should yield应该产生
(f 'Hello')(f 'world')
Here's what I did:这是我所做的:
g ← {f¨⍵}
And this works just fine for the example above.这对于上面的例子来说很好。 However, it doesn't work when the right argument is just one string, as it maps f to every character of that string.
但是,当正确的参数只是一个字符串时,它不起作用,因为它将 f 映射到该字符串的每个字符。 For example:
例如:
g 'Hello'
yields产量
(f 'H')(f 'e')(f 'l')(f 'l')(f 'o')
Of course, I wanted the output to be f 'Hello'
.当然,我希望 output 是
f 'Hello'
。
I could write我可以写
g ← {f¨⊂⍵}
So that 'Hello'
would be interpreted as这样
'Hello'
将被解释为
┌─────┐
│Hello│
└─────┘
But then 'Hello' 'world'
will be interpreted as但随后
'Hello' 'world'
将被解释为
┌─────────────┐
│┌─────┬─────┐│
││Hello│world││
│└─────┴─────┘│
└─────────────┘
And then it won't map correctly.然后它不会正确 map。
Is there a way to solve this succinctly?有没有办法简洁地解决这个问题?
You're looking for ⊆你在找⊆
⊆'hello'
┌─────┐
│hello│
└─────┘
⊆'hello' 'world'
┌─────┬─────┐
│hello│world│
└─────┴─────┘
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.