### Re: A function that expands value() and more

petelomax said...
euphoric said...
Senator said...

Just an observation. The function does not "Gets any numerical value at any position on a string", but rather gets or extracts the first numerical value found in the string and appends any subsequent numerical symbols to the initial numerical value.

```print(1, val("This string includes the numbers 42 18 36."))
-- outputs
-- 42 18 16
```

So, the function should output a sequence of found values. In the case above, it would return {42,18,36}.

You can do this in Phix:

```string s = "This string includes the numbers 42 18 36."
sequence res = scanf(" "&s,"%s %d%s")
pp(res,{pp_StrFmt,-2})
?vslice(res,2)
```

Output:

```{{" This string includes the numbers", 42, " 18 36."},
{" This string includes the numbers 42", 18, " 36."},
{" This string includes the numbers 42 18", 36, "."}}
{42,18,36}
```

Your code sure seems nice, euphoric. But you didn't use Euphoria, you used another language...
You literally "Phixed" it, right? :)
I wrote a script that gets the output mentioned by Senator.

```include get.e
include std/sequence.e
function val(object parm)
-- Gets any numerical value at any position on a string
sequence num_val = {}
sequence numbers = "0123456789"
if sequence(parm) then
for i = 1 to length(parm) do
if find(parm[i], numbers) then
num_val = append(num_val, {i, parm[i]})
end if
end for
sequence fnum_val = {}
fnum_val = flatten(num_val)
sequence values = {}
atom j = 3
while j <= length(fnum_val) do
atom dif = fnum_val[j] - fnum_val[j-2]
if dif != 1 then
values = append(values, fnum_val[j-1])
values = append(values, 44)
else
values = append(values, fnum_val[j-1])
end if
j = j + 2
end while
atom k = length(fnum_val)
values = append(values, fnum_val[k])
return values
else
return 0
end if
end function

puts(1, val("This string includes numbers 42 52 and 33."))
```

outputs 42,52,33

However, I doubt that has been evaluated to numerical... Has it? Can they be used as numerical values? I don't know, I've been testing Euphoria only for 10 days or so. Please, be patient with me and keep answering my (eventually dumb) questions. Okay? Thanks.