1

If I have a massive argument list like:

program :-
    function(bxcjhbxhcbdbhbxzhbfhxhfbghfghjdfhgxfh),
    another_function(bxcjhbxhcbdbhbxzhbfhxhfbghfghjdfhgxfh).

can i do something like:

program :-
    var = bxcjhbxhcbdbhbxzhbfhxhfbghfghjdfhgxfh
    function(var),
    another_function(var).

?

1 Answer 1

3

Yes, you could do that in Prolog.

But you need to

  • add a , at the end of the var = .... line).
  • use Capital First Letters for variable names.

This works:

function([1, 2]).
another_function([1, 2]).

program :-
    Var = bxcjhbxhcbdbhbxzhbfhxhfbghfghjdfhgxfh,
    function(Var),
    another_function(Var).
Sign up to request clarification or add additional context in comments.

5 Comments

its the exact syntax i used in my question??
Yes, but you need to add a , at the end of the var = ... line.
a typo: Bxcjhbxhcbdbhbxzhbfhxhfbghfghjdfhgxfh is a singleton variable now
@peroni_santo no, it is very important that Var starts with a capital (upper case) letter as any logical variable must. Var = data is not a declaration, it is a unification of logical variable named Var, and data. The comma , after it signifies an AND; you could also have ; there, which stands for OR. Logvars exist in their own right, and can be uninstantiated as well as instantiated. Just by writing X=1 we create a logvar X and unify it with ("instantiate it as") 1. We could write X=Y which would create two uninstantiated logvars X and Y.
Is the use of [1,2] in the initial definitions of function and another_function significant or necessary? To me it looks like the functions are defined for lists, then you pass them the Var which is unified to the long, tedious-to-type atom.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.