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
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.
@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 observe
1`.
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)
—