Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"Our vision is to speed up time, eventually eliminating it." -- Alex Schure


devel / comp.lang.lisp / Re: .Re: Confused about Scheme...???

SubjectAuthor
* .Re: Confused about Scheme...???Robert L.
`- Re: .Re: Confused about Scheme...???Robert L.

1
.Re: Confused about Scheme...???

<t1pfoc$8g5$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17004&group=comp.lang.lisp#17004

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!+Jn9Lcdk4P01xEyP4J6GcA.user.46.165.242.75.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.lisp
Subject: .Re: Confused about Scheme...???
Date: Sun, 27 Mar 2022 10:54:07 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <t1pfoc$8g5$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="8709"; posting-host="+Jn9Lcdk4P01xEyP4J6GcA.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. - Sun, 27 Mar 2022 10:54 UTC

> In short, 'reduce-list', is take a list of variable length, 'b',
> below and reduce it if the (caar ls) and (caadr ls) are equal...this
> is the first atom within the pair of consecutive sublists and if this
> is true contruct a list, (list (caar ls) (+ (cadar ls) (cadadr ls)))
> , and add second atom of the consective pairs. For example,
> (reduce-list b) ==> ((4 3) (3 7) (2 1) (1 2) (0 1)). I can get it to
> work for the first two terms without using recursion, produces (4 3),
> but when I implement recursion it barfs. Could some one tell me what
> I'm doing wrong because I know that I'm trying to do to much at once?
>
>
> -Conrad
>
>
> (define (reduce-list ls)
> (cond ((null? ls) ls)
> (else
> (cond ((null? (cadr ls)) ls)
> (else
> (cond ((eq? (caar ls) (caadr ls))
> (list (caar ls) (+ (cadar ls) (cadadr ls)))
> (reduce-list (cdr ls)))
> (else (list (car ls) (reduce-list (cdr ls)))))))))))
>
>
> (define b '((4 1) (4 2) (3 3) (3 4) (2 1) (1 2) (0 1)))
>
> (reduce-list b)

Gauche Scheme or Racket:

(use srfi-1) ;; span for Gauche
or
(require srfi/1) ;; span for Racket
(require srfi/8) ;; receive for Racket

(define b '((4 1) (4 2) (4 80) (3 3) (3 4) (2 1) (1 2) (0 1)))

(define (reduce-list xs)
(if (null? xs)
'()
(let ((k (caar xs)))
(receive (these those)
(span (lambda (ys) (equal? (car ys) k)) xs)
(cons (list k (apply + (map cadr these)))
(reduce-list those))))))

(reduce-list b)
===>
((4 83) (3 7) (2 1) (1 2) (0 1))

Re: .Re: Confused about Scheme...???

<t1qe96$1mah$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17005&group=comp.lang.lisp#17005

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!6pSIWr/38Wh2NyVfcM+k7A.user.46.165.242.75.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.lisp
Subject: Re: .Re: Confused about Scheme...???
Date: Sun, 27 Mar 2022 19:35:03 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <t1qe96$1mah$1@gioia.aioe.org>
References: <t1pfoc$8g5$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="55633"; posting-host="6pSIWr/38Wh2NyVfcM+k7A.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. - Sun, 27 Mar 2022 19:35 UTC

On 3/27/2022, Robert L. wrote:

> (define b '((4 1) (4 2) (4 80) (3 3) (3 4) (2 1) (1 2) (0 1)))
>
> (define (reduce-list xs)
> (if (null? xs)
> '()
> (let ((k (caar xs)))
> (receive (these those)
> (span (lambda (ys) (equal? (car ys) k)) xs)
> (cons (list k (apply + (map cadr these)))
> (reduce-list those))))))
>
> (reduce-list b)
> ===>
> ((4 83) (3 7) (2 1) (1 2) (0 1))

Using pattern-matching.

Gauche Scheme:

(use util.match)

(define (kons xs accum)
(match `(,xs ,accum)
[((a b) ((c d) z ...)) (=> no)
(if (equal? a c)
(cons (list a (+ b d)) z)
(no))]
[(y z) (cons y z)]))

(define (reduce-list xs) (fold-right kons '() xs))

(define b '((4 1) (4 2) (4 80) (3 3) (3 4) (2 1) (1 2) (0 1)))

(reduce-list b)

===>
((4 83) (3 7) (2 1) (1 2) (0 1))

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor