ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:100630] [Ruby master Feature#17290] Syntax sugar for boolean keyword argument
@ 2020-10-29  2:54 sawadatsuyoshi
  2020-10-29  4:29 ` [ruby-core:100633] " marcandre-ruby-core
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: sawadatsuyoshi @ 2020-10-29  2:54 UTC (permalink / raw)
  To: ruby-core

Issue #17290 has been reported by sawa (Tsuyoshi Sawada).

----------------------------------------
Feature #17290: Syntax sugar for boolean keyword argument
https://bugs.ruby-lang.org/issues/17290

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
----------------------------------------
We frequently use keyword arguments just to pass `true` value out of the truthy/falsy options given. And in many such cases, the falsy option is set as the default, and only the truthy value is ever passed explicitly. I propose to have a syntax sugar to omit the value of a keyword argument. When omitted, it should be interpreted with value `true`.

```ruby
gets(chomp:)
CSV.parse(" foo var ", strip:)
```

should be equivalent to

```ruby
gets(chomp: true)
CSV.parse(" foo var ", strip: true)
```

Additionally, we may also extend this to pragmas.

```ruby
# frozen_string_literal:
```

to be equivalent to:

```ruby
# frozen_string_literal: true
```




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:100633] [Ruby master Feature#17290] Syntax sugar for boolean keyword argument
  2020-10-29  2:54 [ruby-core:100630] [Ruby master Feature#17290] Syntax sugar for boolean keyword argument sawadatsuyoshi
@ 2020-10-29  4:29 ` marcandre-ruby-core
  2020-10-29  4:51 ` [ruby-core:100634] " keystonelemur
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: marcandre-ruby-core @ 2020-10-29  4:29 UTC (permalink / raw)
  To: ruby-core

Issue #17290 has been updated by marcandre (Marc-Andre Lafortune).


I'm personally hoping that `strip: ` could be syntax sugar for `strip: strip`...

----------------------------------------
Feature #17290: Syntax sugar for boolean keyword argument
https://bugs.ruby-lang.org/issues/17290#change-88268

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
----------------------------------------
We frequently use keyword arguments just to pass `true` value out of the truthy/falsy options given. And in many such cases, the falsy option is set as the default, and only the truthy value is ever passed explicitly. I propose to have a syntax sugar to omit the value of a keyword argument. When omitted, it should be interpreted with value `true`.

```ruby
gets(chomp:)
CSV.parse(" foo var ", strip:)
```

should be equivalent to

```ruby
gets(chomp: true)
CSV.parse(" foo var ", strip: true)
```

Additionally, we may also extend this to pragmas.

```ruby
# frozen_string_literal:
```

to be equivalent to:

```ruby
# frozen_string_literal: true
```




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:100634] [Ruby master Feature#17290] Syntax sugar for boolean keyword argument
  2020-10-29  2:54 [ruby-core:100630] [Ruby master Feature#17290] Syntax sugar for boolean keyword argument sawadatsuyoshi
  2020-10-29  4:29 ` [ruby-core:100633] " marcandre-ruby-core
@ 2020-10-29  4:51 ` keystonelemur
  2022-10-15 16:57 ` [ruby-core:110315] " sawa (Tsuyoshi Sawada)
  2023-03-30  5:35 ` [ruby-core:113046] " sawa (Tsuyoshi Sawada) via ruby-core
  3 siblings, 0 replies; 5+ messages in thread
From: keystonelemur @ 2020-10-29  4:51 UTC (permalink / raw)
  To: ruby-core

Issue #17290 has been updated by baweaver (Brandon Weaver).


I would concur with Marc-Andre on this one, I believe punning would be a more valuable feature, especially for keyword arguments.

Examples:

```ruby
def method_name(foo: 1, bar: 2, baz: 3)
  foo + bar + baz
end

foo = 1
bar = 2
baz = 3

method_name(foo:, bar:, baz:) # 1, 2, 3
# => 6

# Also punning in hashes which would be distinct from block syntax:
{ foo:, bar:, baz: }
# => { foo: 1, bar: 2, baz: 3 }
```

May open a separate ticket on those ideas or amend a current punning proposition

----------------------------------------
Feature #17290: Syntax sugar for boolean keyword argument
https://bugs.ruby-lang.org/issues/17290#change-88269

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
----------------------------------------
We frequently use keyword arguments just to pass `true` value out of the truthy/falsy options given. And in many such cases, the falsy option is set as the default, and only the truthy value is ever passed explicitly. I propose to have a syntax sugar to omit the value of a keyword argument. When omitted, it should be interpreted with value `true`.

```ruby
gets(chomp:)
CSV.parse(" foo var ", strip:)
```

should be equivalent to

```ruby
gets(chomp: true)
CSV.parse(" foo var ", strip: true)
```

Additionally, we may also extend this to pragmas.

```ruby
# frozen_string_literal:
```

to be equivalent to:

```ruby
# frozen_string_literal: true
```




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:110315] [Ruby master Feature#17290] Syntax sugar for boolean keyword argument
  2020-10-29  2:54 [ruby-core:100630] [Ruby master Feature#17290] Syntax sugar for boolean keyword argument sawadatsuyoshi
  2020-10-29  4:29 ` [ruby-core:100633] " marcandre-ruby-core
  2020-10-29  4:51 ` [ruby-core:100634] " keystonelemur
@ 2022-10-15 16:57 ` sawa (Tsuyoshi Sawada)
  2023-03-30  5:35 ` [ruby-core:113046] " sawa (Tsuyoshi Sawada) via ruby-core
  3 siblings, 0 replies; 5+ messages in thread
From: sawa (Tsuyoshi Sawada) @ 2022-10-15 16:57 UTC (permalink / raw)
  To: ruby-core

Issue #17290 has been updated by sawa (Tsuyoshi Sawada).


I think Marc-Andre and Brandon's idea can be limited to be relevant only for receiving the parameters (in a definition), and it will still make sense. My proposal is is about the parameters (in a method call). I think they can be kept distinct.

I rarely see people using `gets(chomp: true)`, and I think it is because it is shorter to write `gets.chomp`.  It is a pity that such a useful feature was introduced, but no one uses it because the old school way is more convenient.

----------------------------------------
Feature #17290: Syntax sugar for boolean keyword argument
https://bugs.ruby-lang.org/issues/17290#change-99605

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
----------------------------------------
We frequently use keyword arguments just to pass `true` value out of the truthy/falsy options given. And in many such cases, the falsy option is set as the default, and only the truthy value is ever passed explicitly. I propose to have a syntax sugar to omit the value of a keyword argument. When omitted, it should be interpreted with value `true`.

```ruby
gets(chomp:)
CSV.parse(" foo var ", strip:)
```

should be equivalent to

```ruby
gets(chomp: true)
CSV.parse(" foo var ", strip: true)
```

Additionally, we may also extend this to pragmas.

```ruby
# frozen_string_literal:
```

to be equivalent to:

```ruby
# frozen_string_literal: true
```




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:113046] [Ruby master Feature#17290] Syntax sugar for boolean keyword argument
  2020-10-29  2:54 [ruby-core:100630] [Ruby master Feature#17290] Syntax sugar for boolean keyword argument sawadatsuyoshi
                   ` (2 preceding siblings ...)
  2022-10-15 16:57 ` [ruby-core:110315] " sawa (Tsuyoshi Sawada)
@ 2023-03-30  5:35 ` sawa (Tsuyoshi Sawada) via ruby-core
  3 siblings, 0 replies; 5+ messages in thread
From: sawa (Tsuyoshi Sawada) via ruby-core @ 2023-03-30  5:35 UTC (permalink / raw)
  To: ruby-core; +Cc: sawa (Tsuyoshi Sawada)

Issue #17290 has been updated by sawa (Tsuyoshi Sawada).


I withdraw this proposal. Please close it. I came up with a better idea #19559.

----------------------------------------
Feature #17290: Syntax sugar for boolean keyword argument
https://bugs.ruby-lang.org/issues/17290#change-102585

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
----------------------------------------
We frequently use keyword arguments just to pass `true` value out of the truthy/falsy options given. And in many such cases, the falsy option is set as the default, and only the truthy value is ever passed explicitly. I propose to have a syntax sugar to omit the value of a keyword argument. When omitted, it should be interpreted with value `true`.

```ruby
gets(chomp:)
CSV.parse(" foo var ", strip:)
```

should be equivalent to

```ruby
gets(chomp: true)
CSV.parse(" foo var ", strip: true)
```

Additionally, we may also extend this to pragmas.

```ruby
# frozen_string_literal:
```

to be equivalent to:

```ruby
# frozen_string_literal: true
```




-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-03-30  5:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-29  2:54 [ruby-core:100630] [Ruby master Feature#17290] Syntax sugar for boolean keyword argument sawadatsuyoshi
2020-10-29  4:29 ` [ruby-core:100633] " marcandre-ruby-core
2020-10-29  4:51 ` [ruby-core:100634] " keystonelemur
2022-10-15 16:57 ` [ruby-core:110315] " sawa (Tsuyoshi Sawada)
2023-03-30  5:35 ` [ruby-core:113046] " sawa (Tsuyoshi Sawada) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).