Feature #10068

[PATCH] Implement monadic operator for Vector

Added by gogo tanaka 9 months ago. Updated 6 months ago.

[ruby-core:63847]
Status:Closed
Priority:Normal
Assignee:Marc-Andre Lafortune

Description

Before
```
v = Vector[1, 2, 3]

  • v
    => NoMethodError: undefined method `+@' for Vector[1, 2, 3]:Vector

  • v
    => NoMethodError: undefined method -@' for Vector[1, 2, 3]:Vector
    ``

After
```
v = Vector[1, 2, 3]

  • v
    => Vector[1, 2, 3]

  • v
    => Vector[-1, -2, -3]
    ```

implement_uplus_for_vector.patch Magnifier (842 Bytes) gogo tanaka, 07/19/2014 01:56 AM

implement_negate_for_vector.patch Magnifier (1.25 KB) gogo tanaka, 07/19/2014 01:56 AM


Related issues

Related to Ruby trunk - Feature #10069: [PATCH] Implement monadic operator for Matrix Closed 07/19/2014

Associated revisions

Revision 47840
Added by Marc-Andre Lafortune 6 months ago

  • lib/matrix.rb: Add @- and @+ for Matrix and Vector. patch by gogo tanaka [#10068] [#10069]

Revision 47840
Added by Marc-Andre Lafortune 6 months ago

  • lib/matrix.rb: Add @- and @+ for Matrix and Vector. patch by gogo tanaka [#10068] [#10069]

History

#1 Updated by gogo tanaka 9 months ago

I'm sorry my report looks ugly... I fix it. ↓

Before

v = Vector[1, 2, 3]

+ v
=> NoMethodError: undefined method `+@' for Vector[1, 2, 3]:Vector

- v
=> NoMethodError: undefined method `-@' for Vector[1, 2, 3]:Vector

After

v = Vector[1, 2, 3]

+ v
=> Vector[1, 2, 3]

- v
=> Vector[-1, -2, -3]

#2 Updated by Yukihiro Matsumoto 9 months ago

I am not sure the term monadic is a proper one, but I like the idea.

Matz.

#3 Updated by Yukihiro Matsumoto 9 months ago

  • Related to Feature #10069: [PATCH] Implement monadic operator for Matrix added

#4 Updated by Hiroshi SHIBATA 8 months ago

  • Assignee set to Marc-Andre Lafortune
  • Target version set to current: 2.2.0
  • Category set to lib
  • Status changed from Open to Assigned

#5 Updated by Marc-Andre Lafortune 6 months ago

  • Status changed from Assigned to Closed

Done.

Thanks for catching this omission, and for the patch.

#6 Updated by gogo tanaka 6 months ago

Thank you, too.

Also available in: Atom PDF