Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Numeric stability is probably not all that important when you're guessing.


devel / comp.lang.forth / Re: Modifying a string

SubjectAuthor
* Modifying a stringRobert L.
+- Re: Modifying a stringS Jack
`- Re: Modifying a stringHans Bezemer

1
Modifying a string

<t00p9d$1pk4$1@gioia.aioe.org>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=17018&group=comp.lang.forth#17018

 copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!bvgHpzLNDmR+c2aSW1J/UQ.user.46.165.242.75.POSTED!not-for-mail
From: No_spamm...@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.forth
Subject: Modifying a string
Date: Sat, 5 Mar 2022 22:47:11 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <t00p9d$1pk4$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="59012"; posting-host="bvgHpzLNDmR+c2aSW1J/UQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: XanaNews/1.18.1.6
X-Notice: Filtered by postfilter v. 0.9.2
 by: Robert L. - Sat, 5 Mar 2022 22:47 UTC

Find the integers in a string and multiply them by
a given number.

Gauche Scheme:

(define (mul-nums-in-string s n)
(regexp-replace-all #/\d+/ s
(lambda (m)
(number->string
(* n (string->number (rxmatch-substring m)))))))

(mul-nums-in-string
"37 apples, 6 oranges, and 982 pecans."
5)

"185 apples, 30 oranges, and 4910 pecans."

In Forth?

Re: Modifying a string

<cf3675fc-7b0c-4301-ba65-3534806ecbe0n@googlegroups.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=17022&group=comp.lang.forth#17022

 copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ac8:5b82:0:b0:2cf:232d:b1f8 with SMTP id a2-20020ac85b82000000b002cf232db1f8mr4652178qta.58.1646530609342;
Sat, 05 Mar 2022 17:36:49 -0800 (PST)
X-Received: by 2002:a05:622a:18b:b0:2de:8f67:b3e2 with SMTP id
s11-20020a05622a018b00b002de8f67b3e2mr4733009qtw.104.1646530609209; Sat, 05
Mar 2022 17:36:49 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sat, 5 Mar 2022 17:36:49 -0800 (PST)
In-Reply-To: <t00p9d$1pk4$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:3f7a:20d0:790e:70da:4541:696a;
posting-account=V5nGoQoAAAC_P2U0qnxm2kC0s1jNJXJa
NNTP-Posting-Host: 2600:1700:3f7a:20d0:790e:70da:4541:696a
References: <t00p9d$1pk4$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <cf3675fc-7b0c-4301-ba65-3534806ecbe0n@googlegroups.com>
Subject: Re: Modifying a string
From: sdwjac...@gmail.com (S Jack)
Injection-Date: Sun, 06 Mar 2022 01:36:49 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 40
 by: S Jack - Sun, 6 Mar 2022 01:36 UTC

On Saturday, March 5, 2022 at 4:47:14 PM UTC-6, Robert L. wrote:
> Find the integers in a string and multiply them by
> a given number.
>
> Gauche Scheme:
>
> (define (mul-nums-in-string s n)
> (regexp-replace-all #/\d+/ s
> (lambda (m)
> (number->string
> (* n (string->number (rxmatch-substring m)))))))
>
> (mul-nums-in-string
> "37 apples, 6 oranges, and 982 pecans."
> 5)
>
> "185 apples, 30 oranges, and 4910 pecans."
>
>
> In Forth?
:) frogd
ELF32X86_64 Frog Version 1.0d

"job" /go
5 { >r
begin
bl parse dup while ( have item )
OVER C@ ASC 0 ASC 9 1+ WITHIN IF
cr geval r * . bl parse 1- type
II 2DROP FI
repeat
rdrop
} run1 37 apples, 6 oranges, and 982 pecans.
185 apples
30 oranges
4910 pecans
ok
--
me

Re: Modifying a string

<8e6d5a71-a04d-4567-bb82-21d73bc00f5fn@googlegroups.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=17037&group=comp.lang.forth#17037

 copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a37:9746:0:b0:61f:ea7b:a488 with SMTP id z67-20020a379746000000b0061fea7ba488mr4517344qkd.618.1646581427648;
Sun, 06 Mar 2022 07:43:47 -0800 (PST)
X-Received: by 2002:ac8:7e90:0:b0:2de:2b69:aa3c with SMTP id
w16-20020ac87e90000000b002de2b69aa3cmr6411328qtj.279.1646581427486; Sun, 06
Mar 2022 07:43:47 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sun, 6 Mar 2022 07:43:47 -0800 (PST)
In-Reply-To: <t00p9d$1pk4$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=82.95.228.79; posting-account=Ebqe4AoAAABfjCRL4ZqOHWv4jv5ZU4Cs
NNTP-Posting-Host: 82.95.228.79
References: <t00p9d$1pk4$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8e6d5a71-a04d-4567-bb82-21d73bc00f5fn@googlegroups.com>
Subject: Re: Modifying a string
From: the.beez...@gmail.com (Hans Bezemer)
Injection-Date: Sun, 06 Mar 2022 15:43:47 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 21
 by: Hans Bezemer - Sun, 6 Mar 2022 15:43 UTC

On Saturday, March 5, 2022 at 11:47:14 PM UTC+1, Robert L. wrote:
> In Forth?
It's almost not worth an answer. And note: I don't depend on a massive REGEX engine here.
People who depend on those tools cannot be considered true programmers IMHO.

include lib/scanskip.4th

64 string result

: replay
result >r 0 dup r@ place
begin
bl split -trailing dup
while
2dup number error? if drop else nip nip 5 * <# #s #> then
r@ count if s" " r@ +place then drop r@ +place dup if chop then
repeat 2drop rdrop
;

s" 37 apples, 6 oranges, and 982 pecans." replay result count type cr

Hans Bezemer

1
server_pubkey.txt

rocksolid light 0.9.7
clearnet tor