unofficial mirror of emacs-tangents@gnu.org
 help / color / mirror / Atom feed
* 2016-05-23 Emacs News
@ 2016-05-23 16:44 Sacha Chua
  2016-06-10  0:04 ` Rolf Ade
  0 siblings, 1 reply; 9+ messages in thread
From: Sacha Chua @ 2016-05-23 16:44 UTC (permalink / raw)
  To: emacs-tangents


[-- Attachment #1.1: Type: text/plain, Size: 6812 bytes --]

2016-05-23 Emacs News
=====================

  - Coding:
    - [Literal values and destructive functions] (http://mbork.pl/2016-05-23_Literal_values_and_destructive_functions)
    - [Complete line with ivy-mode] (http://blog.binchen.org/posts/complete-line-with-ivy-mode.html)
    - [Making git and Emacs' eshell work together] (http://hexmode.com/2016/05/making-git-and-emacs-eshell-work-together/)
    - [Locally configure or disable show-paren-mode] (http://endlessparentheses.com/locally-configure-or-disable-show-paren-mode.html?source=rss)
    - [One of my favorite things about Helm: live git grep searching] (http://i.imgur.com/T5lGV0M.gif) ([Reddit] (https://www.reddit.com/r/emacs/comments/4kji7j/one_of_my_favorite_things_about_helm_live_git/))
    - [Stripping "all space" lines created while typing] (https://www.reddit.com/r/emacs/comments/4k7jjc/stripping_all_space_lines_created_while_typing/) - ws-butler, too
    - [Reference look up in JS2 mode.] (https://github.com/NicolasPetton/xref-js2) ([Reddit] (https://www.reddit.com/r/emacs/comments/4jz8wp/reference_look_up_in_js2_mode/))
    - [nlinum-relative-mode - Emacs relative line number besed on nlinum-mode] (https://github.com/CodeFalling/nlinum-relative) ([Reddit] (https://www.reddit.com/r/emacs/comments/4k6eme/nlinumrelativemode_emacs_relative_line_number/))
    - [emacs/git workflow] (https://www.reddit.com/r/emacs/comments/4jys9m/emacsgit_workflow/)
    - ["protip" disable global-semanticdb-minor-mode for a faster C IDE] (https://www.reddit.com/r/emacs/comments/4jsnd9/protip_disable_globalsemanticdbminormode_for_a/)
  - Emacs Lisp:
    - [Emacs Lisp closures demystified] (http://mbork.pl/2016-05-17_Emacs_Lisp_closures_demystified)
    - [Emacs Testing with Assess] (http://www.russet.org.uk/blog/3135) ([Reddit] (https://www.reddit.com/r/emacs/comments/4k7elj/emacs_testing_with_assess/))
    - [Hook Helpers - A Package to Cleanly Add Functions to Hooks] (https://savannah.nongnu.org/projects/hook-helpers-el/) ([Reddit] (https://www.reddit.com/r/emacs/comments/4kh3fb/hook_helpers_a_package_to_cleanly_add_functions/))
    - [Indenting the statements after case labels in c-mode] (https://www.reddit.com/r/emacs/comments/4kej9e/indenting_the_statements_after_case_labels_in/) - sample indent function
  - Other:
    - [blog-admin and Nikola] (https://punchagan.muse-amuse.in/posts/blog-admin-and-nikola.html)
    - [Three Ways to Quote in your Notes with Org-Mode] (https://www.wisdomandwonder.com/article/10250/three-ways-to-quote-in-your-notes-with-org-mode)
    - [Emacs: Find number of days between dates] (http://xenodium.com/#emacs-find-number-of-days-between-dates)
    - [emacs 25.1 NEWS] (http://puntoblogspot.blogspot.com/2016/05/emacs-251-news.html)
    - [Renaming Files] (https://alexschroeder.ch/wiki/2016-05-18_Renaming_Files)
    - [Make Messages Buffer modifiable in Emacs 24.4] (http://blog.binchen.org/posts/make-messages-buffer-modifiable-in-emacs-24-4.html)
    - [(mastering Emacs) book is 50% off] (https://www.reddit.com/r/emacs/comments/4kk2b8/mastering_emacs_book_is_50_off/)
    - [Emacs for writing ? Tell me your tricks !] (https://www.reddit.com/r/emacs/comments/4kj7cv/emacs_for_writing_tell_me_your_tricks/)
    - [The Universal Latin input method for Emacs.] (http://www.gkayaalp.com/releases/gk-unilat-1.2.el) ([Reddit] (https://www.reddit.com/r/emacs/comments/4kdo1m/the_universal_latin_input_method_for_emacs/))
    - [A Collection of Ridiculously Useful eXtensions for Emacs] (https://github.com/bbatsov/crux) ([Reddit] (https://www.reddit.com/r/emacs/comments/4ka2oo/a_collection_of_ridiculously_useful_extensions/))
    - [GNU Emacs pretest 25.0.94 now available] (https://lists.gnu.org/archive/html/emacs-devel/2016-05/msg00408.html) ([Reddit] (https://www.reddit.com/r/emacs/comments/4ju5qq/gnu_emacs_pretest_25094_now_available/))
    - [What's the 20% of emacs/spacemacs that you use 80% of the time?] (https://www.reddit.com/r/emacs/comments/4jkwj0/whats_the_20_of_emacsspacemacs_that_you_use_80_of/)
    - [Evil tabbar - rearranging tabs] (https://www.reddit.com/r/emacs/comments/4kflrk/evil_tabbar_rearranging_tabs/) - eyebrowse
    - [Can I kill idle buffers?] (https://www.reddit.com/r/emacs/comments/4joygc/can_i_kill_idle_buffers/) clean-buffer-list
    - [Assimilate Emacs packages using Git submodules] (https://www.reddit.com/r/emacs/comments/4js0tr/assimilate_emacs_packages_using_git_submodules/)
    - [Living in Emacs (22:52, German)] (https://www.youtube.com/watch?v=qon4mg9C0ZY)
  - New packages:
    - annotate-depth <http://melpa.org/#/annotate-depth>: Annotate buffer if indentation depth is beyond threshold.
    - cursor-in-brackets <http://melpa.org/#/cursor-in-brackets>: move cursor in brackets/quotes when right bracket/quote is inserted
    - datetime <http://melpa.org/#/datetime>: Parsing, formatting and matching timestamps
    - datetime-format <http://melpa.org/#/datetime-format>: Datetime functions
    - fastdef <http://melpa.org/#/fastdef>: Insert terminology from Google top search results
    - highlight-operators <http://melpa.org/#/highlight-operators>: a face for operators in programming modes
    - immortal-scratch <http://melpa.org/#/immortal-scratch>: respawn the scratch buffer when it's killed
    - ivy-gitlab <http://melpa.org/#/ivy-gitlab>: Ivy interface to Gitlab
    - ivy-hydra <http://melpa.org/#/ivy-hydra>: Additional key bindings for Ivy
    - judge-indent <http://melpa.org/#/judge-indent>: judge indent and tab widths
    - llvm-mode <http://melpa.org/#/llvm-mode>: Major mode for the LLVM assembler language.
    - markdown-mac-link <http://melpa.org/#/markdown-mac-link>: Insert Markdown links to items selected in various Mac apps
    - modern-cpp-font-lock <http://melpa.org/#/modern-cpp-font-lock>: Font-locking for "Modern C++"
    - org-eww <http://melpa.org/#/org-eww>: automatically use eww to preview current org-file when save
    - restclient-test <http://melpa.org/#/restclient-test>: Run tests with restclient.el
    - timecop <http://melpa.org/#/timecop>: Freeze Time for testing
    - smart-yank <https://elpa.gnu.org/packages/smart-yank.html>: A different approach of yank pointer handling

  Links from [reddit.com/r/emacs] (http://reddit.com/r/emacs/new), [/r/orgmode] (http://reddit.com/r/orgmode), [Hacker News] (https://hn.algolia.com/?query=emacs&sort=byDate&prefix&page=0&dateRange=all&type=story), [planet.emacsen.org] (http://planet.emacsen.org), [Youtube] (https://www.youtube.com/results?search_query=emacs&search_sort=video_date_uploaded), the changes to the [Emacs NEWS file] (http://git.savannah.gnu.org/cgit/emacs.git/log/etc/NEWS), and [emacs-devel] (http://lists.gnu.org/archive/html/emacs-devel/2016-05).

  [Past Emacs News round-ups] (http://sachachua.com/blog/category/emacs-news)


[-- Attachment #1.2: Type: text/html, Size: 8254 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: emacs-news.org --]
[-- Type: text/x-org; name=emacs-news.org, Size: 6479 bytes --]

* 2016-05-23 Emacs News
#+RESULTS: 
- Coding:
  - [[http://mbork.pl/2016-05-23_Literal_values_and_destructive_functions][Literal values and destructive functions]]
  - [[http://blog.binchen.org/posts/complete-line-with-ivy-mode.html][Complete line with ivy-mode]]
  - [[http://hexmode.com/2016/05/making-git-and-emacs-eshell-work-together/][Making git and Emacs' eshell work together]]
  - [[http://endlessparentheses.com/locally-configure-or-disable-show-paren-mode.html?source=rss][Locally configure or disable show-paren-mode]]
  - [[http://i.imgur.com/T5lGV0M.gif][One of my favorite things about Helm: live git grep searching]] ([[https://www.reddit.com/r/emacs/comments/4kji7j/one_of_my_favorite_things_about_helm_live_git/][Reddit]])
  - [[https://www.reddit.com/r/emacs/comments/4k7jjc/stripping_all_space_lines_created_while_typing/][Stripping "all space" lines created while typing]] - ws-butler, too
  - [[https://github.com/NicolasPetton/xref-js2][Reference look up in JS2 mode.]] ([[https://www.reddit.com/r/emacs/comments/4jz8wp/reference_look_up_in_js2_mode/][Reddit]])
  - [[https://github.com/CodeFalling/nlinum-relative][nlinum-relative-mode - Emacs relative line number besed on nlinum-mode]] ([[https://www.reddit.com/r/emacs/comments/4k6eme/nlinumrelativemode_emacs_relative_line_number/][Reddit]])
  - [[https://www.reddit.com/r/emacs/comments/4jys9m/emacsgit_workflow/][emacs/git workflow]]
  - [[https://www.reddit.com/r/emacs/comments/4jsnd9/protip_disable_globalsemanticdbminormode_for_a/]["protip" disable global-semanticdb-minor-mode for a faster C IDE]]
- Emacs Lisp:
  - [[http://mbork.pl/2016-05-17_Emacs_Lisp_closures_demystified][Emacs Lisp closures demystified]]
  - [[http://www.russet.org.uk/blog/3135][Emacs Testing with Assess]] ([[https://www.reddit.com/r/emacs/comments/4k7elj/emacs_testing_with_assess/][Reddit]])
  - [[https://savannah.nongnu.org/projects/hook-helpers-el/][Hook Helpers - A Package to Cleanly Add Functions to Hooks]] ([[https://www.reddit.com/r/emacs/comments/4kh3fb/hook_helpers_a_package_to_cleanly_add_functions/][Reddit]])
  - [[https://www.reddit.com/r/emacs/comments/4kej9e/indenting_the_statements_after_case_labels_in/][Indenting the statements after case labels in c-mode]] - sample indent function
- Other:
  - [[https://punchagan.muse-amuse.in/posts/blog-admin-and-nikola.html][blog-admin and Nikola]]
  - [[https://www.wisdomandwonder.com/article/10250/three-ways-to-quote-in-your-notes-with-org-mode][Three Ways to Quote in your Notes with Org-Mode]]
  - [[http://xenodium.com/#emacs-find-number-of-days-between-dates][Emacs: Find number of days between dates]]
  - [[http://puntoblogspot.blogspot.com/2016/05/emacs-251-news.html][emacs 25.1 NEWS]]
  - [[https://alexschroeder.ch/wiki/2016-05-18_Renaming_Files][Renaming Files]]
  - [[http://blog.binchen.org/posts/make-messages-buffer-modifiable-in-emacs-24-4.html][Make Messages Buffer modifiable in Emacs 24.4]]
  - [[https://www.reddit.com/r/emacs/comments/4kk2b8/mastering_emacs_book_is_50_off/][(mastering Emacs) book is 50% off]]
  - [[https://www.reddit.com/r/emacs/comments/4kj7cv/emacs_for_writing_tell_me_your_tricks/][Emacs for writing ? Tell me your tricks !]]
  - [[http://www.gkayaalp.com/releases/gk-unilat-1.2.el][The Universal Latin input method for Emacs.]] ([[https://www.reddit.com/r/emacs/comments/4kdo1m/the_universal_latin_input_method_for_emacs/][Reddit]])
  - [[https://github.com/bbatsov/crux][A Collection of Ridiculously Useful eXtensions for Emacs]] ([[https://www.reddit.com/r/emacs/comments/4ka2oo/a_collection_of_ridiculously_useful_extensions/][Reddit]])
  - [[https://lists.gnu.org/archive/html/emacs-devel/2016-05/msg00408.html][GNU Emacs pretest 25.0.94 now available]] ([[https://www.reddit.com/r/emacs/comments/4ju5qq/gnu_emacs_pretest_25094_now_available/][Reddit]])
  - [[https://www.reddit.com/r/emacs/comments/4jkwj0/whats_the_20_of_emacsspacemacs_that_you_use_80_of/][What's the 20% of emacs/spacemacs that you use 80% of the time?]]
  - [[https://www.reddit.com/r/emacs/comments/4kflrk/evil_tabbar_rearranging_tabs/][Evil tabbar - rearranging tabs]] - eyebrowse
  - [[https://www.reddit.com/r/emacs/comments/4joygc/can_i_kill_idle_buffers/][Can I kill idle buffers?]] clean-buffer-list
  - [[https://www.reddit.com/r/emacs/comments/4js0tr/assimilate_emacs_packages_using_git_submodules/][Assimilate Emacs packages using Git submodules]]
  - [[https://www.youtube.com/watch?v=qon4mg9C0ZY][Living in Emacs (22:52, German)]]
- New packages:
  - http://melpa.org/#/annotate-depth: Annotate buffer if indentation depth is beyond threshold.
  - http://melpa.org/#/cursor-in-brackets: move cursor in brackets/quotes when right bracket/quote is inserted
  - http://melpa.org/#/datetime: Parsing, formatting and matching timestamps
  - http://melpa.org/#/datetime-format: Datetime functions
  - http://melpa.org/#/fastdef: Insert terminology from Google top search results
  - http://melpa.org/#/highlight-operators: a face for operators in programming modes
  - http://melpa.org/#/immortal-scratch: respawn the scratch buffer when it's killed
  - http://melpa.org/#/ivy-gitlab: Ivy interface to Gitlab
  - http://melpa.org/#/ivy-hydra: Additional key bindings for Ivy
  - http://melpa.org/#/judge-indent: judge indent and tab widths
  - http://melpa.org/#/llvm-mode: Major mode for the LLVM assembler language.
  - http://melpa.org/#/markdown-mac-link: Insert Markdown links to items selected in various Mac apps
  - http://melpa.org/#/modern-cpp-font-lock: Font-locking for "Modern C++"
  - http://melpa.org/#/org-eww: automatically use eww to preview current org-file when save
  - http://melpa.org/#/restclient-test: Run tests with restclient.el
  - http://melpa.org/#/timecop: Freeze Time for testing
  - https://elpa.gnu.org/packages/smart-yank.html: A different approach of yank pointer handling

Links from [[http://reddit.com/r/emacs/new][reddit.com/r/emacs]], [[http://reddit.com/r/orgmode][/r/orgmode]], [[https://hn.algolia.com/?query=emacs&sort=byDate&prefix&page=0&dateRange=all&type=story][Hacker News]], [[http://planet.emacsen.org][planet.emacsen.org]], [[https://www.youtube.com/results?search_query=emacs&search_sort=video_date_uploaded][Youtube]], the changes to the [[http://git.savannah.gnu.org/cgit/emacs.git/log/etc/NEWS][Emacs NEWS file]], and [[http://lists.gnu.org/archive/html/emacs-devel/2016-05][emacs-devel]].

[[http://sachachua.com/blog/category/emacs-news][Past Emacs News round-ups]]


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

* Re: 2016-05-23 Emacs News
  2016-05-23 16:44 2016-05-23 Emacs News Sacha Chua
@ 2016-06-10  0:04 ` Rolf Ade
  2016-06-10 10:30   ` Nicolas Richard
  0 siblings, 1 reply; 9+ messages in thread
From: Rolf Ade @ 2016-06-10  0:04 UTC (permalink / raw)
  To: emacs-tangents


Sacha Chua <sacha@sachachua.com> writes:
> 2016-05-23 Emacs News
>
> * Coding: 
>
>   * Literal values and destructive functions 

(That is:
http://mbork.pl/2016-05-23_Literal_values_and_destructive_functions)

Wait, what?

Sure, sort is documented as modifying the LIST in place. And the setq
makes `foo` global, so ... maybe no surprise, or so. But if I eval

(defun destructive-havoc ()
  "Example of destructive havoc."
  (let ((foo '(1 3 2)))
        (message "before sort, foo is: %s" foo)
        (sort foo #'<)
        (message "after sort, foo is: %s" foo)))

and M-: (destructive-havoc) two times, I still get

before sort, foo is: (1 3 2)
after sort, foo is: (1 2 3)
before sort, foo is: (1 2 3)
after sort, foo is: (1 2 3)

in *Messages*. Could someone please explain that to me?





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

* Re: 2016-05-23 Emacs News
  2016-06-10  0:04 ` Rolf Ade
@ 2016-06-10 10:30   ` Nicolas Richard
  2016-06-10 13:37     ` Rolf Ade
  0 siblings, 1 reply; 9+ messages in thread
From: Nicolas Richard @ 2016-06-10 10:30 UTC (permalink / raw)
  To: Rolf Ade; +Cc: emacs-tangents

Rolf Ade <rolf@pointsman.de> writes:
> (That is:
> http://mbork.pl/2016-05-23_Literal_values_and_destructive_functions)
>
> Wait, what?
>
> Sure, sort is documented as modifying the LIST in place. And the setq
> makes `foo` global, so ... maybe no surprise, or so. But if I eval
>
> (defun destructive-havoc ()
>   "Example of destructive havoc."
>   (let ((foo '(1 3 2)))
>         (message "before sort, foo is: %s" foo)
>         (sort foo #'<)
>         (message "after sort, foo is: %s" foo)))
>
> and M-: (destructive-havoc) two times, I still get
>
> before sort, foo is: (1 3 2)
> after sort, foo is: (1 2 3)
> before sort, foo is: (1 2 3)
> after sort, foo is: (1 2 3)
>
> in *Messages*. Could someone please explain that to me?

The article you're referring to explains just that. Is it somehow
unclear ? Quoting the article:

| What’s going on?
| 
| Well, the literal in the function definition was actually changed. (If
| you evaluate the defun form now, it will be redefined once again to
| the “correct” value.) If you don’t believe it, try this: M-:
| (symbol-function #'destructive-havoc), or even better, M-x
| pp-eval-expression RET (symbol-function #'destructive-havoc) RET and
| see for yourself.

Btw it's even more impressive (imho) if you start from '(3 2 1) :

(defun destructive-havoc ()
  "Example of destructive havoc."
  (let ((foo '(3 2 1)))
        (message "before sort, foo is: %s" foo)
        (sort foo #'<)
        (message "after sort, foo is: %s" foo)))

calling it twice gives :

before sort, foo is: (3 2 1)
after sort, foo is: (3)
before sort, foo is: (3)
after sort, foo is: (3)

-- 
Nicolas



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

* Re: 2016-05-23 Emacs News
  2016-06-10 10:30   ` Nicolas Richard
@ 2016-06-10 13:37     ` Rolf Ade
  2016-06-10 13:52       ` Marcin Borkowski
  2016-06-10 14:55       ` Nicolas Richard
  0 siblings, 2 replies; 9+ messages in thread
From: Rolf Ade @ 2016-06-10 13:37 UTC (permalink / raw)
  To: emacs-tangents


Nicolas Richard <youngfrog@members.fsf.org> writes:
> Rolf Ade <rolf@pointsman.de> writes:
>> (That is:
>> http://mbork.pl/2016-05-23_Literal_values_and_destructive_functions)
>> 
>> Wait, what?
>> [...]
>> in *Messages*. Could someone please explain that to me?
>
> The article you're referring to explains just that. Is it somehow
> unclear ? Quoting the article:
>
> | What’s going on?
> | 
> | Well, the literal in the function definition was actually changed. (If
> | you evaluate the defun form now, it will be redefined once again to
> | the “correct” value.) If you don’t believe it, try this: M-:
> | (symbol-function #'destructive-havoc), or even better, M-x
> | pp-eval-expression RET (symbol-function #'destructive-havoc) RET and
> | see for yourself.

Well ..., sorry, yes, that explanation isn't clear to me. While I'm
far away to claim I'm a versed emacs lisp programmer, I've written a few
screen full of emacs lisp code. Now this thing left me back with the
feeling, that I've missed to understand something at the core of the
language (with the additional unpleasant feeling, that my emacs lisp
programming is even more cargo cult coding, than I already suspected).

The "explanation", that the literal in the function definition was
changed by the (sort) call doesn't help me on track. While I'm fluent
with other programming languages, that are able to rewrite function
definitions during run-time I don't know a programming language that do
this as a 'side effect' of a function call (other than you craft one,
that deliberate does so).

Is what the article demonstrates something special to the 'build-in'
function sort or to emacs lisp? It would help me, if someone explains
what happen in this example in other words (not in implementation detail
but language concepts).




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

* Re: 2016-05-23 Emacs News
  2016-06-10 13:37     ` Rolf Ade
@ 2016-06-10 13:52       ` Marcin Borkowski
  2016-06-10 15:22         ` Rolf Ade
  2016-06-10 14:55       ` Nicolas Richard
  1 sibling, 1 reply; 9+ messages in thread
From: Marcin Borkowski @ 2016-06-10 13:52 UTC (permalink / raw)
  To: Rolf Ade; +Cc: emacs-tangents


On 2016-06-10, at 15:37, Rolf Ade <rolf@pointsman.de> wrote:

> Nicolas Richard <youngfrog@members.fsf.org> writes:
>> Rolf Ade <rolf@pointsman.de> writes:
>>> (That is:
>>> http://mbork.pl/2016-05-23_Literal_values_and_destructive_functions)
>>> 
>>> Wait, what?
>>> [...]
>>> in *Messages*. Could someone please explain that to me?
>>
>> The article you're referring to explains just that. Is it somehow
>> unclear ? Quoting the article:
>>
>> | What’s going on?
>> | 
>> | Well, the literal in the function definition was actually changed. (If
>> | you evaluate the defun form now, it will be redefined once again to
>> | the “correct” value.) If you don’t believe it, try this: M-:
>> | (symbol-function #'destructive-havoc), or even better, M-x
>> | pp-eval-expression RET (symbol-function #'destructive-havoc) RET and
>> | see for yourself.
>
> Well ..., sorry, yes, that explanation isn't clear to me. While I'm
> far away to claim I'm a versed emacs lisp programmer, I've written a few
> screen full of emacs lisp code. Now this thing left me back with the
> feeling, that I've missed to understand something at the core of the
> language (with the additional unpleasant feeling, that my emacs lisp
> programming is even more cargo cult coding, than I already suspected).
>
> The "explanation", that the literal in the function definition was
> changed by the (sort) call doesn't help me on track. While I'm fluent
> with other programming languages, that are able to rewrite function
> definitions during run-time I don't know a programming language that do
> this as a 'side effect' of a function call (other than you craft one,
> that deliberate does so).
>
> Is what the article demonstrates something special to the 'build-in'
> function sort or to emacs lisp? It would help me, if someone explains
> what happen in this example in other words (not in implementation detail
> but language concepts).

Hi,

original author here.  Sorry for being rather terse.  I've got only
a couple of minutes, but let me try.

It's not like `sort' changes the _function_.  But the function contains
a _literal structure_ (like "a constant"), and it is remembered as
a "pointer" (conceptually, not necessarily in C sense).  So when `sort'
changes the structure "pointed to" by its argument (and it gets the
"pointer" to the very same structure referred to by the function), it
looks like the function is changed.

Is that better?  (If yes, I'll amend the article.)

BTW, AFAIK, other Lisps have it similar with destructive functions.

Best,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



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

* Re: 2016-05-23 Emacs News
  2016-06-10 13:37     ` Rolf Ade
  2016-06-10 13:52       ` Marcin Borkowski
@ 2016-06-10 14:55       ` Nicolas Richard
  2016-06-10 16:01         ` Rolf Ade
  1 sibling, 1 reply; 9+ messages in thread
From: Nicolas Richard @ 2016-06-10 14:55 UTC (permalink / raw)
  To: Rolf Ade; +Cc: emacs-tangents

Rolf Ade <rolf@pointsman.de> writes:
> Is what the article demonstrates something special to the 'build-in'
> function sort or to emacs lisp? It would help me, if someone explains
> what happen in this example in other words (not in implementation detail
> but language concepts).


Note : meanwhile I saw Marcin posted a much shorter re-explanation... oh
well, I'll just post this anyway :)

I can't really do it in language-concepts because I don't know which
concepts you're familiar with, and more importantly because *I* am not
familiar enough with the concepts. I still hope it will be helpful :

It's related to two facts:
 (i)  sort changes the list inplace.
 (ii) the list is built at read-time instead of call-time, so that
 calling the same function multiple times re-uses the same list.

Now the steps that show the "problem". I'll try to explain very slowly.
I hope this is not too much details.

A) lisp code is actually a lisp list. In our example, the code that
   defines destructive-havoc is this :

   (defun destructive-havoc ()
     "Example of destructive havoc."
     (setq foo '(1 3 2))
     (message "before sort, foo is: %s" foo)
     (sort foo #'<)
     (message "after sort, foo is: %s" foo))
   
   That clearly looks like a list (first element would be the symbol
   `defun`, then the symbol `destructive`, then the empty list aka symbol
   `nil`, then a string, then four more lists). When you want to eval this
   code, emacs will first turn this list-looking-thing-in-your-buffer into
   an actual Lisp list. This is the reading step, aka read-time.
   
   Two more things to note in this step :
   - when emacs read '(1 3 2), it turned it into (quote (1 3 2)). This is
     what ' means. So this is in fact a list made of the symbol quote and
     the list (1 3 2). This list (1 3 2), I'll call it FooBar.
   - if you read the docstring of `quote`, it mentions something about «
     the value that was pre-constructed by the Lisp reader » and what it
     refers to, is exactly the FooBar list. But quote is not doing its
     job right now, so I'll come back to that later.


B) Since we asked, emacs will now proceed to evaluating this big list.
   This is what I called "call-time".
   How it does it is described in (info "(elisp) Intro Eval"), but
   basically it first looks at the first element of the list, and then
   decides what to do with the rest of the list. In this case the first
   element is `defun`, which is a symbol which denotes a macro, thus emacs
   will expand the macro and do its thing. At the end of this step,
   emacs now turned the symbol `destructive-havoc` into a function which
   holds the following list as its definition:
   (lambda nil "Example of destructive havoc." (setq foo (quote (1 3 2))) (message "before sort, foo is: %s" foo) (sort foo (function <)) (message "after sort, foo is: %s" foo))

   Here, note that a part of this list is in fact the bit that was created in step
   A, namely everything from (setq ... until the last paren. In
   particular, the (1 3 2) list in there is our FooBar.

C) next thing you'll be doing is evaluate (destructive-havoc). Again,
   emacs will read first (like step A) then evaluate (like step B) this
   code. This time, when evaluating, emacs sees destructive-havoc is symbol
   with a function definition, which means it'll evaluate the list
   contained in that function, i.e. the (lambda ...) form we have mentionned
   previously.

   Evaluating this lambda essentially means to evaluate all elements of the
   code inside, which is those :
     (setq foo (quote (1 3 2)))
     (message "before sort, foo is: %s" foo)
     (sort foo (function <))
     (message "after sort, foo is: %s" foo)

C1) The first thing is the setq, which gives `foo' the value obtained from
    evaluating (quote (1 3 2)). At this point, evaluating (quote (1 3 2))
    returns the value pre-constructed by the lisp reader in step A at the
    very beginning, which is FooBar.
C2) message constructs a string and shows it in the *Messages* buffer.
C3) sort sorts in-place, thus changing the data. IOW, FooBar was (1 3 2)
    but is now (1 2 3). It's the same list, but its content was changed.
C4) message constructs a string and shows it in the *Messages* buffer.

*at this point in time*, since the function definition contained FooBar
 and FooBar has had its content changed, the function inside
 destructive-havoc has somehow... changed too. It didn't change, really,
 but its content changed.

D) if you re-evaluate (destructive-havoc), the same steps happen again,
but since FooBar is now (1 2 3), what you see at step D2 is different.

Please note that despite the rather long post, I left out some details,
in particular (i) the difference between macro (or special form) and
function, (ii) the actual implementation of lists (as cons cells), (iii)
the byte-compilation and eager macro-expansion that might actually
happen when you evaluate things manually, even though you did not
request them.

HTH anyway.

-- 
Nicolas



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

* Re: 2016-05-23 Emacs News
  2016-06-10 13:52       ` Marcin Borkowski
@ 2016-06-10 15:22         ` Rolf Ade
  2016-06-10 16:45           ` John Mastro
  0 siblings, 1 reply; 9+ messages in thread
From: Rolf Ade @ 2016-06-10 15:22 UTC (permalink / raw)
  To: emacs-tangents; +Cc: Marcin Borkowski


Marcin Borkowski <mbork@mbork.pl> writes:
> On 2016-06-10, at 15:37, Rolf Ade <rolf@pointsman.de> wrote:
>> Nicolas Richard <youngfrog@members.fsf.org> writes:
>>> Rolf Ade <rolf@pointsman.de> writes:
>>>> (That is:
>>>> http://mbork.pl/2016-05-23_Literal_values_and_destructive_functions)
>>>> 
>>>> Wait, what?
>>>> [...]
>>>> in *Messages*. Could someone please explain that to me?
>>>
>>> The article you're referring to explains just that. Is it somehow
>>> unclear ? Quoting the article:
>>>
>>> | What’s going on?
>>> | 
>>> | Well, the literal in the function definition was actually changed. (If
>>> | you evaluate the defun form now, it will be redefined once again to
>>> | the “correct” value.) If you don’t believe it, try this: M-:
>>> | (symbol-function #'destructive-havoc), or even better, M-x
>>> | pp-eval-expression RET (symbol-function #'destructive-havoc) RET and
>>> | see for yourself.
>>
>> Well ..., sorry, yes, that explanation isn't clear to me. [...]
>
> It's not like `sort' changes the _function_.  But the function contains
> a _literal structure_ (like "a constant"), and it is remembered as
> a "pointer" (conceptually, not necessarily in C sense).  So when `sort'
> changes the structure "pointed to" by its argument (and it gets the
> "pointer" to the very same structure referred to by the function), it
> looks like the function is changed.
>
> Is that better?  (If yes, I'll amend the article.)

Hrrrhmm ... this discussion forces me, to paint myself as blockhead, but
no, it still feels I poke around in the dark with a long stick.

I could accept, that '(1 3 2) defines some global "constant", that gets
modified by the `sort' call.

But if I then look at:

(defun destructive-havoc1 ()
  "Example of destructive havoc."
  (setq foo '(1 3 2))
  (message "before sort, foo is: %s" foo)
  (sort foo #'<)
  (message "after sort, foo is: %s" foo))

(defun destructive-havoc2 ()
  "Example of destructive havoc."
  (setq foo '(1 3 2))
  (message "before sort, foo is: %s" foo)
  (sort foo #'<)
  (message "after sort, foo is: %s" foo))

Evalute both defuns. Then do M-: (destructive-havoc1), then M-:
(destructive-havoc2), then look at the *Messages* buffer. I see

before sort, foo is: (1 3 2)
after sort, foo is: (1 2 3)
before sort, foo is: (1 3 2)
after sort, foo is: (1 2 3)

So, ... '(1 3 2) defines some (defun local) "constant" ...?

I'm still afraid, I miss completely some basic concept or syntax
understanding.




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

* Re: 2016-05-23 Emacs News
  2016-06-10 14:55       ` Nicolas Richard
@ 2016-06-10 16:01         ` Rolf Ade
  0 siblings, 0 replies; 9+ messages in thread
From: Rolf Ade @ 2016-06-10 16:01 UTC (permalink / raw)
  To: emacs-tangents


Nicolas Richard <youngfrog@members.fsf.org> writes:
> Rolf Ade <rolf@pointsman.de> writes:
>> Is what the article demonstrates something special to the 'build-in'
>> function sort or to emacs lisp? It would help me, if someone explains
>> what happen in this example in other words (not in implementation detail
>> but language concepts).
>
> Note : meanwhile I saw Marcin posted a much shorter re-explanation... oh
> well, I'll just post this anyway :)
>
> [Step-by-step explanation]

Saw your post only after answering to Marcin. Thank you very much for
going into that lengths, I really appreciate.

Maybe some light is shining into my darkness. It boils down to the
difference between (quote (1 3 2)) and (list 1 3 2). `(elisp)Printed
Representation' has probably the crucical sentences:

  "In other languages, an expression is text; it has no other form.  In
Lisp, an expression is primarily a Lisp object and only secondarily the
text that is the object’s read syntax."

Still have to dig around more on this road; I would lie if I claim it's
all clear now ...




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

* Re: 2016-05-23 Emacs News
  2016-06-10 15:22         ` Rolf Ade
@ 2016-06-10 16:45           ` John Mastro
  0 siblings, 0 replies; 9+ messages in thread
From: John Mastro @ 2016-06-10 16:45 UTC (permalink / raw)
  To: emacs-tangents; +Cc: Rolf Ade, Marcin Borkowski

Rolf Ade <rolf@pointsman.de> wrote:
> So, ... '(1 3 2) defines some (defun local) "constant" ...?
>
> I'm still afraid, I miss completely some basic concept or syntax
> understanding.


That's right, though the fact that it's "defun local" is an
implementation detail. It could hypothetically be module/package local,
or global, etc. with a different implementation and compilation
strategy. (Also, I think "literal" is a better word for this than
"constant".)

The reason it's defun local in Emacs lisp is that each function object
(whether byte-compiled or not) contains the literals from that
function's definition.

It might (or might not) be more clear if you try this, which is
essentially the same as Marcin's recipe but we byte-compile the
function. You'll see that the list is stored in an vector of the
literals in the definition (in this case, the quoted list, symbols, and
strings). The reason I think this might help is that it makes it more
clear that the function itself is an object containing data.

(defun destructive-havoc ()
  (let ((foo '(1 3 2)))
    (message "before sort: %s" foo)
    (sort foo #'<)
    (message "after sort: %s" foo)))

(byte-compile 'destructive-havoc)
(pp-eval-expression '(symbol-function 'destructive-havoc))
(destructive-havoc)
(pp-eval-expression '(symbol-function 'destructive-havoc))

So, when you call `destructive-havoc', the call to `sort' is acting on
the list in that vector. That vector and its contents are part of the
function object for `destructive-havoc', so mutations to them are
permanent (relative to the function object itself).

Hope that helps,

        John



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

end of thread, other threads:[~2016-06-10 16:45 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-23 16:44 2016-05-23 Emacs News Sacha Chua
2016-06-10  0:04 ` Rolf Ade
2016-06-10 10:30   ` Nicolas Richard
2016-06-10 13:37     ` Rolf Ade
2016-06-10 13:52       ` Marcin Borkowski
2016-06-10 15:22         ` Rolf Ade
2016-06-10 16:45           ` John Mastro
2016-06-10 14:55       ` Nicolas Richard
2016-06-10 16:01         ` Rolf Ade

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