Page 1 of 1

Example of a domains declaration of a string list

Posted: 1 Feb 2022 15:45
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.

Re: Example of a domains declaration of a string list

Posted: 1 Feb 2022 20:50
by Harrison Pratt
Perhaps something like this:

Code: Select all

domains     colorListDOM = string_list.   constants     colorList : colorListDOM = ["red", "blue", "green"].

Re: Example of a domains declaration of a string list

Posted: 2 Feb 2022 0:51
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"].

Re: Example of a domains declaration of a string list

Posted: 2 Feb 2022 9:40
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).

Re: Example of a domains declaration of a string list

Posted: 2 Feb 2022 10:05
by VPExplorer
Ok, thanks Thomas. Got another question, related to the console. Will open another thread.