Increment a numerical string: Difference between revisions

Content deleted Content added
Hakank (talk | contribs)
Line 2,473: Line 2,473:
<lang php>$s = "12345";
<lang php>$s = "12345";
$s++;</lang>
$s++;</lang>

=={{header|Picat}}==
parse_term/1 is the best to use if there can be no assumption of the type of the number (integer or float). For integers to_int/1 is better to use, and for floats to_float/1.
<lang Picat>go =>

% integer
Int = "123",
println(int=Int),
println(parse_term=Int.parse_term+1),
println(to_int=Int.to_int+1), % assumes integer
nl,

% float
Float = "122.5",
println(float=Float),
println(parse_term=Float.parse_term+1),
println(to_float=Float.to_float+1),
nl.
</lang>

Output:
<pre>int = 123
parse_term = 124
to_int = 124

float = 122.5
parse_term = 123.5
to_float = 123.5</pre>

parse term/3 can evaluate numeric expressions with the help of apply/1:
<lang Picat>go2 =>
T = "2**16+1",
println(t=T),
parse_term(T,Term, _Vars),
println(term=Term),
println(apply=Term.apply).
</lang>

Output:
<pre>t = 2**16+1
term = 2 ** 16 + 1
apply = 65537</pre>



=={{header|PicoLisp}}==
=={{header|PicoLisp}}==