ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:86152] [Ruby trunk Feature#14609] `Kernel#p` without args shows the receiver
       [not found] <redmine.issue-14609.20180316012909@ruby-lang.org>
@ 2018-03-16  1:29 ` ko1
  2018-03-16  3:11 ` [ruby-core:86153] " mame
                   ` (17 subsequent siblings)
  18 siblings, 0 replies; 19+ messages in thread
From: ko1 @ 2018-03-16  1:29 UTC (permalink / raw)
  To: ruby-core

Issue #14609 has been reported by ko1 (Koichi Sasada).

----------------------------------------
Feature #14609: `Kernel#p` without args shows the receiver
https://bugs.ruby-lang.org/issues/14609

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 2.6
----------------------------------------
# Abstract

`Kernel#p(obj)` prints obj as `inspect`ed.
How about to show the receiver if an argument is not given?

# Background

We recently introduce `yield_self` which encourages block chain.

https://zverok.github.io/blog/2018-01-24-yield_self.html
Quoted from this article, we can write method chain with blocks:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }
  .yield_self { |id| "server:#{id}" }
```

There is a small problem at debugging.
If we want to see the middle values in method/block chain, we need to insert `tap{|e| p e}`.

With above example,

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.tap{|e| p e} # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.tap{|e| p e} # debug print
  .yield_self { |id| "server:#{id}" }
```

# Proposal

`obj.p` shows same as `p(obj)`.

We can replace
  `block{...}.tap{|e| p e}`
to 
  `block{...}.p`

For above example, we can simply add `.p` at the end of line:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.p # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.p # debug print
  .yield_self { |id| "server:#{id}" }
```

# Compatibility issue

(1) Shorthand for `nil`

This spec change can introduce compatibility issue because `p` returns `nil` and do not output anything.
That is to say, `p` is shorthand of `nil`. Some code-golfers use it.

Maybe we can ignore them :p

(2) make public method

`Kernel#p` is private method, so if we typo `obj.x` to `obj.p` (not sure how it is feasible), it will be `NoMethodError` because of visibility.
We need to change this behavior.

# Note

## Past proposal and discussion

Endoh-san proposed same idea 10+ years ago [ruby-dev:29736] in Japanese.
I think we should revisit this idea because of `yield_self` introduction.

At this thread, Matz said "simple `p` shows `p(self)`, it is not clear".

[ruby-dev:30903]

```
  p

はどう動くのかとか(p selfと同じ、は変な気が)

  self.p(obj)

はどうなのかとか。その辺が解決(納得)できたら、ということで。
```

English translation:

```
What the behavior of (I feel strange that it is similar to `p(self)`):

  p

What happen on

  self.p(obj)
```

## pp

If this proposal is accepted, we also need to change `pp` behavior.

## gems

`tapp` method is provided by gem.
https://github.com/esminc/tapp 

I'd thought to propose this method into core. But I found that `p` is more shorter than `tapp`.
Disadvantage is `p` is too short and difficult to grep.




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

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

* [ruby-core:86153] [Ruby trunk Feature#14609] `Kernel#p` without args shows the receiver
       [not found] <redmine.issue-14609.20180316012909@ruby-lang.org>
  2018-03-16  1:29 ` [ruby-core:86152] [Ruby trunk Feature#14609] `Kernel#p` without args shows the receiver ko1
@ 2018-03-16  3:11 ` mame
  2018-03-16  8:00 ` [ruby-core:86155] " zverok.offline
                   ` (16 subsequent siblings)
  18 siblings, 0 replies; 19+ messages in thread
From: mame @ 2018-03-16  3:11 UTC (permalink / raw)
  To: ruby-core

Issue #14609 has been updated by mame (Yusuke Endoh).


+1

`Kernel#p` is one of the greatest feature in Ruby.  It would be further great to make it useful.

----------------------------------------
Feature #14609: `Kernel#p` without args shows the receiver
https://bugs.ruby-lang.org/issues/14609#change-71031

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 2.6
----------------------------------------
# Abstract

`Kernel#p(obj)` prints obj as `inspect`ed.
How about to show the receiver if an argument is not given?

# Background

We recently introduce `yield_self` which encourages block chain.

https://zverok.github.io/blog/2018-01-24-yield_self.html
Quoted from this article, we can write method chain with blocks:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }
  .yield_self { |id| "server:#{id}" }
```

There is a small problem at debugging.
If we want to see the middle values in method/block chain, we need to insert `tap{|e| p e}`.

With above example,

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.tap{|e| p e} # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.tap{|e| p e} # debug print
  .yield_self { |id| "server:#{id}" }
```

# Proposal

`obj.p` shows same as `p(obj)`.

We can replace
  `block{...}.tap{|e| p e}`
to 
  `block{...}.p`

For above example, we can simply add `.p` at the end of line:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.p # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.p # debug print
  .yield_self { |id| "server:#{id}" }
```

# Compatibility issue

(1) Shorthand for `nil`

This spec change can introduce compatibility issue because `p` returns `nil` and do not output anything.
That is to say, `p` is shorthand of `nil`. Some code-golfers use it.

Maybe we can ignore them :p

(2) make public method

`Kernel#p` is private method, so if we typo `obj.x` to `obj.p` (not sure how it is feasible), it will be `NoMethodError` because of visibility.
We need to change this behavior.

# Note

## Past proposal and discussion

Endoh-san proposed same idea 10+ years ago [ruby-dev:29736] in Japanese.
I think we should revisit this idea because of `yield_self` introduction.

At this thread, Matz said "simple `p` shows `p(self)`, it is not clear".

[ruby-dev:30903]

```
  p

はどう動くのかとか(p selfと同じ、は変な気が)

  self.p(obj)

はどうなのかとか。その辺が解決(納得)できたら、ということで。
```

English translation:

```
What the behavior of (I feel strange that it is similar to `p(self)`):

  p

What happen on

  self.p(obj)
```

## pp

If this proposal is accepted, we also need to change `pp` behavior.

## gems

`tapp` method is provided by gem.
https://github.com/esminc/tapp 

I'd thought to propose this method into core. But I found that `p` is more shorter than `tapp`.
Disadvantage is `p` is too short and difficult to grep.




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

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

* [ruby-core:86155] [Ruby trunk Feature#14609] `Kernel#p` without args shows the receiver
       [not found] <redmine.issue-14609.20180316012909@ruby-lang.org>
  2018-03-16  1:29 ` [ruby-core:86152] [Ruby trunk Feature#14609] `Kernel#p` without args shows the receiver ko1
  2018-03-16  3:11 ` [ruby-core:86153] " mame
@ 2018-03-16  8:00 ` zverok.offline
  2018-03-16 10:55 ` [ruby-core:86156] " hanmac
                   ` (15 subsequent siblings)
  18 siblings, 0 replies; 19+ messages in thread
From: zverok.offline @ 2018-03-16  8:00 UTC (permalink / raw)
  To: ruby-core

Issue #14609 has been updated by zverok (Victor Shepelev).


Small notice: If #13581 would be once acted upon, attaching `p` in the middle of the chain could be as simple as (using one of the proposed syntaxes)

```ruby
  .yield_self { |response| JSON.parse(response) }.tap(&:.p)
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.tap(&:.p)
```

Just `.p` is still nicer, though.


----------------------------------------
Feature #14609: `Kernel#p` without args shows the receiver
https://bugs.ruby-lang.org/issues/14609#change-71033

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 2.6
----------------------------------------
# Abstract

`Kernel#p(obj)` prints obj as `inspect`ed.
How about to show the receiver if an argument is not given?

# Background

We recently introduce `yield_self` which encourages block chain.

https://zverok.github.io/blog/2018-01-24-yield_self.html
Quoted from this article, we can write method chain with blocks:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }
  .yield_self { |id| "server:#{id}" }
```

There is a small problem at debugging.
If we want to see the middle values in method/block chain, we need to insert `tap{|e| p e}`.

With above example,

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.tap{|e| p e} # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.tap{|e| p e} # debug print
  .yield_self { |id| "server:#{id}" }
```

# Proposal

`obj.p` shows same as `p(obj)`.

We can replace
  `block{...}.tap{|e| p e}`
to 
  `block{...}.p`

For above example, we can simply add `.p` at the end of line:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.p # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.p # debug print
  .yield_self { |id| "server:#{id}" }
```

# Compatibility issue

(1) Shorthand for `nil`

This spec change can introduce compatibility issue because `p` returns `nil` and do not output anything.
That is to say, `p` is shorthand of `nil`. Some code-golfers use it.

Maybe we can ignore them :p

(2) make public method

`Kernel#p` is private method, so if we typo `obj.x` to `obj.p` (not sure how it is feasible), it will be `NoMethodError` because of visibility.
We need to change this behavior.

# Note

## Past proposal and discussion

Endoh-san proposed same idea 10+ years ago [ruby-dev:29736] in Japanese.
I think we should revisit this idea because of `yield_self` introduction.

At this thread, Matz said "simple `p` shows `p(self)`, it is not clear".

[ruby-dev:30903]

```
  p

はどう動くのかとか(p selfと同じ、は変な気が)

  self.p(obj)

はどうなのかとか。その辺が解決(納得)できたら、ということで。
```

English translation:

```
What the behavior of (I feel strange that it is similar to `p(self)`):

  p

What happen on

  self.p(obj)
```

## pp

If this proposal is accepted, we also need to change `pp` behavior.

## gems

`tapp` method is provided by gem.
https://github.com/esminc/tapp 

I'd thought to propose this method into core. But I found that `p` is more shorter than `tapp`.
Disadvantage is `p` is too short and difficult to grep.




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

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

* [ruby-core:86156] [Ruby trunk Feature#14609] `Kernel#p` without args shows the receiver
       [not found] <redmine.issue-14609.20180316012909@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2018-03-16  8:00 ` [ruby-core:86155] " zverok.offline
@ 2018-03-16 10:55 ` hanmac
  2018-08-10  7:03 ` [ruby-core:88426] " ko1
                   ` (14 subsequent siblings)
  18 siblings, 0 replies; 19+ messages in thread
From: hanmac @ 2018-03-16 10:55 UTC (permalink / raw)
  To: ruby-core

Issue #14609 has been updated by Hanmac (Hans Mackowiak).


hm i have a slightly problem with this

check out the different return types there:

~~~ ruby

a = []
p *a #=> nil

a = [1]
p *a #=> 1

a = [1,2]
p *a #=> [1,2]
~~~




----------------------------------------
Feature #14609: `Kernel#p` without args shows the receiver
https://bugs.ruby-lang.org/issues/14609#change-71034

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 2.6
----------------------------------------
# Abstract

`Kernel#p(obj)` prints obj as `inspect`ed.
How about to show the receiver if an argument is not given?

# Background

We recently introduce `yield_self` which encourages block chain.

https://zverok.github.io/blog/2018-01-24-yield_self.html
Quoted from this article, we can write method chain with blocks:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }
  .yield_self { |id| "server:#{id}" }
```

There is a small problem at debugging.
If we want to see the middle values in method/block chain, we need to insert `tap{|e| p e}`.

With above example,

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.tap{|e| p e} # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.tap{|e| p e} # debug print
  .yield_self { |id| "server:#{id}" }
```

# Proposal

`obj.p` shows same as `p(obj)`.

We can replace
  `block{...}.tap{|e| p e}`
to 
  `block{...}.p`

For above example, we can simply add `.p` at the end of line:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.p # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.p # debug print
  .yield_self { |id| "server:#{id}" }
```

# Compatibility issue

(1) Shorthand for `nil`

This spec change can introduce compatibility issue because `p` returns `nil` and do not output anything.
That is to say, `p` is shorthand of `nil`. Some code-golfers use it.

Maybe we can ignore them :p

(2) make public method

`Kernel#p` is private method, so if we typo `obj.x` to `obj.p` (not sure how it is feasible), it will be `NoMethodError` because of visibility.
We need to change this behavior.

# Note

## Past proposal and discussion

Endoh-san proposed same idea 10+ years ago [ruby-dev:29736] in Japanese.
I think we should revisit this idea because of `yield_self` introduction.

At this thread, Matz said "simple `p` shows `p(self)`, it is not clear".

[ruby-dev:30903]

```
  p

はどう動くのかとか(p selfと同じ、は変な気が)

  self.p(obj)

はどうなのかとか。その辺が解決(納得)できたら、ということで。
```

English translation:

```
What the behavior of (I feel strange that it is similar to `p(self)`):

  p

What happen on

  self.p(obj)
```

## pp

If this proposal is accepted, we also need to change `pp` behavior.

## gems

`tapp` method is provided by gem.
https://github.com/esminc/tapp 

I'd thought to propose this method into core. But I found that `p` is more shorter than `tapp`.
Disadvantage is `p` is too short and difficult to grep.




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

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

* [ruby-core:88426] [Ruby trunk Feature#14609] `Kernel#p` without args shows the receiver
       [not found] <redmine.issue-14609.20180316012909@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2018-03-16 10:55 ` [ruby-core:86156] " hanmac
@ 2018-08-10  7:03 ` ko1
  2018-08-10 13:09 ` [ruby-core:88438] " hanmac
                   ` (13 subsequent siblings)
  18 siblings, 0 replies; 19+ messages in thread
From: ko1 @ 2018-08-10  7:03 UTC (permalink / raw)
  To: ruby-core

Issue #14609 has been updated by ko1 (Koichi Sasada).


Hanmac: do you rely on this behavior?


----------------------------------------
Feature #14609: `Kernel#p` without args shows the receiver
https://bugs.ruby-lang.org/issues/14609#change-73479

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 2.6
----------------------------------------
# Abstract

`Kernel#p(obj)` prints obj as `inspect`ed.
How about to show the receiver if an argument is not given?

# Background

We recently introduce `yield_self` which encourages block chain.

https://zverok.github.io/blog/2018-01-24-yield_self.html
Quoted from this article, we can write method chain with blocks:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }
  .yield_self { |id| "server:#{id}" }
```

There is a small problem at debugging.
If we want to see the middle values in method/block chain, we need to insert `tap{|e| p e}`.

With above example,

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.tap{|e| p e} # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.tap{|e| p e} # debug print
  .yield_self { |id| "server:#{id}" }
```

# Proposal

`obj.p` shows same as `p(obj)`.

We can replace
  `block{...}.tap{|e| p e}`
to 
  `block{...}.p`

For above example, we can simply add `.p` at the end of line:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.p # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.p # debug print
  .yield_self { |id| "server:#{id}" }
```

# Compatibility issue

(1) Shorthand for `nil`

This spec change can introduce compatibility issue because `p` returns `nil` and do not output anything.
That is to say, `p` is shorthand of `nil`. Some code-golfers use it.

Maybe we can ignore them :p

(2) make public method

`Kernel#p` is private method, so if we typo `obj.x` to `obj.p` (not sure how it is feasible), it will be `NoMethodError` because of visibility.
We need to change this behavior.

# Note

## Past proposal and discussion

Endoh-san proposed same idea 10+ years ago [ruby-dev:29736] in Japanese.
I think we should revisit this idea because of `yield_self` introduction.

At this thread, Matz said "simple `p` shows `p(self)`, it is not clear".

[ruby-dev:30903]

```
  p

はどう動くのかとか(p selfと同じ、は変な気が)

  self.p(obj)

はどうなのかとか。その辺が解決(納得)できたら、ということで。
```

English translation:

```
What the behavior of (I feel strange that it is similar to `p(self)`):

  p

What happen on

  self.p(obj)
```

## pp

If this proposal is accepted, we also need to change `pp` behavior.

## gems

`tapp` method is provided by gem.
https://github.com/esminc/tapp 

I'd thought to propose this method into core. But I found that `p` is more shorter than `tapp`.
Disadvantage is `p` is too short and difficult to grep.




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

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

* [ruby-core:88438] [Ruby trunk Feature#14609] `Kernel#p` without args shows the receiver
       [not found] <redmine.issue-14609.20180316012909@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2018-08-10  7:03 ` [ruby-core:88426] " ko1
@ 2018-08-10 13:09 ` hanmac
  2018-08-11  1:49 ` [ruby-core:88444] " manga.osyo
                   ` (12 subsequent siblings)
  18 siblings, 0 replies; 19+ messages in thread
From: hanmac @ 2018-08-10 13:09 UTC (permalink / raw)
  To: ruby-core

Issue #14609 has been updated by Hanmac (Hans Mackowiak).


ko1 (Koichi Sasada) wrote:
> Hanmac: do you rely on this behavior?

Me? not so much, in general i don't trust the return value of print commands (print returns null)

it was months ago, i probably wanted to point out that the return value of `p` might be differ depending on the parameters
It might be inconsistency?


There is `Object.display` too but i don't use it much because it doesn't have new lines

----------------------------------------
Feature #14609: `Kernel#p` without args shows the receiver
https://bugs.ruby-lang.org/issues/14609#change-73493

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 2.6
----------------------------------------
# Abstract

`Kernel#p(obj)` prints obj as `inspect`ed.
How about to show the receiver if an argument is not given?

# Background

We recently introduce `yield_self` which encourages block chain.

https://zverok.github.io/blog/2018-01-24-yield_self.html
Quoted from this article, we can write method chain with blocks:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }
  .yield_self { |id| "server:#{id}" }
```

There is a small problem at debugging.
If we want to see the middle values in method/block chain, we need to insert `tap{|e| p e}`.

With above example,

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.tap{|e| p e} # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.tap{|e| p e} # debug print
  .yield_self { |id| "server:#{id}" }
```

# Proposal

`obj.p` shows same as `p(obj)`.

We can replace
  `block{...}.tap{|e| p e}`
to 
  `block{...}.p`

For above example, we can simply add `.p` at the end of line:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.p # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.p # debug print
  .yield_self { |id| "server:#{id}" }
```

# Compatibility issue

(1) Shorthand for `nil`

This spec change can introduce compatibility issue because `p` returns `nil` and do not output anything.
That is to say, `p` is shorthand of `nil`. Some code-golfers use it.

Maybe we can ignore them :p

(2) make public method

`Kernel#p` is private method, so if we typo `obj.x` to `obj.p` (not sure how it is feasible), it will be `NoMethodError` because of visibility.
We need to change this behavior.

# Note

## Past proposal and discussion

Endoh-san proposed same idea 10+ years ago [ruby-dev:29736] in Japanese.
I think we should revisit this idea because of `yield_self` introduction.

At this thread, Matz said "simple `p` shows `p(self)`, it is not clear".

[ruby-dev:30903]

```
  p

はどう動くのかとか(p selfと同じ、は変な気が)

  self.p(obj)

はどうなのかとか。その辺が解決(納得)できたら、ということで。
```

English translation:

```
What the behavior of (I feel strange that it is similar to `p(self)`):

  p

What happen on

  self.p(obj)
```

## pp

If this proposal is accepted, we also need to change `pp` behavior.

## gems

`tapp` method is provided by gem.
https://github.com/esminc/tapp 

I'd thought to propose this method into core. But I found that `p` is more shorter than `tapp`.
Disadvantage is `p` is too short and difficult to grep.




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

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

* [ruby-core:88444] [Ruby trunk Feature#14609] `Kernel#p` without args shows the receiver
       [not found] <redmine.issue-14609.20180316012909@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2018-08-10 13:09 ` [ruby-core:88438] " hanmac
@ 2018-08-11  1:49 ` manga.osyo
  2018-08-11  3:29 ` [ruby-core:88445] " nobu
                   ` (11 subsequent siblings)
  18 siblings, 0 replies; 19+ messages in thread
From: manga.osyo @ 2018-08-11  1:49 UTC (permalink / raw)
  To: ruby-core

Issue #14609 has been updated by osyo (manga osyo).


Good proposal.
This can solve the following problem.

```ruby
# NG: syntax error, unexpected ':', expecting '}'
p { name: "homu", age: 14 }

# OK:
{ name: "homu", age: 14 }.p
# => {:name=>"homu", :age=>14}
```


----------------------------------------
Feature #14609: `Kernel#p` without args shows the receiver
https://bugs.ruby-lang.org/issues/14609#change-73499

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 2.6
----------------------------------------
# Abstract

`Kernel#p(obj)` prints obj as `inspect`ed.
How about to show the receiver if an argument is not given?

# Background

We recently introduce `yield_self` which encourages block chain.

https://zverok.github.io/blog/2018-01-24-yield_self.html
Quoted from this article, we can write method chain with blocks:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }
  .yield_self { |id| "server:#{id}" }
```

There is a small problem at debugging.
If we want to see the middle values in method/block chain, we need to insert `tap{|e| p e}`.

With above example,

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.tap{|e| p e} # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.tap{|e| p e} # debug print
  .yield_self { |id| "server:#{id}" }
```

# Proposal

`obj.p` shows same as `p(obj)`.

We can replace
  `block{...}.tap{|e| p e}`
to 
  `block{...}.p`

For above example, we can simply add `.p` at the end of line:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.p # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.p # debug print
  .yield_self { |id| "server:#{id}" }
```

# Compatibility issue

(1) Shorthand for `nil`

This spec change can introduce compatibility issue because `p` returns `nil` and do not output anything.
That is to say, `p` is shorthand of `nil`. Some code-golfers use it.

Maybe we can ignore them :p

(2) make public method

`Kernel#p` is private method, so if we typo `obj.x` to `obj.p` (not sure how it is feasible), it will be `NoMethodError` because of visibility.
We need to change this behavior.

# Note

## Past proposal and discussion

Endoh-san proposed same idea 10+ years ago [ruby-dev:29736] in Japanese.
I think we should revisit this idea because of `yield_self` introduction.

At this thread, Matz said "simple `p` shows `p(self)`, it is not clear".

[ruby-dev:30903]

```
  p

はどう動くのかとか(p selfと同じ、は変な気が)

  self.p(obj)

はどうなのかとか。その辺が解決(納得)できたら、ということで。
```

English translation:

```
What the behavior of (I feel strange that it is similar to `p(self)`):

  p

What happen on

  self.p(obj)
```

## pp

If this proposal is accepted, we also need to change `pp` behavior.

## gems

`tapp` method is provided by gem.
https://github.com/esminc/tapp 

I'd thought to propose this method into core. But I found that `p` is more shorter than `tapp`.
Disadvantage is `p` is too short and difficult to grep.




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

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

* [ruby-core:88445] [Ruby trunk Feature#14609] `Kernel#p` without args shows the receiver
       [not found] <redmine.issue-14609.20180316012909@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2018-08-11  1:49 ` [ruby-core:88444] " manga.osyo
@ 2018-08-11  3:29 ` nobu
  2018-08-18 17:59 ` [ruby-core:88546] " shevegen
                   ` (10 subsequent siblings)
  18 siblings, 0 replies; 19+ messages in thread
From: nobu @ 2018-08-11  3:29 UTC (permalink / raw)
  To: ruby-core

Issue #14609 has been updated by nobu (Nobuyoshi Nakada).


osyo (manga osyo) wrote:
> Good proposal.
> This can solve the following problem.
> 
> ```ruby
> # NG: syntax error, unexpected ':', expecting '}'
> p { name: "homu", age: 14 }

You can use parentheses.
```ruby
p(name: "home", age: 14)
```



----------------------------------------
Feature #14609: `Kernel#p` without args shows the receiver
https://bugs.ruby-lang.org/issues/14609#change-73500

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 2.6
----------------------------------------
# Abstract

`Kernel#p(obj)` prints obj as `inspect`ed.
How about to show the receiver if an argument is not given?

# Background

We recently introduce `yield_self` which encourages block chain.

https://zverok.github.io/blog/2018-01-24-yield_self.html
Quoted from this article, we can write method chain with blocks:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }
  .yield_self { |id| "server:#{id}" }
```

There is a small problem at debugging.
If we want to see the middle values in method/block chain, we need to insert `tap{|e| p e}`.

With above example,

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.tap{|e| p e} # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.tap{|e| p e} # debug print
  .yield_self { |id| "server:#{id}" }
```

# Proposal

`obj.p` shows same as `p(obj)`.

We can replace
  `block{...}.tap{|e| p e}`
to 
  `block{...}.p`

For above example, we can simply add `.p` at the end of line:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.p # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.p # debug print
  .yield_self { |id| "server:#{id}" }
```

# Compatibility issue

(1) Shorthand for `nil`

This spec change can introduce compatibility issue because `p` returns `nil` and do not output anything.
That is to say, `p` is shorthand of `nil`. Some code-golfers use it.

Maybe we can ignore them :p

(2) make public method

`Kernel#p` is private method, so if we typo `obj.x` to `obj.p` (not sure how it is feasible), it will be `NoMethodError` because of visibility.
We need to change this behavior.

# Note

## Past proposal and discussion

Endoh-san proposed same idea 10+ years ago [ruby-dev:29736] in Japanese.
I think we should revisit this idea because of `yield_self` introduction.

At this thread, Matz said "simple `p` shows `p(self)`, it is not clear".

[ruby-dev:30903]

```
  p

はどう動くのかとか(p selfと同じ、は変な気が)

  self.p(obj)

はどうなのかとか。その辺が解決(納得)できたら、ということで。
```

English translation:

```
What the behavior of (I feel strange that it is similar to `p(self)`):

  p

What happen on

  self.p(obj)
```

## pp

If this proposal is accepted, we also need to change `pp` behavior.

## gems

`tapp` method is provided by gem.
https://github.com/esminc/tapp 

I'd thought to propose this method into core. But I found that `p` is more shorter than `tapp`.
Disadvantage is `p` is too short and difficult to grep.




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

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

* [ruby-core:88546] [Ruby trunk Feature#14609] `Kernel#p` without args shows the receiver
       [not found] <redmine.issue-14609.20180316012909@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2018-08-11  3:29 ` [ruby-core:88445] " nobu
@ 2018-08-18 17:59 ` shevegen
  2018-09-13  6:04 ` [ruby-core:88971] " nobu
                   ` (9 subsequent siblings)
  18 siblings, 0 replies; 19+ messages in thread
From: shevegen @ 2018-08-18 17:59 UTC (permalink / raw)
  To: ruby-core

Issue #14609 has been updated by shevegen (Robert A. Heiler).


I don't mind, personally. To me, the biggest improvement was
that we could omit doing:

    require 'pp'

;)

Since I did that a lot in my code. (I love pp; I think I use it
more than just p)

I personally have not been using (or needing) yield_self or tap so
far, so the change would probably not be of immediate benefit to
me; but probably also not require of me to change anything either.

To the name "tapp" - that name is a bit weird. To me it reads as
if we combine "tap" and then add a "p" to it. Reminds me of a
joke proposal to condense "end" into "enddd" and such. :D

To be fair, I  consider the name yield_self to be also weird :D -
but matz added an alias called "then" to it if I understand it
correctly (though the semantic confuses me a bit as well ... but
I don't really want to distract here since I don't really feel
too strongly either way; picking good names is not always easy).

On a side note, perhaps in the long run we could have something
to "experiment" with - like new or changed features in ruby that
have not been 100% approved in the sense of a name AND the associated
functionality, so we can try them out for some time, which may help
build a stronger opinion either way. (I mean this in general, not
just in regards to #p here).

It may still be best to ask matz again though. Syntax shortcuts
(syntactic sugar) has always been an area in ruby where code changes
has happened (e. g. yield_self to then, or omitting the end value
for infinite ranges and so forth).

----------------------------------------
Feature #14609: `Kernel#p` without args shows the receiver
https://bugs.ruby-lang.org/issues/14609#change-73607

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 2.6
----------------------------------------
# Abstract

`Kernel#p(obj)` prints obj as `inspect`ed.
How about to show the receiver if an argument is not given?

# Background

We recently introduce `yield_self` which encourages block chain.

https://zverok.github.io/blog/2018-01-24-yield_self.html
Quoted from this article, we can write method chain with blocks:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }
  .yield_self { |id| "server:#{id}" }
```

There is a small problem at debugging.
If we want to see the middle values in method/block chain, we need to insert `tap{|e| p e}`.

With above example,

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.tap{|e| p e} # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.tap{|e| p e} # debug print
  .yield_self { |id| "server:#{id}" }
```

# Proposal

`obj.p` shows same as `p(obj)`.

We can replace
  `block{...}.tap{|e| p e}`
to 
  `block{...}.p`

For above example, we can simply add `.p` at the end of line:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.p # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.p # debug print
  .yield_self { |id| "server:#{id}" }
```

# Compatibility issue

(1) Shorthand for `nil`

This spec change can introduce compatibility issue because `p` returns `nil` and do not output anything.
That is to say, `p` is shorthand of `nil`. Some code-golfers use it.

Maybe we can ignore them :p

(2) make public method

`Kernel#p` is private method, so if we typo `obj.x` to `obj.p` (not sure how it is feasible), it will be `NoMethodError` because of visibility.
We need to change this behavior.

# Note

## Past proposal and discussion

Endoh-san proposed same idea 10+ years ago [ruby-dev:29736] in Japanese.
I think we should revisit this idea because of `yield_self` introduction.

At this thread, Matz said "simple `p` shows `p(self)`, it is not clear".

[ruby-dev:30903]

```
  p

はどう動くのかとか(p selfと同じ、は変な気が)

  self.p(obj)

はどうなのかとか。その辺が解決(納得)できたら、ということで。
```

English translation:

```
What the behavior of (I feel strange that it is similar to `p(self)`):

  p

What happen on

  self.p(obj)
```

## pp

If this proposal is accepted, we also need to change `pp` behavior.

## gems

`tapp` method is provided by gem.
https://github.com/esminc/tapp 

I'd thought to propose this method into core. But I found that `p` is more shorter than `tapp`.
Disadvantage is `p` is too short and difficult to grep.




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

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

* [ruby-core:88971] [Ruby trunk Feature#14609] `Kernel#p` without args shows the receiver
       [not found] <redmine.issue-14609.20180316012909@ruby-lang.org>
                   ` (8 preceding siblings ...)
  2018-08-18 17:59 ` [ruby-core:88546] " shevegen
@ 2018-09-13  6:04 ` nobu
  2018-09-13  6:16 ` [ruby-core:88973] " matz
                   ` (8 subsequent siblings)
  18 siblings, 0 replies; 19+ messages in thread
From: nobu @ 2018-09-13  6:04 UTC (permalink / raw)
  To: ruby-core

Issue #14609 has been updated by nobu (Nobuyoshi Nakada).


How about:

```ruby
self.P
```

:P

----------------------------------------
Feature #14609: `Kernel#p` without args shows the receiver
https://bugs.ruby-lang.org/issues/14609#change-74001

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 2.6
----------------------------------------
# Abstract

`Kernel#p(obj)` prints obj as `inspect`ed.
How about to show the receiver if an argument is not given?

# Background

We recently introduce `yield_self` which encourages block chain.

https://zverok.github.io/blog/2018-01-24-yield_self.html
Quoted from this article, we can write method chain with blocks:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }
  .yield_self { |id| "server:#{id}" }
```

There is a small problem at debugging.
If we want to see the middle values in method/block chain, we need to insert `tap{|e| p e}`.

With above example,

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.tap{|e| p e} # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.tap{|e| p e} # debug print
  .yield_self { |id| "server:#{id}" }
```

# Proposal

`obj.p` shows same as `p(obj)`.

We can replace
  `block{...}.tap{|e| p e}`
to 
  `block{...}.p`

For above example, we can simply add `.p` at the end of line:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.p # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.p # debug print
  .yield_self { |id| "server:#{id}" }
```

# Compatibility issue

(1) Shorthand for `nil`

This spec change can introduce compatibility issue because `p` returns `nil` and do not output anything.
That is to say, `p` is shorthand of `nil`. Some code-golfers use it.

Maybe we can ignore them :p

(2) make public method

`Kernel#p` is private method, so if we typo `obj.x` to `obj.p` (not sure how it is feasible), it will be `NoMethodError` because of visibility.
We need to change this behavior.

# Note

## Past proposal and discussion

Endoh-san proposed same idea 10+ years ago [ruby-dev:29736] in Japanese.
I think we should revisit this idea because of `yield_self` introduction.

At this thread, Matz said "simple `p` shows `p(self)`, it is not clear".

[ruby-dev:30903]

```
  p

はどう動くのかとか(p selfと同じ、は変な気が)

  self.p(obj)

はどうなのかとか。その辺が解決(納得)できたら、ということで。
```

English translation:

```
What the behavior of (I feel strange that it is similar to `p(self)`):

  p

What happen on

  self.p(obj)
```

## pp

If this proposal is accepted, we also need to change `pp` behavior.

## gems

`tapp` method is provided by gem.
https://github.com/esminc/tapp 

I'd thought to propose this method into core. But I found that `p` is more shorter than `tapp`.
Disadvantage is `p` is too short and difficult to grep.




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

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

* [ruby-core:88973] [Ruby trunk Feature#14609] `Kernel#p` without args shows the receiver
       [not found] <redmine.issue-14609.20180316012909@ruby-lang.org>
                   ` (9 preceding siblings ...)
  2018-09-13  6:04 ` [ruby-core:88971] " nobu
@ 2018-09-13  6:16 ` matz
  2018-10-13 13:57 ` [ruby-core:89400] " lukas
                   ` (7 subsequent siblings)
  18 siblings, 0 replies; 19+ messages in thread
From: matz @ 2018-09-13  6:16 UTC (permalink / raw)
  To: ruby-core

Issue #14609 has been updated by matz (Yukihiro Matsumoto).


I vote for #tapp.

Matz.


----------------------------------------
Feature #14609: `Kernel#p` without args shows the receiver
https://bugs.ruby-lang.org/issues/14609#change-74002

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 2.6
----------------------------------------
# Abstract

`Kernel#p(obj)` prints obj as `inspect`ed.
How about to show the receiver if an argument is not given?

# Background

We recently introduce `yield_self` which encourages block chain.

https://zverok.github.io/blog/2018-01-24-yield_self.html
Quoted from this article, we can write method chain with blocks:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }
  .yield_self { |id| "server:#{id}" }
```

There is a small problem at debugging.
If we want to see the middle values in method/block chain, we need to insert `tap{|e| p e}`.

With above example,

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.tap{|e| p e} # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.tap{|e| p e} # debug print
  .yield_self { |id| "server:#{id}" }
```

# Proposal

`obj.p` shows same as `p(obj)`.

We can replace
  `block{...}.tap{|e| p e}`
to 
  `block{...}.p`

For above example, we can simply add `.p` at the end of line:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.p # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.p # debug print
  .yield_self { |id| "server:#{id}" }
```

# Compatibility issue

(1) Shorthand for `nil`

This spec change can introduce compatibility issue because `p` returns `nil` and do not output anything.
That is to say, `p` is shorthand of `nil`. Some code-golfers use it.

Maybe we can ignore them :p

(2) make public method

`Kernel#p` is private method, so if we typo `obj.x` to `obj.p` (not sure how it is feasible), it will be `NoMethodError` because of visibility.
We need to change this behavior.

# Note

## Past proposal and discussion

Endoh-san proposed same idea 10+ years ago [ruby-dev:29736] in Japanese.
I think we should revisit this idea because of `yield_self` introduction.

At this thread, Matz said "simple `p` shows `p(self)`, it is not clear".

[ruby-dev:30903]

```
  p

はどう動くのかとか(p selfと同じ、は変な気が)

  self.p(obj)

はどうなのかとか。その辺が解決(納得)できたら、ということで。
```

English translation:

```
What the behavior of (I feel strange that it is similar to `p(self)`):

  p

What happen on

  self.p(obj)
```

## pp

If this proposal is accepted, we also need to change `pp` behavior.

## gems

`tapp` method is provided by gem.
https://github.com/esminc/tapp 

I'd thought to propose this method into core. But I found that `p` is more shorter than `tapp`.
Disadvantage is `p` is too short and difficult to grep.




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

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

* [ruby-core:89400] [Ruby trunk Feature#14609] `Kernel#p` without args shows the receiver
       [not found] <redmine.issue-14609.20180316012909@ruby-lang.org>
                   ` (10 preceding siblings ...)
  2018-09-13  6:16 ` [ruby-core:88973] " matz
@ 2018-10-13 13:57 ` lukas
  2018-10-16 11:13 ` [ruby-core:89416] " zverok.offline
                   ` (6 subsequent siblings)
  18 siblings, 0 replies; 19+ messages in thread
From: lukas @ 2018-10-13 13:57 UTC (permalink / raw)
  To: ruby-core

Issue #14609 has been updated by docx (Lukas Dolezal).


Allowing debugging within `yield_self` is great! If `yield_self` was inspired by Elixir, we can look at Elixir for inspiration here as well:

https://hexdocs.pm/elixir/IO.html#inspect/2

One of the examples that is very interesting is that they have optional parameter to describe the printout:

```
[1, 2, 3]
|> IO.inspect(label: "before")
|> Enum.map(&(&1 * 2))
|> IO.inspect(label: "after")
|> Enum.sum
```

Prints:

```
before: [1, 2, 3]
after: [2, 4, 6]
```

I'm wondering, would that be something we would like in Ruby too?

The problem with the proposal of making `obj.p` is that the same method already is defined with parameter in the form of `p(obj)`.

Hence it would be impossible to implement `obj.p("after")` - as that would conflict with the current version of `p` with parameter.

My feeling is that given that both `yield_self` and `tap` are defined on `Object`, it does not feel to me right that `.p` should be defined on `Kernel`. I can see the advantage of already existing method there, but I feel like it would be wrong overloading.

Continuing on the argument that `yield_self` is defined on `Object`, should we define this "print inspect and return self" method be defined on `Object too`?

If so, we can keep the name `Object.p` and implement it with new interface when called as instance method and avoid making `Kernel.p` public:

```
Object.p() - p self.inspect and return self
Object.p(label:) - p "#{label}: #{self.inspect}" and return self
```

What do you think?

----------------------------------------
Feature #14609: `Kernel#p` without args shows the receiver
https://bugs.ruby-lang.org/issues/14609#change-74439

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 2.6
----------------------------------------
# Abstract

`Kernel#p(obj)` prints obj as `inspect`ed.
How about to show the receiver if an argument is not given?

# Background

We recently introduce `yield_self` which encourages block chain.

https://zverok.github.io/blog/2018-01-24-yield_self.html
Quoted from this article, we can write method chain with blocks:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }
  .yield_self { |id| "server:#{id}" }
```

There is a small problem at debugging.
If we want to see the middle values in method/block chain, we need to insert `tap{|e| p e}`.

With above example,

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.tap{|e| p e} # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.tap{|e| p e} # debug print
  .yield_self { |id| "server:#{id}" }
```

# Proposal

`obj.p` shows same as `p(obj)`.

We can replace
  `block{...}.tap{|e| p e}`
to 
  `block{...}.p`

For above example, we can simply add `.p` at the end of line:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.p # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.p # debug print
  .yield_self { |id| "server:#{id}" }
```

# Compatibility issue

(1) Shorthand for `nil`

This spec change can introduce compatibility issue because `p` returns `nil` and do not output anything.
That is to say, `p` is shorthand of `nil`. Some code-golfers use it.

Maybe we can ignore them :p

(2) make public method

`Kernel#p` is private method, so if we typo `obj.x` to `obj.p` (not sure how it is feasible), it will be `NoMethodError` because of visibility.
We need to change this behavior.

# Note

## Past proposal and discussion

Endoh-san proposed same idea 10+ years ago [ruby-dev:29736] in Japanese.
I think we should revisit this idea because of `yield_self` introduction.

At this thread, Matz said "simple `p` shows `p(self)`, it is not clear".

[ruby-dev:30903]

```
  p

はどう動くのかとか(p selfと同じ、は変な気が)

  self.p(obj)

はどうなのかとか。その辺が解決(納得)できたら、ということで。
```

English translation:

```
What the behavior of (I feel strange that it is similar to `p(self)`):

  p

What happen on

  self.p(obj)
```

## pp

If this proposal is accepted, we also need to change `pp` behavior.

## gems

`tapp` method is provided by gem.
https://github.com/esminc/tapp 

I'd thought to propose this method into core. But I found that `p` is more shorter than `tapp`.
Disadvantage is `p` is too short and difficult to grep.




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

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

* [ruby-core:89416] [Ruby trunk Feature#14609] `Kernel#p` without args shows the receiver
       [not found] <redmine.issue-14609.20180316012909@ruby-lang.org>
                   ` (11 preceding siblings ...)
  2018-10-13 13:57 ` [ruby-core:89400] " lukas
@ 2018-10-16 11:13 ` zverok.offline
  2018-10-16 13:10 ` [ruby-core:89419] " nobu
                   ` (5 subsequent siblings)
  18 siblings, 0 replies; 19+ messages in thread
From: zverok.offline @ 2018-10-16 11:13 UTC (permalink / raw)
  To: ruby-core

Issue #14609 has been updated by zverok (Victor Shepelev).


@docx That are pretty interesting comparison with Elixir!
In fact, what the examples show (to me) is a need for more powerful partial application of procs. E.g. what would be a parity for Elixir is something like...

```ruby
def p_with_label(label, obj)
  puts "#{label}#{obj.inspect}"
end

[1, 2, 3]
  .tap(&method(:p_with_label).curry['before: '])
  .map { |x| x * 2 }
  .tap(&method(:p_with_label).curry['after: '])
  .sum
```

This example already works, yet doesn't look VERY expressive, to be honest. I see two pretty different solutions to the problem:

First is **core**. Considering the shorten of `&method(:name)` is discussed for ages (and _almost_ agreed to be `&:.name`), it could be discussed on addition of more powerful partial application than current (mostly unusable) `Proc#curry` to language core. The result may look somewhat like (fantasizing)...

```ruby
[1, 2, 3]
  .tap(&:.p.with('before: '))
  .map { |x| x * 2 }
  .tap(&:.p.with('after: '))
  .sum
```

The second one is **rise of proc-producing libraries:**

```ruby
module Functional
  module_function
  def inspect(label:)
    ->(obj) { puts "#{label}#{obj.inspect}" }
  end
end

[1, 2, 3]
  .tap(&Functional.inspect(label: 'before: '))
  .map { |x| x * 2 }
  .tap(&Functional.inspect(label: 'after: '))
  .sum
```

----------------------------------------
Feature #14609: `Kernel#p` without args shows the receiver
https://bugs.ruby-lang.org/issues/14609#change-74455

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 2.6
----------------------------------------
# Abstract

`Kernel#p(obj)` prints obj as `inspect`ed.
How about to show the receiver if an argument is not given?

# Background

We recently introduce `yield_self` which encourages block chain.

https://zverok.github.io/blog/2018-01-24-yield_self.html
Quoted from this article, we can write method chain with blocks:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }
  .yield_self { |id| "server:#{id}" }
```

There is a small problem at debugging.
If we want to see the middle values in method/block chain, we need to insert `tap{|e| p e}`.

With above example,

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.tap{|e| p e} # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.tap{|e| p e} # debug print
  .yield_self { |id| "server:#{id}" }
```

# Proposal

`obj.p` shows same as `p(obj)`.

We can replace
  `block{...}.tap{|e| p e}`
to 
  `block{...}.p`

For above example, we can simply add `.p` at the end of line:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.p # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.p # debug print
  .yield_self { |id| "server:#{id}" }
```

# Compatibility issue

(1) Shorthand for `nil`

This spec change can introduce compatibility issue because `p` returns `nil` and do not output anything.
That is to say, `p` is shorthand of `nil`. Some code-golfers use it.

Maybe we can ignore them :p

(2) make public method

`Kernel#p` is private method, so if we typo `obj.x` to `obj.p` (not sure how it is feasible), it will be `NoMethodError` because of visibility.
We need to change this behavior.

# Note

## Past proposal and discussion

Endoh-san proposed same idea 10+ years ago [ruby-dev:29736] in Japanese.
I think we should revisit this idea because of `yield_self` introduction.

At this thread, Matz said "simple `p` shows `p(self)`, it is not clear".

[ruby-dev:30903]

```
  p

はどう動くのかとか(p selfと同じ、は変な気が)

  self.p(obj)

はどうなのかとか。その辺が解決(納得)できたら、ということで。
```

English translation:

```
What the behavior of (I feel strange that it is similar to `p(self)`):

  p

What happen on

  self.p(obj)
```

## pp

If this proposal is accepted, we also need to change `pp` behavior.

## gems

`tapp` method is provided by gem.
https://github.com/esminc/tapp 

I'd thought to propose this method into core. But I found that `p` is more shorter than `tapp`.
Disadvantage is `p` is too short and difficult to grep.




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

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

* [ruby-core:89419] [Ruby trunk Feature#14609] `Kernel#p` without args shows the receiver
       [not found] <redmine.issue-14609.20180316012909@ruby-lang.org>
                   ` (12 preceding siblings ...)
  2018-10-16 11:13 ` [ruby-core:89416] " zverok.offline
@ 2018-10-16 13:10 ` nobu
  2018-10-16 13:18 ` [ruby-core:89420] " zverok.offline
                   ` (4 subsequent siblings)
  18 siblings, 0 replies; 19+ messages in thread
From: nobu @ 2018-10-16 13:10 UTC (permalink / raw)
  To: ruby-core

Issue #14609 has been updated by nobu (Nobuyoshi Nakada).


zverok (Victor Shepelev) wrote:
> First is **core**. Considering the shorten of `&method(:name)` is discussed for ages (and _almost_ agreed to be `&:.name`),

You may want to say `&self.:name` at https://bugs.ruby-lang.org/issues/13581#change-72072?
It wouldn't be able to omit the receiver, syntactically.

----------------------------------------
Feature #14609: `Kernel#p` without args shows the receiver
https://bugs.ruby-lang.org/issues/14609#change-74457

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 2.6
----------------------------------------
# Abstract

`Kernel#p(obj)` prints obj as `inspect`ed.
How about to show the receiver if an argument is not given?

# Background

We recently introduce `yield_self` which encourages block chain.

https://zverok.github.io/blog/2018-01-24-yield_self.html
Quoted from this article, we can write method chain with blocks:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }
  .yield_self { |id| "server:#{id}" }
```

There is a small problem at debugging.
If we want to see the middle values in method/block chain, we need to insert `tap{|e| p e}`.

With above example,

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.tap{|e| p e} # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.tap{|e| p e} # debug print
  .yield_self { |id| "server:#{id}" }
```

# Proposal

`obj.p` shows same as `p(obj)`.

We can replace
  `block{...}.tap{|e| p e}`
to 
  `block{...}.p`

For above example, we can simply add `.p` at the end of line:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.p # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.p # debug print
  .yield_self { |id| "server:#{id}" }
```

# Compatibility issue

(1) Shorthand for `nil`

This spec change can introduce compatibility issue because `p` returns `nil` and do not output anything.
That is to say, `p` is shorthand of `nil`. Some code-golfers use it.

Maybe we can ignore them :p

(2) make public method

`Kernel#p` is private method, so if we typo `obj.x` to `obj.p` (not sure how it is feasible), it will be `NoMethodError` because of visibility.
We need to change this behavior.

# Note

## Past proposal and discussion

Endoh-san proposed same idea 10+ years ago [ruby-dev:29736] in Japanese.
I think we should revisit this idea because of `yield_self` introduction.

At this thread, Matz said "simple `p` shows `p(self)`, it is not clear".

[ruby-dev:30903]

```
  p

はどう動くのかとか(p selfと同じ、は変な気が)

  self.p(obj)

はどうなのかとか。その辺が解決(納得)できたら、ということで。
```

English translation:

```
What the behavior of (I feel strange that it is similar to `p(self)`):

  p

What happen on

  self.p(obj)
```

## pp

If this proposal is accepted, we also need to change `pp` behavior.

## gems

`tapp` method is provided by gem.
https://github.com/esminc/tapp 

I'd thought to propose this method into core. But I found that `p` is more shorter than `tapp`.
Disadvantage is `p` is too short and difficult to grep.




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

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

* [ruby-core:89420] [Ruby trunk Feature#14609] `Kernel#p` without args shows the receiver
       [not found] <redmine.issue-14609.20180316012909@ruby-lang.org>
                   ` (13 preceding siblings ...)
  2018-10-16 13:10 ` [ruby-core:89419] " nobu
@ 2018-10-16 13:18 ` zverok.offline
  2018-10-17 16:21 ` [ruby-core:89449] " ko1
                   ` (3 subsequent siblings)
  18 siblings, 0 replies; 19+ messages in thread
From: zverok.offline @ 2018-10-16 13:18 UTC (permalink / raw)
  To: ruby-core

Issue #14609 has been updated by zverok (Victor Shepelev).


> It wouldn't be able to omit the receiver, syntactically.

Hmm, I missed this point is the discussion. This limitation makes `:.` syntax sugar _substantially less useful_ :(

----------------------------------------
Feature #14609: `Kernel#p` without args shows the receiver
https://bugs.ruby-lang.org/issues/14609#change-74458

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 2.6
----------------------------------------
# Abstract

`Kernel#p(obj)` prints obj as `inspect`ed.
How about to show the receiver if an argument is not given?

# Background

We recently introduce `yield_self` which encourages block chain.

https://zverok.github.io/blog/2018-01-24-yield_self.html
Quoted from this article, we can write method chain with blocks:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }
  .yield_self { |id| "server:#{id}" }
```

There is a small problem at debugging.
If we want to see the middle values in method/block chain, we need to insert `tap{|e| p e}`.

With above example,

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.tap{|e| p e} # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.tap{|e| p e} # debug print
  .yield_self { |id| "server:#{id}" }
```

# Proposal

`obj.p` shows same as `p(obj)`.

We can replace
  `block{...}.tap{|e| p e}`
to 
  `block{...}.p`

For above example, we can simply add `.p` at the end of line:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.p # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.p # debug print
  .yield_self { |id| "server:#{id}" }
```

# Compatibility issue

(1) Shorthand for `nil`

This spec change can introduce compatibility issue because `p` returns `nil` and do not output anything.
That is to say, `p` is shorthand of `nil`. Some code-golfers use it.

Maybe we can ignore them :p

(2) make public method

`Kernel#p` is private method, so if we typo `obj.x` to `obj.p` (not sure how it is feasible), it will be `NoMethodError` because of visibility.
We need to change this behavior.

# Note

## Past proposal and discussion

Endoh-san proposed same idea 10+ years ago [ruby-dev:29736] in Japanese.
I think we should revisit this idea because of `yield_self` introduction.

At this thread, Matz said "simple `p` shows `p(self)`, it is not clear".

[ruby-dev:30903]

```
  p

はどう動くのかとか(p selfと同じ、は変な気が)

  self.p(obj)

はどうなのかとか。その辺が解決(納得)できたら、ということで。
```

English translation:

```
What the behavior of (I feel strange that it is similar to `p(self)`):

  p

What happen on

  self.p(obj)
```

## pp

If this proposal is accepted, we also need to change `pp` behavior.

## gems

`tapp` method is provided by gem.
https://github.com/esminc/tapp 

I'd thought to propose this method into core. But I found that `p` is more shorter than `tapp`.
Disadvantage is `p` is too short and difficult to grep.




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

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

* [ruby-core:89449] [Ruby trunk Feature#14609] `Kernel#p` without args shows the receiver
       [not found] <redmine.issue-14609.20180316012909@ruby-lang.org>
                   ` (14 preceding siblings ...)
  2018-10-16 13:18 ` [ruby-core:89420] " zverok.offline
@ 2018-10-17 16:21 ` ko1
  2019-03-11  4:50 ` [ruby-core:91744] " akr
                   ` (2 subsequent siblings)
  18 siblings, 0 replies; 19+ messages in thread
From: ko1 @ 2018-10-17 16:21 UTC (permalink / raw)
  To: ruby-core

Issue #14609 has been updated by ko1 (Koichi Sasada).


How about `obj.p!` or `obj.pp!` ?

----------------------------------------
Feature #14609: `Kernel#p` without args shows the receiver
https://bugs.ruby-lang.org/issues/14609#change-74491

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 2.6
----------------------------------------
# Abstract

`Kernel#p(obj)` prints obj as `inspect`ed.
How about to show the receiver if an argument is not given?

# Background

We recently introduce `yield_self` which encourages block chain.

https://zverok.github.io/blog/2018-01-24-yield_self.html
Quoted from this article, we can write method chain with blocks:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }
  .yield_self { |id| "server:#{id}" }
```

There is a small problem at debugging.
If we want to see the middle values in method/block chain, we need to insert `tap{|e| p e}`.

With above example,

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.tap{|e| p e} # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.tap{|e| p e} # debug print
  .yield_self { |id| "server:#{id}" }
```

# Proposal

`obj.p` shows same as `p(obj)`.

We can replace
  `block{...}.tap{|e| p e}`
to 
  `block{...}.p`

For above example, we can simply add `.p` at the end of line:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.p # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.p # debug print
  .yield_self { |id| "server:#{id}" }
```

# Compatibility issue

(1) Shorthand for `nil`

This spec change can introduce compatibility issue because `p` returns `nil` and do not output anything.
That is to say, `p` is shorthand of `nil`. Some code-golfers use it.

Maybe we can ignore them :p

(2) make public method

`Kernel#p` is private method, so if we typo `obj.x` to `obj.p` (not sure how it is feasible), it will be `NoMethodError` because of visibility.
We need to change this behavior.

# Note

## Past proposal and discussion

Endoh-san proposed same idea 10+ years ago [ruby-dev:29736] in Japanese.
I think we should revisit this idea because of `yield_self` introduction.

At this thread, Matz said "simple `p` shows `p(self)`, it is not clear".

[ruby-dev:30903]

```
  p

はどう動くのかとか(p selfと同じ、は変な気が)

  self.p(obj)

はどうなのかとか。その辺が解決(納得)できたら、ということで。
```

English translation:

```
What the behavior of (I feel strange that it is similar to `p(self)`):

  p

What happen on

  self.p(obj)
```

## pp

If this proposal is accepted, we also need to change `pp` behavior.

## gems

`tapp` method is provided by gem.
https://github.com/esminc/tapp 

I'd thought to propose this method into core. But I found that `p` is more shorter than `tapp`.
Disadvantage is `p` is too short and difficult to grep.




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

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

* [ruby-core:91744] [Ruby trunk Feature#14609] `Kernel#p` without args shows the receiver
       [not found] <redmine.issue-14609.20180316012909@ruby-lang.org>
                   ` (15 preceding siblings ...)
  2018-10-17 16:21 ` [ruby-core:89449] " ko1
@ 2019-03-11  4:50 ` akr
  2019-03-11  4:54 ` [ruby-core:91745] " nobu
  2019-03-11  4:59 ` [ruby-core:91746] " ko1
  18 siblings, 0 replies; 19+ messages in thread
From: akr @ 2019-03-11  4:50 UTC (permalink / raw)
  To: ruby-core

Issue #14609 has been updated by akr (Akira Tanaka).


matz (Yukihiro Matsumoto) wrote:
> I vote for #tapp.

I don't like #tappp (for `pp self` ).



----------------------------------------
Feature #14609: `Kernel#p` without args shows the receiver
https://bugs.ruby-lang.org/issues/14609#change-77020

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
# Abstract

`Kernel#p(obj)` prints obj as `inspect`ed.
How about to show the receiver if an argument is not given?

# Background

We recently introduce `yield_self` which encourages block chain.

https://zverok.github.io/blog/2018-01-24-yield_self.html
Quoted from this article, we can write method chain with blocks:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }
  .yield_self { |id| "server:#{id}" }
```

There is a small problem at debugging.
If we want to see the middle values in method/block chain, we need to insert `tap{|e| p e}`.

With above example,

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.tap{|e| p e} # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.tap{|e| p e} # debug print
  .yield_self { |id| "server:#{id}" }
```

# Proposal

`obj.p` shows same as `p(obj)`.

We can replace
  `block{...}.tap{|e| p e}`
to 
  `block{...}.p`

For above example, we can simply add `.p` at the end of line:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.p # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.p # debug print
  .yield_self { |id| "server:#{id}" }
```

# Compatibility issue

(1) Shorthand for `nil`

This spec change can introduce compatibility issue because `p` returns `nil` and do not output anything.
That is to say, `p` is shorthand of `nil`. Some code-golfers use it.

Maybe we can ignore them :p

(2) make public method

`Kernel#p` is private method, so if we typo `obj.x` to `obj.p` (not sure how it is feasible), it will be `NoMethodError` because of visibility.
We need to change this behavior.

# Note

## Past proposal and discussion

Endoh-san proposed same idea 10+ years ago [ruby-dev:29736] in Japanese.
I think we should revisit this idea because of `yield_self` introduction.

At this thread, Matz said "simple `p` shows `p(self)`, it is not clear".

[ruby-dev:30903]

```
  p

はどう動くのかとか(p selfと同じ、は変な気が)

  self.p(obj)

はどうなのかとか。その辺が解決(納得)できたら、ということで。
```

English translation:

```
What the behavior of (I feel strange that it is similar to `p(self)`):

  p

What happen on

  self.p(obj)
```

## pp

If this proposal is accepted, we also need to change `pp` behavior.

## gems

`tapp` method is provided by gem.
https://github.com/esminc/tapp 

I'd thought to propose this method into core. But I found that `p` is more shorter than `tapp`.
Disadvantage is `p` is too short and difficult to grep.




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

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

* [ruby-core:91745] [Ruby trunk Feature#14609] `Kernel#p` without args shows the receiver
       [not found] <redmine.issue-14609.20180316012909@ruby-lang.org>
                   ` (16 preceding siblings ...)
  2019-03-11  4:50 ` [ruby-core:91744] " akr
@ 2019-03-11  4:54 ` nobu
  2019-03-11  4:59 ` [ruby-core:91746] " ko1
  18 siblings, 0 replies; 19+ messages in thread
From: nobu @ 2019-03-11  4:54 UTC (permalink / raw)
  To: ruby-core

Issue #14609 has been updated by nobu (Nobuyoshi Nakada).


`obj.?`

----------------------------------------
Feature #14609: `Kernel#p` without args shows the receiver
https://bugs.ruby-lang.org/issues/14609#change-77021

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
# Abstract

`Kernel#p(obj)` prints obj as `inspect`ed.
How about to show the receiver if an argument is not given?

# Background

We recently introduce `yield_self` which encourages block chain.

https://zverok.github.io/blog/2018-01-24-yield_self.html
Quoted from this article, we can write method chain with blocks:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }
  .yield_self { |id| "server:#{id}" }
```

There is a small problem at debugging.
If we want to see the middle values in method/block chain, we need to insert `tap{|e| p e}`.

With above example,

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.tap{|e| p e} # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.tap{|e| p e} # debug print
  .yield_self { |id| "server:#{id}" }
```

# Proposal

`obj.p` shows same as `p(obj)`.

We can replace
  `block{...}.tap{|e| p e}`
to 
  `block{...}.p`

For above example, we can simply add `.p` at the end of line:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.p # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.p # debug print
  .yield_self { |id| "server:#{id}" }
```

# Compatibility issue

(1) Shorthand for `nil`

This spec change can introduce compatibility issue because `p` returns `nil` and do not output anything.
That is to say, `p` is shorthand of `nil`. Some code-golfers use it.

Maybe we can ignore them :p

(2) make public method

`Kernel#p` is private method, so if we typo `obj.x` to `obj.p` (not sure how it is feasible), it will be `NoMethodError` because of visibility.
We need to change this behavior.

# Note

## Past proposal and discussion

Endoh-san proposed same idea 10+ years ago [ruby-dev:29736] in Japanese.
I think we should revisit this idea because of `yield_self` introduction.

At this thread, Matz said "simple `p` shows `p(self)`, it is not clear".

[ruby-dev:30903]

```
  p

はどう動くのかとか(p selfと同じ、は変な気が)

  self.p(obj)

はどうなのかとか。その辺が解決(納得)できたら、ということで。
```

English translation:

```
What the behavior of (I feel strange that it is similar to `p(self)`):

  p

What happen on

  self.p(obj)
```

## pp

If this proposal is accepted, we also need to change `pp` behavior.

## gems

`tapp` method is provided by gem.
https://github.com/esminc/tapp 

I'd thought to propose this method into core. But I found that `p` is more shorter than `tapp`.
Disadvantage is `p` is too short and difficult to grep.




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

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

* [ruby-core:91746] [Ruby trunk Feature#14609] `Kernel#p` without args shows the receiver
       [not found] <redmine.issue-14609.20180316012909@ruby-lang.org>
                   ` (17 preceding siblings ...)
  2019-03-11  4:54 ` [ruby-core:91745] " nobu
@ 2019-03-11  4:59 ` ko1
  18 siblings, 0 replies; 19+ messages in thread
From: ko1 @ 2019-03-11  4:59 UTC (permalink / raw)
  To: ruby-core

Issue #14609 has been updated by ko1 (Koichi Sasada).


Discussion:

* `obj.p` has compatibility issue (some code expect `p` returns `nil`) -> reject
* `p!` is not danger. -> reject
* `tapp` seems long. `tappp` is weird
* `tap_p`, `tap_pp` are too long.
* introduce `obj.?` new method name -> don't modify syntax! (by matz). it is not predicate.

No conclusion.


----------------------------------------
Feature #14609: `Kernel#p` without args shows the receiver
https://bugs.ruby-lang.org/issues/14609#change-77022

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
# Abstract

`Kernel#p(obj)` prints obj as `inspect`ed.
How about to show the receiver if an argument is not given?

# Background

We recently introduce `yield_self` which encourages block chain.

https://zverok.github.io/blog/2018-01-24-yield_self.html
Quoted from this article, we can write method chain with blocks:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }
  .yield_self { |id| "server:#{id}" }
```

There is a small problem at debugging.
If we want to see the middle values in method/block chain, we need to insert `tap{|e| p e}`.

With above example,

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.tap{|e| p e} # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.tap{|e| p e} # debug print
  .yield_self { |id| "server:#{id}" }
```

# Proposal

`obj.p` shows same as `p(obj)`.

We can replace
  `block{...}.tap{|e| p e}`
to 
  `block{...}.p`

For above example, we can simply add `.p` at the end of line:

```
construct_url
  .yield_self { |url| Faraday.get(url) }.body
  .yield_self { |response| JSON.parse(response) }.p # debug print
  .dig('object', 'id')
  .yield_self { |id| id || '<undefined>' }.p # debug print
  .yield_self { |id| "server:#{id}" }
```

# Compatibility issue

(1) Shorthand for `nil`

This spec change can introduce compatibility issue because `p` returns `nil` and do not output anything.
That is to say, `p` is shorthand of `nil`. Some code-golfers use it.

Maybe we can ignore them :p

(2) make public method

`Kernel#p` is private method, so if we typo `obj.x` to `obj.p` (not sure how it is feasible), it will be `NoMethodError` because of visibility.
We need to change this behavior.

# Note

## Past proposal and discussion

Endoh-san proposed same idea 10+ years ago [ruby-dev:29736] in Japanese.
I think we should revisit this idea because of `yield_self` introduction.

At this thread, Matz said "simple `p` shows `p(self)`, it is not clear".

[ruby-dev:30903]

```
  p

はどう動くのかとか(p selfと同じ、は変な気が)

  self.p(obj)

はどうなのかとか。その辺が解決(納得)できたら、ということで。
```

English translation:

```
What the behavior of (I feel strange that it is similar to `p(self)`):

  p

What happen on

  self.p(obj)
```

## pp

If this proposal is accepted, we also need to change `pp` behavior.

## gems

`tapp` method is provided by gem.
https://github.com/esminc/tapp 

I'd thought to propose this method into core. But I found that `p` is more shorter than `tapp`.
Disadvantage is `p` is too short and difficult to grep.




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

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

end of thread, other threads:[~2019-03-11  4:59 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-14609.20180316012909@ruby-lang.org>
2018-03-16  1:29 ` [ruby-core:86152] [Ruby trunk Feature#14609] `Kernel#p` without args shows the receiver ko1
2018-03-16  3:11 ` [ruby-core:86153] " mame
2018-03-16  8:00 ` [ruby-core:86155] " zverok.offline
2018-03-16 10:55 ` [ruby-core:86156] " hanmac
2018-08-10  7:03 ` [ruby-core:88426] " ko1
2018-08-10 13:09 ` [ruby-core:88438] " hanmac
2018-08-11  1:49 ` [ruby-core:88444] " manga.osyo
2018-08-11  3:29 ` [ruby-core:88445] " nobu
2018-08-18 17:59 ` [ruby-core:88546] " shevegen
2018-09-13  6:04 ` [ruby-core:88971] " nobu
2018-09-13  6:16 ` [ruby-core:88973] " matz
2018-10-13 13:57 ` [ruby-core:89400] " lukas
2018-10-16 11:13 ` [ruby-core:89416] " zverok.offline
2018-10-16 13:10 ` [ruby-core:89419] " nobu
2018-10-16 13:18 ` [ruby-core:89420] " zverok.offline
2018-10-17 16:21 ` [ruby-core:89449] " ko1
2019-03-11  4:50 ` [ruby-core:91744] " akr
2019-03-11  4:54 ` [ruby-core:91745] " nobu
2019-03-11  4:59 ` [ruby-core:91746] " ko1

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).