Determine if a string is numeric: Difference between revisions

m
Line 65:
 
=={{header|ALGOL 68}}==
{{trans|Ada}}
 
{{works with|ALGOL 68|Revision 1 - no extensions to language used}}
 
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny]}}
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of FORMATted transput}}
<lang algol68>PROC is numeric = (REF STRING string) BOOL: (
BOOL out := TRUE;
Line 74 ⟶ 80:
on logical file end(memory, call back false);
 
UNION (INT, REAL, COMPLEXCOMPL) numeric:=pi0.0;
# use a FORMAT pattern instead of a regular expression #
getf(memory, ($gl$, numeric));
Line 80 ⟶ 86:
);
 
test:(
PROC is numeric test = VOID: (
STRING
s1 := "152",
s2 := "-3.1415926",
s3 := "Foo123";
print((
print((s1, " results in ", is numeric(s1), new line));
print((s2 s1, " results in ", is numeric(s2s1), new line));,
print((s3 s2, " results in ", is numeric(s3s2), new line)),
print((s1 s3, " results in ", is numeric(s1s3), new line));
);
))
 
);
is numeric test</lang>
</lang>
Result is:
Output:
<lang algol68>152 results in T
<pre>
<lang algol68>152 results in T
-3.1415926 results in T
Foo123 results in F</lang>
</pre>
 
=={{header|APL}}==