3 ms·
Because it can be used to wrap any expression. I haven't seen a debug function that returns the value again anywhere else.
by the_duke 8y ago
Because it can be used to wrap any expression.
I haven't seen a debug function that returns the value again anywhere else.
- eslaught 8y agoIt was definitely in Arc first, and probably in other lisps before that: https://github.com/arclanguage/anarki/blob/master/arc.arc#L1628-L1631 https://github.com/arclanguage/anarki/blob/master/arc.arc#L1... Edit: Yes, it's in Common Lisp too, so it goes back at least to the 1980s and probably further. http://www.lispworks.com/documentation/HyperSpec/Body/f_wr_pr.htm http://www.lispworks.com/documentation/HyperSpec/Body/f_wr_p...
- yxhuvud 8y agoThe debug printing method p in Ruby have been returning it's argument for years now. Dbg seems possibly better for the usecase though as you get the location as well.
- majewsky 8y agoIt also reminds me of Ruby's .tap { |x| puts x } For those of you who don't know Ruby, its map/filter/reduce functions chain like this: values.map { |x| x + 2 }.select { |x| x > 3 } So when you want to look at an intermediate result, there's the .tap() method that runs a lambda with that intermediate result, then passes it on to the next step in the chain. [0, 1, 2, 3].map { |x| x + 2 }.tap { |x| puts x }.select { |x| x > 3 } This returns [4, 5] after printing [2, 3, 4, 5]. ("puts" is Ruby's println.)
- killercup 8y agoTook me a while to find it, but Rust's iterators have an `.inspect` method that gives you a read-only reference, so println debugging works fine. For more advanced tap-like stuff, use the `tap` crate (which allows you to write `array.tap(|xs| xs.sort())` for example, even though `sort` mutates in place and doesn't return the array).