Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: negative skip + variable
Pages: [1] Print
Author Topic: negative skip + variable  (Read 395 times)
pepiporn
Newbie
*
Offline Offline

Posts: 8


View Profile
negative skip + variable
« on: April 03, 2005, 10:49:30 AM »

Code:
>> a
== ["hugo" "biene" "foo" "bar" "red red wine" "reggae music"]
>> x
== 2
>> skip a x
== ["foo" "bar" "red red wine" "reggae music"]
>> skip tail a -x
** Script Error: -x has no value
** Near: skip tail a -x
>> skip tail a -2
== ["red red wine" "reggae music"]

hope you get what i want. skip from the end of a series with a variable length ( to get last 2, or last 5 or last 10, or ... )

... at this occasion: how can i get the last 3 without the very last item? ( would be for that example: [ "foo" "bar" "red red wine" ] )
 
Logged
Gabriele
Full Member
***
Offline Offline

Posts: 182


View Profile WWW
negative skip + variable
« Reply #1 on: April 04, 2005, 08:37:42 AM »

You just need a space between "-" and "x". (Without, "-x" is a single word.)

Code:
>> skip tail a (- x)
== ["red red wine" "reggae music"]
>> skip tail a negate x
== ["red red wine" "reggae music"]
>> skip tail a x * -1
== ["red red wine" "reggae music"]

Also, for those used to BASIC (this is something that gets asked very often):

Code:
>> left: func [series number] [copy/part series number]
>> right: func [series number] [copy skip tail series negate number]
>> mid: func [series start number] [copy/part at series start number]
>> left a 3
== ["hugo" "biene" "foo"]
>> right a 3
== ["bar" "red red wine" "reggae music"]
>> mid a 3 3
== ["foo" "bar" "red red wine"]
>> mid tail a -4 3
== ["foo" "bar" "red red wine"]
Logged
Pages: [1] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: negative skip + variable
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 20, 2008, 09:26:10 PM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2287 Posts in 593 Topics by 3725 Members
Latest Member: Heigueundulge

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc