* Inspecting functions returning complicated values @ 2014-09-30 23:58 Marcin Borkowski 2014-10-01 0:46 ` Drew Adams ` (2 more replies) 0 siblings, 3 replies; 7+ messages in thread From: Marcin Borkowski @ 2014-09-30 23:58 UTC (permalink / raw) To: help-gnu-emacs@gnu.org Hi list, assume that I want to inspect a function whose return value is a long, deeply nested list. I found this way to present it in a readable way: M-: (setq blah-blah (function-returning-hairy-stuff)) C-h C-v blah-blah This seems a bit awkward, however. Is there a better/cleaner way? TIA, -- Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Adam Mickiewicz University ^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: Inspecting functions returning complicated values 2014-09-30 23:58 Inspecting functions returning complicated values Marcin Borkowski @ 2014-10-01 0:46 ` Drew Adams 2014-10-01 1:59 ` Eric Abrahamsen [not found] ` <mailman.10126.1412124387.1147.help-gnu-emacs@gnu.org> 2 siblings, 0 replies; 7+ messages in thread From: Drew Adams @ 2014-10-01 0:46 UTC (permalink / raw) To: Marcin Borkowski, help-gnu-emacs > assume that I want to inspect a function whose return value is a > long, deeply nested list. I found this way to present it in a > readable way: > > M-: (setq blah-blah (function-returning-hairy-stuff)) > C-h C-v blah-blah > > This seems a bit awkward, however. Is there a better/cleaner way? M-x pp-eval-expression ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Inspecting functions returning complicated values 2014-09-30 23:58 Inspecting functions returning complicated values Marcin Borkowski 2014-10-01 0:46 ` Drew Adams @ 2014-10-01 1:59 ` Eric Abrahamsen [not found] ` <mailman.10126.1412124387.1147.help-gnu-emacs@gnu.org> 2 siblings, 0 replies; 7+ messages in thread From: Eric Abrahamsen @ 2014-10-01 1:59 UTC (permalink / raw) To: help-gnu-emacs Marcin Borkowski <mbork@wmi.amu.edu.pl> writes: > Hi list, > > assume that I want to inspect a function whose return value is a long, > deeply nested list. I found this way to present it in a readable way: > > M-: (setq blah-blah (function-returning-hairy-stuff)) > C-h C-v blah-blah > > This seems a bit awkward, however. Is there a better/cleaner way? > > TIA, It can also be interesting to start an IELM repl and do things to the return value there. ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <mailman.10126.1412124387.1147.help-gnu-emacs@gnu.org>]
* Re: Inspecting functions returning complicated values [not found] ` <mailman.10126.1412124387.1147.help-gnu-emacs@gnu.org> @ 2014-10-02 0:35 ` Emanuel Berg 2014-10-02 3:06 ` Drew Adams 0 siblings, 1 reply; 7+ messages in thread From: Emanuel Berg @ 2014-10-02 0:35 UTC (permalink / raw) To: help-gnu-emacs Drew Adams <drew.adams@oracle.com> writes: > M-x pp-eval-expression What improvement is that? (message "hello") (eval-expression (message "hello")) (pp-eval-expression (message "hello")) Here, the first two seem to do the same, namely put it in the echo area for inspection and then you can use `C-h e'. pp-eval-expression also puts it in *Messages* but doesn't echo it what I can see. But I agree with the other posters, IELM, with (ielm) is the best way to do this. -- underground experts united ^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: Inspecting functions returning complicated values 2014-10-02 0:35 ` Emanuel Berg @ 2014-10-02 3:06 ` Drew Adams 0 siblings, 0 replies; 7+ messages in thread From: Drew Adams @ 2014-10-02 3:06 UTC (permalink / raw) To: Emanuel Berg, help-gnu-emacs > > M-x pp-eval-expression > > What improvement is that? > (message "hello") > (eval-expression (message "hello")) > (pp-eval-expression (message "hello")) > > Here, the first two seem to do the same, namely put it > in the echo area for inspection and then you can use > `C-h e'. pp-eval-expression also puts it in *Messages* > but doesn't echo it what I can see. Maybe it's because you don't know what you're doing? Maybe you didn't read the doc for `pp-eval-expression'? Hard to guess. Just what are you trying to accomplish? `pp-eval-expression' is a function. As such, it evaluates its argument. What does the doc string tell us it does with its argument? Evaluate EXPRESSION and pretty-print its value. Also add the value to the front of the list in the variable `values'. So let's see what you did. Somehow, you evaluated the sexp `(pp-eval-expression (message "hello"))'. Perhaps you used `C-x C-e', or maybe `M-:', to do that? However you did it, that evaluates the sexp `(message "hello")' and passes the resulting value to function `pp-eval-expression'. That resulting value is the string "hello". So what does `pp-eval-expression' then do with its argument, "hello"? It evaluates it! And then it pretty-prints the result of that evaluation. "hello" evaluates to "hello". OK, whatever. Since the pretty-printed representation of string "hello" is "hello", `pp-eval-expression' prints "hello" in the echo area. End of story...almost. And then, depending on how you evaluated `(pp-eval-expression (message "hello"))', you might see the value of _that_ sexp echoed (in the echo area). What is that value? `nil'. `pp-eval-expression' is used for its side effect, not its value. Why do `C-x C-e' and `M-:' print the value of the sexp they evaluate? Ask them. But it is generally handy that they do. So in the echo area, and in `*Messages*', two things are printed: a pretty-print of the string "hello", followed by `nil'. In addition, you have access to the result of evaluating the argument sexp (the string "hello"), which is "hello", as the car of global variable `values': `C-h v values' or `M-: (car values)'. Now what was it that you _wanted_ to do? Typically, one uses `pp-eval-expression' to (1) evaluate an expression and then (2) pretty-print the result of evaluation. Because it wants to evaluate an expression argument, you need to pass it an expression, and `pp-eval-expression' of course evaluates its argument first, before the function body executes. (It is not a macro or a special form.) So a typical use of `pp-eval-expression' would be something like `(pp-eval-expression 'ctl-x-map)' or `(pp-eval-expression '(nth 2 (nth 2 font-lock-keywords)))', and the result of pretty-printing would look something like this: (keymap #^[nil nil keymap #^^[3 0 pop-global-mark nil list-buffers save-buffers-kill-terminal list-directory eval-last-sexp find-file nil nil indent-rigidly nil kmacro-keymap downcase-region (keymap (108 . set-language-environment) (99 . universal-coding-system-argument) ... or this: (2 (let ((type (get (intern-soft (match-string 1)) 'lisp-define-type))) (cond ((eq type 'var) font-lock-variable-name-face) ((eq type 'type) font-lock-type-face) (t font-lock-function-name-face))) nil t) The first of these is the same kind of representation you see if you use `C-h v ctl-x-map'. Why? Because... `describe-variable' uses function `pp', just like `pp-eval-expression' does. But again, depending on how you evaluate the `pp-eval-expression' sexp, you might be fooled. If you evaluate it interactively then you might be fooled by the _command_ that you use to evaluate it. Using `M-:' or `C-x C-e' (without a prefix arg) prints the value of the evaluated `pp-eval-expression' sexp, right after `pp-eval-expression' prints the value of its argument expression. The hand is quicker than the eye. But lo and behold, `pp-eval-expression' is a command! And that means you can execute it using `M-x' or bind it to a key. What happens then? M-x pp-eval-expression RET Eval: (nth 2 (nth 2 font-lock-keywords)) RET And the pretty-printed value is shown in buffer `*Pp Eval Output*'. And a message tells you "See buffer *Pp Eval Output*." (That message should not end in a period, but let's not nitpick.) But wait, how come we didn't need to quote the expression? Because interactively `pp-eval-expression' uses `read--expression', and that, well,...reads an expression. In this case there is no need to evaluate something to provide `pp-eval-expression' with its expression argument. > But I agree with the other posters, IELM, with (ielm) > is the best way to do this. Good to know. To do what? ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <mailman.10124.1412121528.1147.help-gnu-emacs@gnu.org>]
* Re: Inspecting functions returning complicated values [not found] <mailman.10124.1412121528.1147.help-gnu-emacs@gnu.org> @ 2014-10-01 0:36 ` Emanuel Berg 2014-10-01 14:43 ` Pascal J. Bourguignon 1 sibling, 0 replies; 7+ messages in thread From: Emanuel Berg @ 2014-10-01 0:36 UTC (permalink / raw) To: help-gnu-emacs Marcin Borkowski <mbork@wmi.amu.edu.pl> writes: > M-: (setq blah-blah (function-returning-hairy-stuff)) > C-h C-v blah-blah > > This seems a bit awkward, however. Is there a > better/cleaner way? Ha! Interesting question. I guess I would simply write the above in an Elisp file (with an .el extension) and then evaluate it. (Or even insert it into the buffer.) Otherwise you can just do it as you do (the eval-expression or M-: part) and then `C-h e' or view-echo-area-messages to examine the result in the *Messages* buffer. -- underground experts united ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Inspecting functions returning complicated values [not found] <mailman.10124.1412121528.1147.help-gnu-emacs@gnu.org> 2014-10-01 0:36 ` Emanuel Berg @ 2014-10-01 14:43 ` Pascal J. Bourguignon 1 sibling, 0 replies; 7+ messages in thread From: Pascal J. Bourguignon @ 2014-10-01 14:43 UTC (permalink / raw) To: help-gnu-emacs Marcin Borkowski <mbork@wmi.amu.edu.pl> writes: > Hi list, > > assume that I want to inspect a function whose return value is a long, > deeply nested list. I found this way to present it in a readable way: > > M-: (setq blah-blah (function-returning-hairy-stuff)) > C-h C-v blah-blah > > This seems a bit awkward, however. Is there a better/cleaner way? In most any (writable) buffer, you can type: (prog1 (terpri) (pp (function-returning-hairy-stuff))) C-u C-x C-e This won't work only in buffer where C-x C-e is not bound to eval-last-sexp. In those buffers you can type C-u M-x eval-last-sexp RET instead of C-u C-x C-e You can also use ielm: M-x ielm RET (pp (function-returning-hairy-stuff)) RET (pp (other-function-returning-hairy-stuff)) RET ;; etc… -- __Pascal Bourguignon__ http://www.informatimago.com/ “The factory of the future will have only two employees, a man and a dog. The man will be there to feed the dog. The dog will be there to keep the man from touching the equipment.” -- Carl Bass CEO Autodesk ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-10-02 3:06 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-09-30 23:58 Inspecting functions returning complicated values Marcin Borkowski 2014-10-01 0:46 ` Drew Adams 2014-10-01 1:59 ` Eric Abrahamsen [not found] ` <mailman.10126.1412124387.1147.help-gnu-emacs@gnu.org> 2014-10-02 0:35 ` Emanuel Berg 2014-10-02 3:06 ` Drew Adams [not found] <mailman.10124.1412121528.1147.help-gnu-emacs@gnu.org> 2014-10-01 0:36 ` Emanuel Berg 2014-10-01 14:43 ` Pascal J. Bourguignon
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).