[mercury-users] still the Tuple Construction

Goncalo Jorge Coelho e Silva l10454 at alunos.uevora.pt
Thu May 15 10:37:29 AEST 2003

Hi all,

 Following the past thread on constructing a
read-alike DCG PROLOG parser again... and
Ralph's prescious tip:

              % code_gen/3 would be better written as a function... 
        code_gen([], Heap, Heap). 

        code_gen([Instruction | Program], Heap0, Heap) :- 
                run_instr(Instruction, Heap0, Heap1), 
                code_gen(Program, Heap1, Heap). 

        run_instr(set_value(Address, Value), Heap0, Heap) :- 
                set_heap(Heap0, Address, Value, Heap). 

 and replying to Andrew's post on the issue:

> I would suggest you to forget the 'construct' predicates at all. In 
>general, you construct term just by typing them. Also, forget the 
>'construct_tuple' predicate and construct the tuples using the {,} 
>syntax. (See the section Syntax in the Language Reference). 

 I was unable to find such tuple construction
reference :(( 

 What I intended to do with 'construct' and 'construct_tuple'
was to built a predicate that given a string and a list
of arguments, would construct Ralph's tuples as in:

"set_value(Address, Value)" 

 on to Andrew's reply:

 I'm affraid I wasn't eplicit enough
to what I was looking for to do:

>Your example 
>should be: 
>main(IO0, IO) :- 
>  MyTerm = [i(29), s("string)], 
>  Univ = {1,2}, % personally, I'd call the variable Tuple, not Univ 
>  ... 

 About using the '{'and '}' for tuple

 Sorry, but I'm not sure what's does your 
>  Univ = {1,2}
line represents. A tuple (int,int) with int 1 and int 2?

 Also, I assume you forgot the '"' closing the
2nd argument string, and down on the other example
you gave, the enclosing ')' :
>  MyTerm = [i(29), s("string"], % list(myType) 

 on my example, when I used:
>> main(IO0,IO) :- 
>> %construct(myType,1,[29|"string"]) = MyTerm, 
>> %List = [1|2|[]], 
>> %construct_tuple(List) = Univ, 

I was trying to construct 2 diferent
tuples (or terms), one with 
>> %construct(myType,1,[29|"string"]) = MyTerm,

and the other one, using an already made list,
so as not to build it inside the predicate, with
>> %List = [1|2|[]],
>> %construct_tuple(List) = Univ,

moving on:

>The variable MyTerm will be of type list(myType). 

 That's not quite what I was looking for. I intended
to have a term that would look like something like 
     set_value(Address, Value)

  I only mentioned lists because the arguments to
the tuple to be constructed, had to be passsed as
a list when using 'construct_tuple' (if I recall right
:| ).

>Second, it is not permitted to mix together different types without
>'discriminating' them by distinct functors. In your case, the type
>declaration should be:
>:- type myType ---> i(int); s(string).

  So as a consequence, I'd like to know whether and how
do I have to declare the discriminating union and then
use it for tuple constructing for my examples above.

I'm a little tired by the current time so, I hope I have made my question
clear... :)

mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe

More information about the users mailing list