Monday, June 15, 2009

Shifting sequences

My other foray into trying to bring functional parity between positional parameters and sequence variables is "shift". I'd like a shift operator that operates on a sequence variable similar to how shift works on positional parameters. Something like perl's shift.


a=(foo bar spam)
shift a

now a is (bar spam)

Not sure if I should do this though. It is the equivilent of this not-too-ugly (but not too obvious either)

a=<[ $a[position() > 1] ]>


  1. I am about to implement this (still may) when I realized that the proposed syntax is ambiguous for positional parameters !
    shift 1

    does that shift the variable $1 or shift $* by 1 ?

    Only way to make sense of this is to not allow the syntax to shift positional parameters individually.

    That is you can do

    shift a
    ( shifts variable "a")

    shift 1
    ( shifts positional parameters $* by 1)

    or even
    shift a 2
    ( shifts variable a by 2 )

    but there is no syntax to shift $1 by 1 ...

    shift 1 1

    ? Uglier then sin ?

  2. Implemented in the next release (checked in now to svn)


Due to comment spam, moderation is turned on. I will approve all non-spam comments.