double-splat

two level splatter TCL

半世苍凉 提交于 2020-01-25 19:01:05
问题 If I have a procedure or a command in TCL, with variable number of arguments, one can use, if a list's elements are as an input, the "splatter" operator, for example: set a [list "ko" ] set m [ list "ok" "bang" ] lappend a {*}$m But, what if I want to "twice splatter"? I.e., flatten 2 levels? Using it twice, in sequence, does not work: set a [list "ko" ] set m [ list [ list "ok" ] [ list "bang" ] ] lappend a {*}{*}$m Will error out on extra character. 回答1: You've noticed that {*}

Parameter destructuring (equivalent of python's double-splat)

大兔子大兔子 提交于 2019-12-01 22:31:15
问题 In python I can pass a dict whose keys match parameters' names with the ** (double-splat) operator: def foo(a, b): print (a - b) args = {'b': 7, 'a': 10} foo(**args) # prints 3 How to do the same in ES6? This doesn't work: function foo(a, b) { console.log(a - b) } args = {b: 7, a: 10} foo(...args) NB: I'm looking for a solution that wouldn't involve changing the signature of foo because I want it to be used either way (with and without destructuring). So the following should work: foo(<magic

Parameter destructuring (equivalent of python's double-splat)

放肆的年华 提交于 2019-12-01 20:40:54
In python I can pass a dict whose keys match parameters' names with the ** (double-splat) operator: def foo(a, b): print (a - b) args = {'b': 7, 'a': 10} foo(**args) # prints 3 How to do the same in ES6? This doesn't work: function foo(a, b) { console.log(a - b) } args = {b: 7, a: 10} foo(...args) NB: I'm looking for a solution that wouldn't involve changing the signature of foo because I want it to be used either way (with and without destructuring). So the following should work: foo(<magic>args); foo(123, 456); Bonus question: why is the error message "undefined is not a function"? What

Keyword arguments unpacking (splat) in Ruby

白昼怎懂夜的黑 提交于 2019-11-29 09:59:01
What is happening below seems a little strange to me. def f(a, b) puts "#{a} :: #{b}" end f(*[1, 2], **{}) # prints "1 :: 2" hash = {} f(*[1, 2], **hash) ArgumentError: wrong number of arguments (3 for 2) f(*[1, 2], **Hash.new) ArgumentError: wrong number of arguments (3 for 2) Is this a compiler optimization feature? That is a Ruby's bug that has been reported several times (for example here by me) but has not been fixed. I guess that since the keyword argument feature has been introduced, the double splat syntax has become murky, and that is the indirect cause of this bug. I heard that Matz

Keyword arguments unpacking (splat) in Ruby

限于喜欢 提交于 2019-11-28 02:54:04
问题 What is happening below seems a little strange to me. def f(a, b) puts "#{a} :: #{b}" end f(*[1, 2], **{}) # prints "1 :: 2" hash = {} f(*[1, 2], **hash) ArgumentError: wrong number of arguments (3 for 2) f(*[1, 2], **Hash.new) ArgumentError: wrong number of arguments (3 for 2) Is this a compiler optimization feature? 回答1: That is a Ruby's bug that has been reported several times (for example here by me) but has not been fixed. I guess that since the keyword argument feature has been

Double-splat operator destructively modifies hash – is this a Ruby bug?

雨燕双飞 提交于 2019-11-27 23:45:35
I noticed what I find to be a very surprising behavior with the ** (double-splat) operator in Ruby 2.1.1. When key-value pairs are used before a **hash , the hash remains unmodified; however, when key-value pairs are only used after the **hash , the hash is permanently modified. h = { b: 2 } { a: 1, **h } # => { a: 1, b: 2 } h # => { b: 2 } { a: 1, **h, c: 3 } # => { a: 1, b: 2, c: 3 } h # => { b: 2 } { **h, c: 3 } # => { b: 2, c: 3 } h # => { b: 2, c: 3 } For comparison, consider the behavior of the single- * operator on arrays: a = [2] [1, *a] # => [1, 2] a # => [2] [1, *a, 3] # => [1, 2, 3]

Double-splat operator destructively modifies hash – is this a Ruby bug?

青春壹個敷衍的年華 提交于 2019-11-27 04:41:48
问题 I noticed what I find to be a very surprising behavior with the ** (double-splat) operator in Ruby 2.1.1. When key-value pairs are used before a **hash , the hash remains unmodified; however, when key-value pairs are only used after the **hash , the hash is permanently modified. h = { b: 2 } { a: 1, **h } # => { a: 1, b: 2 } h # => { b: 2 } { a: 1, **h, c: 3 } # => { a: 1, b: 2, c: 3 } h # => { b: 2 } { **h, c: 3 } # => { b: 2, c: 3 } h # => { b: 2, c: 3 } For comparison, consider the

Change what the *splat and **splatty-splat operators do to my object

狂风中的少年 提交于 2019-11-26 21:16:00
问题 How do you override the result of unpacking syntax *obj and **obj ? For example, can you somehow create an object thing which behaves like this: >>> [*thing] ['a', 'b', 'c'] >>> [x for x in thing] ['d', 'e', 'f'] >>> {**thing} {'hello world': 'I am a potato!!'} Note: the iteration via __iter__ ("for x in thing") returns different elements from the *splat unpack. I had a look in operator.mul and operator.pow , but those functions only concern usages with two operands, like a*b and a**b , and