Discussions related to Visual Prolog
Gildas Menier
Active Member
Posts: 25
Joined: 8 Jun 2004 23:01

string::last

Unread post by Gildas Menier »

Last (...) Returns the last Count characters of Source (according to help).

It seems that it rather returns the end of the string starting at the given position :

last("hello",1) returns "ello"

should return "o" ?

last("hello",string::length("hello")-1) ?

Regards

Gildas
User avatar
CalmoSoft
VIP Member
Posts: 73
Joined: 17 Oct 2006 5:49

Re: string::last

Unread post by CalmoSoft »

Hello Gildas,

In the VIP 8.02 HTML help file there is:

Code: Select all

string::last/2->   last : (     string Source,     charCount Position)     -> string Last.   Retired: use fromPosition/2 instead
The next code works properly:

Code: Select all

pos := string::fromPosition("hello",string::length("hello")-1)
Greetings,
Gal Zsolt
(~ CalmoSoft ~)
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Re: string::last

Unread post by Thomas Linder Puls »

We noticed this problem at some time, and decided that both behaviors made sense. The documentation explained one thing and the behavior was the other. So to avoid problems for people that used the predicate we decided that we could not change the behavior and instead the predicate is now deprecated, replaced by these predicates:

Code: Select all

predicates     rear : (string Source, charCount Count) -> string Last.     % @short Return the last #Count characters of #Source.     % @example     % % All the statements below succeed:     % "d" = rear("abcd",1)<br>     % "" = rear("abcd",0)<br>     % "A" = rear("A",5)<br>     % "dart test " = rear("Standart test ",10)<br>     % "" = rear("",0)     % @end   predicates     fromPosition : (string Source, charCount Position) -> string Last.     tryFromPosition : (string Source, charCount Position) -> string Last determ.     % @short Return the last part of #Source from #Position     % @example     % % All the statements below succeed:     % "" = fromPosition("", 0)<br>     % "abcd" = fromPosition("abcd", 0)<br>     % "bcd" = fromPosition("abcd", 1)<br>     % "" = fromPosition("abcd", 4)<br>     % % An example below raises exception: string_exception::outOfBoundaries     % Last = fromPosition("abcd", 5)     % @exception fromPosition/2-> raises string_exception::outOfBoundaries     % if #Source contain less than #Position characters.     % @end
rear corresponds to the documentation of the old predicate. fromPosition corresponds to the behavior of the old predicate. But that obviously only help people that uses the new version.
Regards Thomas Linder Puls
PDC
User avatar
CalmoSoft
VIP Member
Posts: 73
Joined: 17 Oct 2006 5:49

Re: string::last

Unread post by CalmoSoft »

Hello Thomas,

Thanks for your explanations.

Greetings,
Gal Zsolt
(~ CalmoSoft ~)
Post Reply