Sunday, December 15, 2013

Re: retrieve variable name

On 15/12/13 15:47, Alexandre Hoïde wrote:
> Hello,
>
> <--
> let s:vara = 1
> let s:varb = 2
> let s:vars = [ s:vara, s:varb ]

At this point, the new value of s:vars is just [ 1, 2 ] — no record is
kept of where the values came from.

If you had, instead, done

let s:vars = [ 's:vara', 's:varb' ]

(with quotes), then, of course,

for mvar in s:vars
echo mvar ':' eval(mvar)
endfor

would (IIUC) have displayed (not sent to the printer)

s:vara : 1
s:varb : 2

i.e., from the name you can retrieve the value, but not vice-versa.

Of course, the s: namespace means that all those operations have to be
done in the same script. Not in a different script, and not in
command-line mode.

> for mvar in s:vars
> echo ?name_of_var?(mvar)
> endfor
> --> would print
> s:vara
> s:varb
> --
>
> Any suggestion for ?name_of_var?
>
> Thanks in advance for your help,
>


Best regards,
Tony.
--
What a COINCIDENCE! I'm an authorized "SNOOTS OF THE STARS" dealer!!

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment