Jump to content

Increment a numerical string: Difference between revisions

→‎{{header|Picat}}: Split into subsections. code tag for predicates, added {{out}}
(→‎{{header|Picat}}: Split into subsections. code tag for predicates, added {{out}})
Line 2,475:
 
=={{header|Picat}}==
===parse_term/1===
<code>parse_term/1</code> is the best to use if there can be no assumption of the type of the number (integer or float). For integers <code>to_int/1</code> is better to use, and for floats <code>to_float/1</code>.
<lang Picat>go =>
 
Line 2,493 ⟶ 2,494:
</lang>
 
{{out}}
Output:
<pre>int = 123
parse_term = 124
Line 2,502 ⟶ 2,503:
to_float = 123.5</pre>
 
===parse_term/3===
<code>parse term/3</code> can evaluate numeric expressions with the help of <code>apply/1</code>:
<lang Picat>go2 =>
T = "2**16+1",
Line 2,508 ⟶ 2,510:
parse_term(T,Term, _Vars),
println(term=Term),
println(apply=Term.apply).</lang>
</lang>
 
{{out}}
Output:
<pre>t = 2**16+1
term = 2 ** 16 + 1
apply = 65537</pre>
 
 
=={{header|PicoLisp}}==
495

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.