Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Work continues in this area. -- DEC's SPR-Answering-Automaton


devel / comp.lang.forth / Re: Grouping elements in a list

SubjectAuthor
* Grouping elements in a listRobert L.
`- Re: Grouping elements in a listS Jack

1
Grouping elements in a list

<t00pt4$14b$1@gioia.aioe.org>

  copy mid

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

  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: Grouping elements in a list
Date: Sat, 5 Mar 2022 22:57:42 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <t00pt4$14b$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="1163"; 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:57 UTC

Group adjacent equal items in a list.

Gauche Scheme and Racket:

;; for Racket only
(require srfi/1) ;; fold-right

(define (kons x accum)
(if (or (null? accum) (not (equal? x (caar accum))))
(cons (list x) accum)
(cons (cons x (car accum)) (cdr accum))))

(define (group lst)
(fold-right
kons
'()
lst))

(group '(foo bar bar j j j k baz baz))

===>
((foo) (bar bar) (j j j) (k) (baz baz))

In Forth?

Re: Grouping elements in a list

<627e78a1-e586-4790-b2d7-040a2ee6db41n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:6214:500f:b0:435:796b:7c62 with SMTP id jo15-20020a056214500f00b00435796b7c62mr1561538qvb.12.1646527986184;
Sat, 05 Mar 2022 16:53:06 -0800 (PST)
X-Received: by 2002:ac8:5f91:0:b0:2de:2c33:53a0 with SMTP id
j17-20020ac85f91000000b002de2c3353a0mr4561382qta.86.1646527986018; Sat, 05
Mar 2022 16:53:06 -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 16:53:05 -0800 (PST)
In-Reply-To: <t00pt4$14b$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: <t00pt4$14b$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <627e78a1-e586-4790-b2d7-040a2ee6db41n@googlegroups.com>
Subject: Re: Grouping elements in a list
From: sdwjac...@gmail.com (S Jack)
Injection-Date: Sun, 06 Mar 2022 00:53:06 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 51
 by: S Jack - Sun, 6 Mar 2022 00:53 UTC

On Saturday, March 5, 2022 at 4:57:45 PM UTC-6, Robert L. wrote:
> Group adjacent equal items in a list.
>
> Gauche Scheme and Racket:
>
> ;; for Racket only
> (require srfi/1) ;; fold-right
>
> (define (kons x accum)
> (if (or (null? accum) (not (equal? x (caar accum))))
> (cons (list x) accum)
> (cons (cons x (car accum)) (cdr accum))))
>
> (define (group lst)
> (fold-right
> kons
> '()
> lst))
>
>
> (group '(foo bar bar j j j k baz baz))
>
> ===>
> ((foo) (bar bar) (j j j) (k) (baz baz))
>
>
> In Forth?
:) frogd
ELF32X86_64 Frog Version 1.0d

"job" /go
{ 0 pad !
begin
bl parse dup while ( have item )
2dup pad gscmp if ( a new item )
pad @ if ." )" fi
cr ." ( "
fi
2dup pad gts
type space
repeat
." )"
} run1 foo bar bar j j j k baz baz
( foo )
( bar bar )
( j j j )
( k )
( baz baz ) ok
bye :)
--
me

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor