[vim/vim] printf("%p") is useless (#1466)

218 views
Skip to first unread message

Nikolai Aleksandrovich Pavlov

unread,
Feb 11, 2017, 12:29:32 PM2/11/17
to vim/vim, Subscribed

Currently printf("%p", expr) returns an address of the expr string which is utterly useless: even

let a = "str"
echo printf("%p", a)
echo printf("%p", a)

will yield different results because strings are copied. I would suggest using actual pointers instead: neovim/neovim#6065. Such behaviour (as one of the variants of id() function) is useful in serializers: e.g. if you want to serialize to YAML and use its anchor features properly you need to either save all containers and do O(N) iteration with is to determine duplicates or have id() function which returns unique identifier, printf("%p") is enough for this purpose.

Example:

let l = []
let ll = [l, l]

if serialized as

%YAML 1.2
---
- &l []
- *l

when deserializing will yield functionally the same ll.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub

Dominique Pellé

unread,
Feb 11, 2017, 12:52:38 PM2/11/17
to vim/vim, Subscribed

The %p format is not documented in Vim help and not meant to be used.
It is there because the same code is used internally in vim C code.
However, I just searched for %p and only found one use of it in os_amiga.c:431:

 423     /*
 424      * Make a unique name for the temp file (which we will not delete!).
 425      * Use a pointer on the stack (nobody else will be using it).
 426      * Under AmigaOS4, this assumption might change in the future, so
 427      * we use a pointer to the current task instead. This should be a
 428      * shared structure and thus globally unique.
 429      */
 430 #ifdef __amigaos4__
 431     sprintf((char *)buf1, "t:nc%p", FindTask(0));
 432 #else
 433     sprintf((char *)buf1, "t:nc%ld", (long)buf1);
 434 #endif

We could get rid of it, but who is going to fix and test the Amiga code? :-)

Besides %p, other formats like %ld, %lld, %h and perhaps others are also
useless in Vim script.

Nikolai Aleksandrovich Pavlov

unread,
Feb 11, 2017, 1:08:42 PM2/11/17
to vim/vim, Subscribed

@dpelle %ld, etc are not useless, they do what was requested with supplied numbers. Just VimL has only one integer type. You can e.g. use printf(&t_8f, 255, 0, 0) even though t_8f contains lu in place of u and this will work. Or printf('%hd, 65537)and observe1`.

h_east

unread,
Feb 11, 2017, 1:31:28 PM2/11/17
to vim_dev, v...@noreply.github.com, subsc...@noreply.github.com, reply+00b1d1989ec264917d44f29986eb1d83edc59b0...@reply.github.com, vim-dev...@256bit.org
Hi Nikolai,

Excuse, This has nothing to do with the subject, will not you stop using `VimL`?
GitHub ceased using VimL.
See the attached image.
--
Best regards,
Hirohito Higashi (a.k.a. h_east)

github_vim_script.png

vim-dev ML

unread,
Feb 11, 2017, 1:32:02 PM2/11/17
to vim/vim, vim-dev ML, Your activity

Nikolay Aleksandrovich Pavlov

unread,
Feb 11, 2017, 1:45:40 PM2/11/17
to vim_dev, vim/vim, Subscribed, reply+00b1d1989ec264917d44f29986eb1d83edc59b0...@reply.github.com, vim-dev ML
2017-02-11 21:31 GMT+03:00 h_east <h.eas...@gmail.com>:
> Hi Nikolai,
>
> Excuse, This has nothing to do with the subject, will not you stop using `VimL`?
> GitHub ceased using VimL.
> See the attached image.

I have no reasons to, and me starting to use this term has nothing to
do with GH: VimL is faster to type. And it is a recognized alias to
Vim script: e.g. see
https://en.wikipedia.org/wiki/Vim_(text_editor)#Vim_script.

> --
> Best regards,
> Hirohito Higashi (a.k.a. h_east)
>
> --
> --
> You received this message from the "vim_dev" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

vim-dev ML

unread,
Feb 11, 2017, 1:46:13 PM2/11/17
to vim/vim, vim-dev ML, Your activity

Tony Mechelynck

unread,
Feb 11, 2017, 7:37:32 PM2/11/17
to vim_dev, reply+00b1d1988b5f4a6fe01952502c16d3bca6482a2...@reply.github.com, vim/vim, vim-dev ML, Your activity
On Sat, Feb 11, 2017 at 7:31 PM, vim-dev ML <vim-dev...@256bit.org> wrote:
> Hi Nikolai,
>
> Excuse, This has nothing to do with the subject, will not you stop using
> `VimL`?
> GitHub ceased using VimL.
> See the attached image.
> --
> Best regards,
> Hirohito Higashi (a.k.a. h_east)

I couldn't care less what github does or doesn't use: they don't
dictate how I speak or what I understand. When someone speaks of VimL,
even though I don't personally use the term, I understand that what is
meant is what I call vimscript, or in a slightly higher language
register, "the Vim scripting language".

Best regards,
Tony.

vim-dev ML

unread,
Feb 11, 2017, 7:37:59 PM2/11/17
to vim/vim, vim-dev ML, Your activity

Bram Moolenaar

unread,
Feb 12, 2017, 10:54:54 AM2/12/17
to vim...@googlegroups.com, Tony Mechelynck, reply+00b1d1988b5f4a6fe01952502c16d3bca6482a2...@reply.github.com, vim/vim, vim-dev ML, Your activity
That is right. I don't know where "vimL" came from, it looks like
someone wanted to fit anything into four characters. It's not really a
language anyway. "Vim script" is the short form.

--
Looking at Perl through Lisp glasses, Perl looks atrocious.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

vim-dev ML

unread,
Feb 12, 2017, 10:55:23 AM2/12/17
to vim/vim, vim-dev ML, Your activity
Reply all
Reply to author
Forward
0 new messages