Re: Arr subtract

`mymeth` worked fine for me. You’d have to invoke as `mymeth(var) {|e| ...}` of course (among multiple options) and ensure it has access to `arr` in its scope or declare `arr` as `@arr` if you are at the top level scope.

Regarding “I assumed arr.delete{} would delete if the expr is true. Would anyone expect what arr.delete is doing??”, what you are really looking for is: `arr#delete_if {}`

`arr.delete {}`’s block does something different. Here is what the Ruby API says: “ the result of the block is returned if the item is not found”

Andy

···

On Aug 11, 2021, at 2:35 PM, Die Optimisten <inform@die-optimisten.net> wrote:

Hello

Thanks for the answers!

How can I do it with an OPTIONAL blocK?

Meaning:

how can I forward the block as arg to another method?

def mymeth(var, &block)
    arr.find (var, &block) ... # does not work! # how to "tranlate"
the args to use them here?
end

---
I assumed arr.delete{} would delete if the expr is true. Would anyone
expect what arr.delete is doing??

thanks
Opti

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<ruby-talk list: member options login page>

Hi
Thanks for your answer;

/"Would anyone expect what arr.delete is doing??/”
- I should have written: "/Does (could) //anyone expect what arr.delete
is doing??/”
Yes, mymeth works fine,

Would'nt a [normal/standard/non-programming :slight_smile: ] human expect
[1,2,2,3,3,3] - [2,3] == [1,2,3,3] ??
Should this be changed (Ruby7)?
Maybe thats not easy, because much SW may depend on this... [ we have
.delete !! ]

The (different) question is:
How can I transfer args (unknown if it's a block or a variable), for
example if writing an interface for .uniq:
myIndex ->{|args)|
puts 'Now running index'
self.index(args) # does not work (with a block)
}
myIndex.call(args)

Same with a method:
class Array
#def myIndex(*args)
def myIndex(*args,&block)
puts 'Running index'
self.index(*args,&block)
end end

[3,3,4].myIndex{|x| 5} # -> 'given block not used' ???

···

Am 11.08.21 um 23:29 schrieb Andy Maleh:

`mymeth` worked fine for me. You’d have to invoke as `mymeth(var) {|e|
...}` of course (among multiple options) and ensure it has access to
`arr` in its scope or declare `arr` as `@arr` if you are at the top
level scope.

Regarding “/I assumed arr.delete{} would delete if the expr is
true. Would anyone expect what arr.delete is doing??/”, *what you are
really looking for is*: `arr#delete_if {}`

`arr.delete {}`’s block does something different. Here is what the
Ruby API says: “ the result of the block is returned if the item is
not found”

Andy

Hi,
Thanks for your answer;

/"Would anyone expect what arr.delete is doing??/”
- I should have written: "/Does (could) //anyone expect what arr.delete
is doing??/”
Yes, mymeth works fine,

Would'nt a [normal/standard/non-programming :slight_smile: ] human expect
[1,2,2,3,3,3] - [2,3] == [1,2,3,3] ??
Should this be changed (in Ruby7)? -- We have .delete !!
Maybe thats not easy, because much SW may depend on this...

Question still open:

1) How can I transfer args (unknown if it's a block or a variable), for
example if writing an interface for .uniq or .index :

myIndex ->{|args|
puts 'Now running index'

args.index(&block) # does not work (with a [optional] block)
}
myIndex.call(args)

2)

How can a proc/lambda be used on self ?

[1,23,3,3,3,3] .call_lambda(:name, args) ??

thank you!

Opti

Hi!

1) I think you've forgotten to assign the block to variable 'block' in the lambda definition. Try this:


myIndex = ->(arg, &block) { arg.index(&block) }

2) I will suggest you to try `Kernel#tap` or `Kernal#then`. See: module Kernel - Documentation for Ruby master

Yunzhe

-----Original Messages-----

···

From:"Die Optimisten" <inform@die-optimisten.net>
Sent Time:2021-08-12 16:59:36 (Thursday)
To: ruby-talk@ruby-lang.org
Cc:
Subject: Re: Arr subtract [partly solved, REPLACES previous mail!]

Hi,

Thanks for your answer;

"Would anyone expect what arr.delete is doing??”
- I should have written: "Does (could) anyone expect what arr.delete is doing??”
Yes, mymeth works fine,

Would'nt a [normal/standard/non-programming :slight_smile: ] human expect
[1,2,2,3,3,3] - [2,3] == [1,2,3,3] ??

Should this be changed (in Ruby7)? -- We have .delete !!
Maybe thats not easy, because much SW may depend on this...

Question still open:

1) How can I transfer args (unknown if it's a block or a variable), for example if writing an interface for .uniq or .index :

myIndex ->{|args|
  puts 'Now running index'

args.index(&block) # does not work (with a [optional] block)
}
myIndex.call(args)

2)

How can a proc/lambda be used on self ?

[1,23,3,3,3,3] .call_lambda(:name, args) ??

thank you!

Opti

What about this case?:

···

On Thu, Aug 12, 2021 at 7:01 PM Die Optimisten <inform@die-optimisten.net> wrote:

Would'nt a [normal/standard/non-programming :slight_smile: ] human expect
[1,2,2,3,3,3] - [2,3] == [1,2,3,3] ??

~~~
[2, [2, 3], 3] - [2, 3]
~~~

Cheers
--
  Matthew Kerwin
  https://matthew.kerwin.net.au/

Hello!
Good example :slight_smile:
My answer:
We live in a linear world :wink: [it is already complicated enough...]
So when not writing [[2,3]] (as element), the solution must be [1,2,3,3]
Specification: elems.minus(elems)
(must be two arrays syntactically)

Cheers. Opti

···

Am 12.08.21 um 12:40 schrieb Matthew Kerwin:

On Thu, Aug 12, 2021 at 7:01 PM Die Optimisten > <inform@die-optimisten.net <mailto:inform@die-optimisten.net>> wrote:

    Would'nt a [normal/standard/non-programming :slight_smile: ] human expect
    [1,2,2,3,3,3] - [2,3] == [1,2,3,3] ??

What about this case?:

~~~
[2, [2, 3], 3] - [2, 3]
~~~

Cheers
--
Matthew Kerwin
https://matthew.kerwin.net.au/

Hello!
Good example :slight_smile:
My answer:
We live in a linear world :wink: [it is already complicated enough...]
So when not writing [[2,3]] (as element), the solution must be
[1,2,3,3] # wrong line pasted!!

 CORRECTION: \[2, \[2, 3\], 3\] \- \[2, 3\] =&gt; \[\[2,3\]\]   \# interesting what

you meant, but computers do not look into the future [hopefully...]!

···

Am 12.08.21 um 15:17 schrieb Die Optimisten:

Specification: elems.minus(elems)
(must be two arrays syntactically)

Cheers. Opti

Am 12.08.21 um 12:40 schrieb Matthew Kerwin:

On Thu, Aug 12, 2021 at 7:01 PM Die Optimisten >> <inform@die-optimisten.net <mailto:inform@die-optimisten.net>> wrote:

    Would'nt a [normal/standard/non-programming :slight_smile: ] human expect
    [1,2,2,3,3,3] - [2,3] == [1,2,3,3] ??

What about this case?:

~~~
[2, [2, 3], 3] - [2, 3]
~~~

Cheers
--
Matthew Kerwin
https://matthew.kerwin.net.au/

If we leave the subject ...[REPLACES previous mail!],
then it doesn't make sense to post anything more...

···

Am 12.08.21 um 15:17 schrieb Die Optimisten:

Hello!
Good example :slight_smile:
My answer:
We live in a linear world :wink: [it is already complicated enough...]
So when not writing [[2,3]] (as element), the solution must be [1,2,3,3]
Specification: elems.minus(elems)
(must be two arrays syntactically)

Cheers. Opti

Am 12.08.21 um 12:40 schrieb Matthew Kerwin:

On Thu, Aug 12, 2021 at 7:01 PM Die Optimisten >> <inform@die-optimisten.net <mailto:inform@die-optimisten.net>> wrote:

    Would'nt a [normal/standard/non-programming :slight_smile: ] human expect
    [1,2,2,3,3,3] - [2,3] == [1,2,3,3] ??

What about this case?:

~~~
[2, [2, 3], 3] - [2, 3]
~~~

Cheers
--
Matthew Kerwin
https://matthew.kerwin.net.au/

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<ruby-talk list: member options login page>