简体   繁体   English

在 GNU APL 中柯里化

[英]Currying in GNU APL

I was trying to "curry" a function in GNU APL, however it doesn't seem to work?我试图在 GNU APL 中“咖喱”一个函数,但它似乎不起作用?

For example:例如:

      (1∘+) 1
SYNTAX ERROR
      (1∘+)1
      ^   ^

What am I doing wrong?我究竟做错了什么? Is the wrong glyph to use? 使用错误的字形吗?

GNU APL does not have the Bind meaning of , found in Dyalog and related implementations. GNU APL没有绑定的意思 ,在发现Dyalog和相关的实现。 Instead, the glyph is exclusively used for the outer product notation, ∘.f .相反, 字形专门用于外积符号∘.f

However, you can define a reasonable substitute yourself:但是,您可以自己定义一个合理的替代品:

∇ r←(a o b)z
  →3⌊⎕NC'b'
  r←z a b ⋄ →0
  r←a b z
∇

It can be used almost like the primitive, except requiring a space when adjacent to a name on its left or a non-glyph on its right:它几乎可以像原语一样使用,除了在其左侧的名称或右侧的非字形相邻时需要一个空格:

      (1o+) 1
2
      (+o 1) 1
2
      1o+ 1
2

Note that the above substitute does not provide function composition .请注意,上述替代品不提供功能组合 In order to also include this, we have to go for a more involved definition:为了也包括这一点,我们必须寻求一个更复杂的定义:

∇ r←x(a o b)y  ⍝ ∘
  →2⌈¯5+2⊥3⌊⎕NC⍪'ab'
  r←a b y ⋄ →0 ⍝ A∘f
  r←y a b ⋄ →0 ⍝ f∘B
  ⍎'x←{⍵}'/⍨0=⎕NC'x'
  r←x a b y    ⍝ f∘g
∇

Now everything works:现在一切正常:

      (1o+) 1
2
      (+o 1) 1
2
      1o+ 1
2
      1+o|¯1
2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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