1
votes

I'm looking for a way of saving and after handling the arguments of a web form in SWI-Prolog when I submit the form and I call the same program to generate another form and so on. Always calling the same prolog program from one form to the next one.
The CGI SWI-Prolog library saves these arguments as a list of Name(Value) terms, i.e [Name(Value)].


if I pass the arguments like a hidden argument inside the form (TotalArguments is a list):

format('"<"input type="hidden" id="nameofform1" name="nameofform1" value="~w" />~n', TotalArguments),

I need to get rid of the id or name that concatenates on my resultant list on TotalArguments when I append it. Any idea of how to do this so that the final list looks like [nameofform1(value1), nameofform2(value2),...]?


I could also write this list of arguments and append it into a file, and consult it every time the program is called again, but this will load them always and I only need to load the arguments needed in the specific step and form handled at the moment. Because otherwise this file could contain undesirable info after some executions. Any thoughts on how to do it this way?
Any other suggestions for this kind of problem?


Edit with my solution using hidden form
I've solved it by creating:

  extract_value([],_).
  extract_value([A0|__ ], Valor) :-
     A0 =.. [_, Value],
     Valor is Value.

and then doing:

extract_value(Arguments, Value),

and submiting the hidden value of the form like:

format('<"input type="hidden" id="nameofform1" name="nameofform1" value="~w"/>~n', [Value]),

and appending it in the next form so that it looks how I wanted:

[nameofform2(value2),nameofform1(value1)]

1
As to your edit: It is better to use arg/3 in this case: arg(1, A0, Value), as there is no need to construct the full list. - mat

1 Answers

2
votes

It's a bit unclear to me what exactly you need here, but to remove the first element of a list that unifies with a given element (especially if you know for certain that the list contains such an element), use selectkchk/3. For example:

selectchk(id(_), List0, List1),
selectchk(name(_), List1, List)

in order to obtain List, which is List0 without the elements id(_) and name(_). Kind of implicit in your question, as I understand it, seems to be how to create a term like "form1(Value)" given the terms name(form1) and Value. You can do this for example with =../2. You can create a term T with functor N and arguments Args with

T =.. [N|Args]

It does not seem necessary to write anything to files here, I would simply pass the info through forms just as you outline.