Richard W.M. Jones
2016-Jul-08 08:10 UTC
Re: [Libguestfs] [PATCH v3 4/8] mllib: Add some imperative list manipulation functions.
On Thu, Jul 07, 2016 at 06:08:43PM +0100, Richard W.M. Jones wrote:> On Thu, Jul 07, 2016 at 07:00:46PM +0200, Pino Toscano wrote: > > On Thursday 07 July 2016 17:30:03 Richard W.M. Jones wrote: > > > This adds imperative list manipulation functions inspired by Perl. > > > The functions are passed list refs which get updated in place. > > > > > > This allows us to replace some awkward pure functional code like: > > > > > > let xs = ys in > > > let xs = if foo then xs @ zs else xs in > > > > > > with: > > > > > > let xs = ref ys in > > > if foo then append xs zs; > > > --- > > > > TBH I've always found the "shift" and "unshift" naming of Perl > > functions slightly awkward, but can live with them. (At least the > > new functions do the same as Perl ones.) > > I agree, but for consistency I thought it was better to keep those > names rather than trying to think up new ones which would be different > from everything else.Actually I forgot that C++ (STL vector, deque etc) have functions called push_front, pop_front, push_back, pop_back. Don't know if that would be better. Is it obvious what front and back mean? Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
Richard W.M. Jones
2016-Jul-08 08:40 UTC
Re: [Libguestfs] [PATCH v3 4/8] mllib: Add some imperative list manipulation functions.
On Fri, Jul 08, 2016 at 09:10:51AM +0100, Richard W.M. Jones wrote:> On Thu, Jul 07, 2016 at 06:08:43PM +0100, Richard W.M. Jones wrote: > > On Thu, Jul 07, 2016 at 07:00:46PM +0200, Pino Toscano wrote: > > > On Thursday 07 July 2016 17:30:03 Richard W.M. Jones wrote: > > > > This adds imperative list manipulation functions inspired by Perl. > > > > The functions are passed list refs which get updated in place. > > > > > > > > This allows us to replace some awkward pure functional code like: > > > > > > > > let xs = ys in > > > > let xs = if foo then xs @ zs else xs in > > > > > > > > with: > > > > > > > > let xs = ref ys in > > > > if foo then append xs zs; > > > > --- > > > > > > TBH I've always found the "shift" and "unshift" naming of Perl > > > functions slightly awkward, but can live with them. (At least the > > > new functions do the same as Perl ones.) > > > > I agree, but for consistency I thought it was better to keep those > > names rather than trying to think up new ones which would be different > > from everything else. > > Actually I forgot that C++ (STL vector, deque etc) have functions > called push_front, pop_front, push_back, pop_back. Don't know if that > would be better. Is it obvious what front and back mean?That would be the attached patch. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
Pino Toscano
2016-Jul-08 08:50 UTC
Re: [Libguestfs] [PATCH v3 4/8] mllib: Add some imperative list manipulation functions.
On Friday 08 July 2016 09:40:12 Richard W.M. Jones wrote:> On Fri, Jul 08, 2016 at 09:10:51AM +0100, Richard W.M. Jones wrote: > > On Thu, Jul 07, 2016 at 06:08:43PM +0100, Richard W.M. Jones wrote: > > > On Thu, Jul 07, 2016 at 07:00:46PM +0200, Pino Toscano wrote: > > > > On Thursday 07 July 2016 17:30:03 Richard W.M. Jones wrote: > > > > > This adds imperative list manipulation functions inspired by Perl. > > > > > The functions are passed list refs which get updated in place. > > > > > > > > > > This allows us to replace some awkward pure functional code like: > > > > > > > > > > let xs = ys in > > > > > let xs = if foo then xs @ zs else xs in > > > > > > > > > > with: > > > > > > > > > > let xs = ref ys in > > > > > if foo then append xs zs; > > > > > --- > > > > > > > > TBH I've always found the "shift" and "unshift" naming of Perl > > > > functions slightly awkward, but can live with them. (At least the > > > > new functions do the same as Perl ones.) > > > > > > I agree, but for consistency I thought it was better to keep those > > > names rather than trying to think up new ones which would be different > > > from everything else. > > > > Actually I forgot that C++ (STL vector, deque etc) have functions > > called push_front, pop_front, push_back, pop_back. Don't know if that > > would be better. Is it obvious what front and back mean?IMHO yes, more than "unshift" (unshift from what, for example?).> That would be the attached patch.LGTM -- note also the current solution is fine for me, as long as we are using a naming already in the wild and not anything homebrew. Thanks, -- Pino Toscano
Maybe Matching Threads
- Re: [PATCH v3 4/8] mllib: Add some imperative list manipulation functions.
- Re: [PATCH v3 4/8] mllib: Add some imperative list manipulation functions.
- [PATCH v3 4/8] mllib: Add some imperative list manipulation functions.
- Re: [PATCH v3 4/8] mllib: Add some imperative list manipulation functions.
- [PATCH v6 04/41] mllib: Split ‘Common_utils’ into ‘Std_utils’ + ‘Common_utils’.