> > class Blahh
> > toX: TYPE_A
> > toY: TYPE_B
> > fn SetXandY(toX, toY)
> > enfunc
> > endclass
> 
> So... like you said, that was confusing.
> 
> But, I just realised that prefixing member variables with "this" everywhere 
> consistently could perhaps allow us to do something in between, along these 
> lines?
> 
> class Blahh
> this.toX: TYPE_A
> this.toY: TYPE_B
> fn SetXandY(this.toX, this.toY, Z : TYPE_C)
>    blahh blah..
> enfunc
> endclass
> 
> 
> Could we make this signature pattern auto assign this.toX and this.toY, for 
> any function?   I'm just exploring other possibilities inspired by the idea 
> you presented with respect to the new() constructor.

I do not see much use for it.  Without supporting using "this.member" as
an argument name the code for the assignment would need to be given
explicitly, which isn't that bad.

> > Simplifying the new() method ~
> > 
> > Many constructors take values for the object members.  Thus you very 
> often see
> > this pattern: >
> > 
> >            this.lnum: number
> >            this.col: number
> > 
> >            def new(lnum: number, col: number)
> >               this.lnum = lnum
> >               this.col = col
> >            enddef
> > 
> > Not only is this text you need to write, it also has the type of each 
> member
> > twice.  Since this is so common a shorter way to write new() is provided: 
> >
> > 
> >            def new(this.lnum, this.col)
> >            enddef
> > 
> > The semantics are easy to understand: Providing the object member name,
> > including "this.", as the argument to new() means the value provided in 
> the
> > new() call is assigned to that object member.  This mechanism is coming 
> from
> > the Dart language.
> 
> Why limit this idea to only the new constructor?

The difference between a regular method and a constructor is that for a
constructor it is very common to assign the argument to an object
member.

The idea comes from Dart, and I don't think Dart supports this for
anything but constructors.


-- 
Q: Is selling software the same as selling hardware?
A: No, good hardware is sold new, good software has already been used by many.

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20221219165003.C5BA41C09DC%40moolenaar.net.

Raspunde prin e-mail lui