string::last

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

string::last

Post by Gildas Menier » 3 Mar 2009 22:13

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
Active Member
Posts: 39
Joined: 17 Oct 2006 5:49

Re: string::last

Post by CalmoSoft » 24 Jun 2018 8:30

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 ~)
There are two types of programmers :
the one who already uses Ring
or Visual Prolog and the others
who are going to use them some time.
(~ CalmoSoft ~)
calmosoft@gmail.com

User avatar
Thomas Linder Puls
VIP Member
Posts: 2333
Joined: 28 Feb 2000 0:01

Re: string::last

Post by Thomas Linder Puls » 25 Jun 2018 7:56

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
Active Member
Posts: 39
Joined: 17 Oct 2006 5:49

Re: string::last

Post by CalmoSoft » 25 Jun 2018 18:15

Hello Thomas,

Thanks for your explanations.

Greetings,
Gal Zsolt
(~ CalmoSoft ~)
There are two types of programmers :
the one who already uses Ring
or Visual Prolog and the others
who are going to use them some time.
(~ CalmoSoft ~)
calmosoft@gmail.com

Post Reply