Re: patch: set() function

2006-10-25 Thread Bram Moolenaar

Hari Krishna Dara wrote:

> On Wed, 25 Oct 2006 at 9:16am, Nikolai Weibull wrote:
> 
> > On 10/25/06, Hari Krishna Dara <[EMAIL PROTECTED]> wrote:
> > >
> > > Here is a patch that adds set() function on the lines of existing get()
> > > for setting list elements by index or dict keys by name. The reason I
> > > wanted this is the lack of support to use :let for modifying the
> > > dictionary elements. E.g., the below will be an error:
> > >
> > > :let get_dict().key = 'val'
> > >
> > > The alternative is to use the new set() function as:
> > >
> > > :call set(get_dict(), 'key', 'val')
> >
> > Wouldn't it be better to allow the :let syntax you describe above?  It
> > shouldn't be impossible to parse that kind of expression.
> 
> - A set() function will be nice to have anyway (to balance out get())
> - Adding a function is much easier (at least for me as a newbie) and the
>   change is more isolated than changing the syntax of the :let command.
>   This also means better likely hood of getting incorporated sooner.
> - The last time the :let syntax was discussed, I don't think Bram agreed
>   to fix this issue, which indicates he is not in favor of that, and
>   so less likelyhood to get incorporated.
> 
> BTW, I noticed that I had the min args as 2 (copied from f_get) which is
> wrong, it should be 3. I can send another patch, again if Bram is OK
> with this change at all.

I would prefer the ":let" command to work.  It's not easy to implement
but would be good for consistency.

The main reason get() exists is to be able to handle non-existing keys
in a simple way.  That argument doesn't hold for set().

The dictionary was modelled after Python, and I don't think that Python
has set().

-- 
Corduroy pillows: They're making headlines!

 /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\download, build and distribute -- http://www.A-A-P.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///


Re: patch: set() function

2006-10-25 Thread G. Sumner Hayes
Hari Krishna Dara <[EMAIL PROTECTED]> wrote:
> Nikolai Weibull wrote:
> > Hari Krishna Dara <[EMAIL PROTECTED]> wrote:
> > >
> > > Here is a patch that adds set() function on the lines of existing get()
> > > for setting list elements by index or dict keys by name.
> [SNIP]
> >
> > Wouldn't it be better to allow the :let syntax you describe above?  It
> > shouldn't be impossible to parse that kind of expression.
>
> - A set() function will be nice to have anyway (to balance out get())

I worry about adding such a set() function with that name.  Vim's been adding 
things like dictionaries/lists with Python-like syntax, and it's entirely 
possible that it may want to add something like Python's set() datatype in the 
future.  Keeping the "set" name reserved in Vim seems wise to me.







Re: patch: set() function

2006-10-25 Thread Hari Krishna Dara

On Wed, 25 Oct 2006 at 9:16am, Nikolai Weibull wrote:

> On 10/25/06, Hari Krishna Dara <[EMAIL PROTECTED]> wrote:
> >
> > Here is a patch that adds set() function on the lines of existing get()
> > for setting list elements by index or dict keys by name. The reason I
> > wanted this is the lack of support to use :let for modifying the
> > dictionary elements. E.g., the below will be an error:
> >
> > :let get_dict().key = 'val'
> >
> > The alternative is to use the new set() function as:
> >
> > :call set(get_dict(), 'key', 'val')
>
> Wouldn't it be better to allow the :let syntax you describe above?  It
> shouldn't be impossible to parse that kind of expression.

- A set() function will be nice to have anyway (to balance out get())
- Adding a function is much easier (at least for me as a newbie) and the
  change is more isolated than changing the syntax of the :let command.
  This also means better likely hood of getting incorporated sooner.
- The last time the :let syntax was discussed, I don't think Bram agreed
  to fix this issue, which indicates he is not in favor of that, and
  so less likelyhood to get incorporated.

BTW, I noticed that I had the min args as 2 (copied from f_get) which is
wrong, it should be 3. I can send another patch, again if Bram is OK
with this change at all.

-- 
Thanks,
Hari

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


Re: patch: set() function

2006-10-25 Thread Nikolai Weibull

On 10/25/06, Hari Krishna Dara <[EMAIL PROTECTED]> wrote:


Here is a patch that adds set() function on the lines of existing get()
for setting list elements by index or dict keys by name. The reason I
wanted this is the lack of support to use :let for modifying the
dictionary elements. E.g., the below will be an error:

:let get_dict().key = 'val'

The alternative is to use the new set() function as:

:call set(get_dict(), 'key', 'val')


Wouldn't it be better to allow the :let syntax you describe above?  It
shouldn't be impossible to parse that kind of expression.

 nikolai


patch: set() function

2006-10-24 Thread Hari Krishna Dara

Here is a patch that adds set() function on the lines of existing get()
for setting list elements by index or dict keys by name. The reason I
wanted this is the lack of support to use :let for modifying the
dictionary elements. E.g., the below will be an error:

:let get_dict().key = 'val'

The alternative is to use the new set() function as:

:call set(get_dict(), 'key', 'val')

The function also returns the new value. Notice that the :let syntax
works to call functions on the dict, so the below is valid:

:let x = get_dict().getX()

Together, I think they will serve most or all of the use cases.

This is my first patch for Vim, and I haven't touched c/c++ code in
years, so I don't know if I screwed up on something.

I can write the documentation if Bram OK's the patch. I don't know if
there are any tests that need to be emended, and if so where they are.

-- 
Thanks,
Hari

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

set_patch.diff
Description: 919171944-set_patch.diff