# Convert atom to term give me another value the atom value is a variable

**URL:** <https://swi-prolog.discourse.group/t/convert-atom-to-term-give-me-another-value-the-atom-value-is-a-variable/2820>\
**Category:** Help!\
**Created:** [August 25, 2020, 8:31am UTC](https://swi-prolog.discourse.group/t/convert-atom-to-term-give-me-another-value-the-atom-value-is-a-variable/2820 "2020-08-25T08:31:02Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![kassepro](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@kassepro](https://swi-prolog.discourse.group/u/kassepro)\
**Post date:** [August 25, 2020, 8:31am UTC](https://swi-prolog.discourse.group/t/convert-atom-to-term-give-me-another-value-the-atom-value-is-a-variable/2820/1 "2020-08-25T08:31:02Z")

</div>

I’m using: SWI-Prolog version 8

I want the code to:

have a response look like this :

```prolog
T = Call

```

But what I’m getting is:

```prolog
_53794

```

My code looks like this:

```prolog
term_to_atom(T,'Call'),write(T).

```

---

<div class="post-metadata">

**Author:** ![Boris](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/boris/32/7486_2.png) [@Boris](https://swi-prolog.discourse.group/u/Boris)\
**Post date:** [August 25, 2020, 8:36am UTC](https://swi-prolog.discourse.group/t/convert-atom-to-term-give-me-another-value-the-atom-value-is-a-variable/2820/2 "2020-08-25T08:36:12Z")

</div>

~~Smells like a bug to me. Can reproduce. Should have probably thrown a `syntax_error`.~~

On the other hand, what kind of term is that? You can make something similar using:

```prolog
?- compound_name_arity(T, 'Call', 0).
T = 'Call'().

```

And even more importantly, what are you trying to achieve by turning an atom into a compound term?

---

<div class="post-metadata">

**Author:** ![kassepro](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@kassepro](https://swi-prolog.discourse.group/u/kassepro)\
**Post date:** [August 25, 2020, 8:44am UTC](https://swi-prolog.discourse.group/t/convert-atom-to-term-give-me-another-value-the-atom-value-is-a-variable/2820/3 "2020-08-25T08:44:52Z")

</div>

I would like to use Call as a variable using in another predicate and Call it comes from a user sending it to me. is it possible to use the atom ‘Call’ as a variable

---

<div class="post-metadata">

**Author:** ![Boris](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/boris/32/7486_2.png) [@Boris](https://swi-prolog.discourse.group/u/Boris)\
**Post date:** [August 25, 2020, 8:48am UTC](https://swi-prolog.discourse.group/t/convert-atom-to-term-give-me-another-value-the-atom-value-is-a-variable/2820/5 "2020-08-25T08:48:41Z")

</div>

So, what really happens here, the atom `'Call'` is taken as it comes; and in Prolog, atoms start with a small letter, and variables start with a capital letter; so, this is _correctly_ parsed as a variable name, and so, the term you get is indeed a free variable. What you are trying to achieve though I do not quite understand.

---

<div class="post-metadata">

**Author:** ![kassepro](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@kassepro](https://swi-prolog.discourse.group/u/kassepro)\
**Post date:** [August 25, 2020, 8:50am UTC](https://swi-prolog.discourse.group/t/convert-atom-to-term-give-me-another-value-the-atom-value-is-a-variable/2820/6 "2020-08-25T08:50:37Z")

</div>

we have a step i have a string in input like this “Call” i sould use it as a varaiable

---

<div class="post-metadata">

**Author:** ![Boris](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/boris/32/7486_2.png) [@Boris](https://swi-prolog.discourse.group/u/Boris)\
**Post date:** [August 25, 2020, 8:51am UTC](https://swi-prolog.discourse.group/t/convert-atom-to-term-give-me-another-value-the-atom-value-is-a-variable/2820/8 "2020-08-25T08:51:52Z")

</div>

> [@kassepro](#):
>
> we have a step i have a string in input like this “Call” i sould use it as a varaiable

This is exactly what you get though; you get a variable. Maybe if you show this code in some context it would become more clear what is happening.

---

<div class="post-metadata">

**Author:** ![kassepro](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@kassepro](https://swi-prolog.discourse.group/u/kassepro)\
**Post date:** [August 25, 2020, 8:53am UTC](https://swi-prolog.discourse.group/t/convert-atom-to-term-give-me-another-value-the-atom-value-is-a-variable/2820/9 "2020-08-25T08:53:01Z")

</div>

yes I agree but month I receive from a json object a string that looks like this “Call” and I have to use it as a variable in a predicate.

---

<div class="post-metadata">

**Author:** ![Boris](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/boris/32/7486_2.png) [@Boris](https://swi-prolog.discourse.group/u/Boris)\
**Post date:** [August 25, 2020, 8:54am UTC](https://swi-prolog.discourse.group/t/convert-atom-to-term-give-me-another-value-the-atom-value-is-a-variable/2820/10 "2020-08-25T08:54:51Z")

</div>

Show more code.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [August 25, 2020, 8:58am UTC](https://swi-prolog.discourse.group/t/convert-atom-to-term-give-me-another-value-the-atom-value-is-a-variable/2820/12 "2020-08-25T08:58:04Z")

</div>

Have a look at term\_string/3 or the older atom\_to\_term/3.

---

<div class="post-metadata">

**Author:** ![kassepro](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@kassepro](https://swi-prolog.discourse.group/u/kassepro)\
**Post date:** [August 25, 2020, 9:01am UTC](https://swi-prolog.discourse.group/t/convert-atom-to-term-give-me-another-value-the-atom-value-is-a-variable/2820/13 "2020-08-25T09:01:15Z")

</div>

```json
{
    "var": "Call"
}

```

```prolog
prove(Request) :-
   http_read_json(Request, DictIn,[json_object(term)]),
   format(user_output,"DictIn is: ~p~n",DictIn),
   P = [DictIn].json,
   Var =P.var 

```

Now I want use `Var` in this predicate or the content of `Var` is `"Call"` Prolog don’t accept it as variable I should do transformation `term_string(V,Var)` don’t work

usage of the variable Var in predicate for example deny a Call

deny(V) //must be iinterpreted by deny(Call)

---

<div class="post-metadata">

**Author:** ![kassepro](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@kassepro](https://swi-prolog.discourse.group/u/kassepro)\
**Post date:** [August 25, 2020, 9:11am UTC](https://swi-prolog.discourse.group/t/convert-atom-to-term-give-me-another-value-the-atom-value-is-a-variable/2820/15 "2020-08-25T09:11:11Z")

</div>

i wan’t to get value in quotation mark “Call” ex : Call

---

<div class="post-metadata">

**Author:** ![kassepro](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@kassepro](https://swi-prolog.discourse.group/u/kassepro)\
**Post date:** [August 25, 2020, 9:17am UTC](https://swi-prolog.discourse.group/t/convert-atom-to-term-give-me-another-value-the-atom-value-is-a-variable/2820/17 "2020-08-25T09:17:34Z")

</div>

i transform the “Call” to atom by atom\_string after would like to transform to term conversion of Capitalize don’t work

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [August 25, 2020, 9:40am UTC](https://swi-prolog.discourse.group/t/convert-atom-to-term-give-me-another-value-the-atom-value-is-a-variable/2820/18 "2020-08-25T09:40:33Z")

</div>

I don’t really get it. Prolog variables have no name. Only read/1 and sister predicates ensure that two variables with the same name become the same variable, i.e., reading a(X,X) becomes a term a/2 with two variables that share. Then there is, mostly for toplevel usage, the read\_term/3 variation (also term\_string/3) that accepts a variable\_names/1 option that gives you access to the name of the variable, so,

```
 ?- term_string(Term, "a(Call)", [variable_names(Names)]).
 Term = a(_48950),
 Names = ['Call'=_48950].

```

So, it does makes sense to have a query string and a variable for which you want to have the binding, as in (JSON) `{ var = "Call", query="deny(Call)" }` this could mean run deny/1 and reply with the variable binding of Call. You can achieve that using term\_string/3 on the query, solve the query and use the `var` name to look inside the variable\_names list for the value of this variable.

Hope this makes some sense …

---

<div class="post-metadata">

**Author:** ![kassepro](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@kassepro](https://swi-prolog.discourse.group/u/kassepro)\
**Post date:** [August 25, 2020, 10:22am UTC](https://swi-prolog.discourse.group/t/convert-atom-to-term-give-me-another-value-the-atom-value-is-a-variable/2820/21 "2020-08-25T10:22:35Z")

</div>

thank you that helps me but the number of variables is dymamic I could have more than two

---

<div class="post-metadata">

**Author:** ![kassepro](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@kassepro](https://swi-prolog.discourse.group/u/kassepro)\
**Post date:** [August 25, 2020, 1:46pm UTC](https://swi-prolog.discourse.group/t/convert-atom-to-term-give-me-another-value-the-atom-value-is-a-variable/2820/24 "2020-08-25T13:46:42Z")

</div>

term\_string/3  
works well
