Discussions related to Visual Prolog
VPExplorer
Active Member
Posts: 25
Joined: 6 Aug 2012 16:56

Example of a domains declaration of a string list

Unread post by VPExplorer »

Hi,

On the Lists and Recursion page Lists and Recursion, it uses an example

Code: Select all

domains     llist = l(list); i(integer); c(char); s(string).         % the functors are l, i, c, and s
that applies to the list

Code: Select all

[i(2), i(9), l([s("food"), s("goo")]), s("new")]
What if we have just a list of strings, [ "red", "blue", "green", "yellow" ]?

Is there a simple way to declare this? I tried

Code: Select all

domains         colors = list.

but that's obviously not the right syntax. Also

Code: Select all

domains         colors = s(list).

but that generate a build error, as well.

I just need an example of a domains declaration of a string list. I can read through more of the docs to understand the example afterwards, but just need something to test with.

In fact, just having an example will help clarify the misunderstanding.
Harrison Pratt
VIP Member
Posts: 432
Joined: 5 Nov 2000 0:01

Re: Example of a domains declaration of a string list

Unread post by Harrison Pratt »

Perhaps something like this:

Code: Select all

domains     colorListDOM = string_list.   constants     colorList : colorListDOM = ["red", "blue", "green"].
VPExplorer
Active Member
Posts: 25
Joined: 6 Aug 2012 16:56

Re: Example of a domains declaration of a string list

Unread post by VPExplorer »

string_list. Thanks, Harrison.

Turns out this usage was deprecated, but VP fixed it immediately to

Code: Select all

string*
Harrison Pratt wrote: 1 Feb 2022 20:50 Perhaps something like this:

Code: Select all

domains     colorListDOM = string_list.   constants     colorList : colorListDOM = ["red", "blue", "green"].
User avatar
Thomas Linder Puls
VIP Member
Posts: 1395
Joined: 28 Feb 2000 0:01

Re: Example of a domains declaration of a string list

Unread post by Thomas Linder Puls »

The example in the tutorial was wrong/buggy.

Now the list domain is declared like this:

Code: Select all

domains     list = elem*.     elem = l(list List); i(integer Integer); c(char Char); s(string String).
A list is a list of elem's. Where an elem is one of the four "things".

Actually we recommend that you don't define names for list domains, unless that name actually play a role. So given a domain like elem above we actually recommend that you don't define the list domain but write elem* instead.

Code: Select all

domains     elem = l(elem* List); i(integer Integer); c(char Char); s(string String).
Regards Thomas Linder Puls
PDC
VPExplorer
Active Member
Posts: 25
Joined: 6 Aug 2012 16:56

Re: Example of a domains declaration of a string list

Unread post by VPExplorer »

Ok, thanks Thomas. Got another question, related to the console. Will open another thread.
Post Reply