#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    172
    Rep Power
    11

    How to use shift in ML


    Hello !!!

    If I have an array and I want to shift the hole array to the right or left.

    a[1,2,3,4]
    shift right = a[4,1,2,3] shift left = a[2,3,4,1] any idea !!

    Thanks !!!
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Originally Posted by BaAa3
    Hello !!!

    If I have an array and I want to shift the hole array to the right or left.

    a[1,2,3,4]
    shift right = a[4,1,2,3] shift left = a[2,3,4,1] any idea !!

    Thanks !!!
    Hey Ba,

    I'm not all that fluent with ML anymore however, the following psuedo code should help.

    last : rest_without_last

    What you want to do cons's the last element into the rest of the elements, but not the last.

    Take care,

    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo