Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

MSDOS is not dead, it just smells that way. -- Henry Spencer


devel / comp.lang.lisp / .Re: About Clisp

SubjectAuthor
* .Re: About ClispRobert L.
+- Re: .Re: About ClispRobert L.
`- Re: .Re: About ClispRobert L.

1
.Re: About Clisp

<sul72u$1kb3$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!500jh8wBfTLqW2S8jheT9g.user.46.165.242.75.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.lisp
Subject: .Re: About Clisp
Date: Thu, 17 Feb 2022 10:12:48 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <sul72u$1kb3$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="53603"; posting-host="500jh8wBfTLqW2S8jheT9g.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. - Thu, 17 Feb 2022 10:12 UTC

John Thingstad wrote:

> > CL-USER> (pack '(a a a a b c c a a d e e e e))
> > (NIL (A A A A) (B) (C C) (A A) (D) (E E E E))
> >
> > and cons of the list seemed to have unnecessary NIL.
> >
> > I'm not sure if it is a bug on clisp.
> > Please give me some advice.
> >
> > Sorry about my strange English. (I'm not a native speaker)
>
> I have a devil of a time understanding your code.
> After translating it I came up with:
>
> (defun pack (list)
> (labels ((build (source sub-list result)
> (let ((current (first source))
> (previous (first sub-list)))
> (cond ((null source)
> (nreverse (cons sub-list result)))
> ((eql current previous)
> (build (rest source) (cons current sub-list) result))
> (t
> (build (rest source) (cons current nil)
> (if (consp sub-list) (cons sub-list result)
> result))))))) ; this is different
> (build list nil nil)))
>
> The problem came from cons'ing ls1 to ls2 the first time the function is
> called when ls1 is nil.
> The code here corrects the problem.
> This way of solving the problem using tail recursion and accumulators is
> very Scheem'ish.
> Here is a more Lisp'ish solution.
>
> (defun pack (list)
> (let (result-list sub-list)
> (do ((current list (rest current))
> (previous nil current))
> ((null current)
> (push sub-list result-list)
> (nreverse result-list))
> (when (and (not (eql (first current) (first previous))) (consp
> sub-list))
> (push sub-list result-list)
> (setf sub-list nil))
> (push (first current) sub-list))))

Gauche Scheme:

(define (place x a b)
(let ((ok (or (null? a) (equal? x (car a)))))
(list (cons x (if ok a '()))
(if ok b (cons a b)))))

(define (clump the-list)
(apply cons
(fold-right
(cut apply place <> <>)
'(() ())
the-list)))

(clump '(a a a a b c c a a d e e e e))
===>
((a a a a) (b) (c c) (a a) (d) (e e e e))

Re: .Re: About Clisp

<sult4a$1dsj$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!/puDKAuHd5eXLgZjI8FkMg.user.46.165.242.75.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.lisp
Subject: Re: .Re: About Clisp
Date: Thu, 17 Feb 2022 16:29:00 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <sult4a$1dsj$1@gioia.aioe.org>
References: <sul72u$1kb3$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="46995"; posting-host="/puDKAuHd5eXLgZjI8FkMg.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. - Thu, 17 Feb 2022 16:29 UTC

On 2/17/2022, Robert L. wrote:

> John Thingstad wrote:
>
> > > CL-USER> (pack '(a a a a b c c a a d e e e e))
> > > (NIL (A A A A) (B) (C C) (A A) (D) (E E E E))
> > >
> > > and cons of the list seemed to have unnecessary NIL.
> > >
> > > I'm not sure if it is a bug on clisp.
> > > Please give me some advice.
> > >
> > > Sorry about my strange English. (I'm not a native speaker)
> >
> > I have a devil of a time understanding your code.
> > After translating it I came up with:
> >
> > (defun pack (list)
> > (labels ((build (source sub-list result)
> > (let ((current (first source))
> > (previous (first sub-list)))
> > (cond ((null source)
> > (nreverse (cons sub-list result)))
> > ((eql current previous)
> > (build (rest source) (cons current sub-list) result))
> > (t
> > (build (rest source) (cons current nil)
> > (if (consp sub-list) (cons sub-list result)
> > result))))))) ; this is different
> > (build list nil nil)))
> >
> > The problem came from cons'ing ls1 to ls2 the first time the function is
> > called when ls1 is nil.
> > The code here corrects the problem.
> > This way of solving the problem using tail recursion and accumulators is
> > very Scheem'ish.
> > Here is a more Lisp'ish solution.
> >
> > (defun pack (list)
> > (let (result-list sub-list)
> > (do ((current list (rest current))
> > (previous nil current))
> > ((null current)
> > (push sub-list result-list)
> > (nreverse result-list))
> > (when (and (not (eql (first current) (first previous))) (consp
> > sub-list))
> > (push sub-list result-list)
> > (setf sub-list nil))
> > (push (first current) sub-list))))
>
> Gauche Scheme:
>
> (define (place x a b)
> (let ((ok (or (null? a) (equal? x (car a)))))
> (list (cons x (if ok a '()))
> (if ok b (cons a b)))))
>
> (define (clump the-list)
> (apply cons
> (fold-right
> (cut apply place <> <>)
> '(() ())
> the-list)))
>
> (clump '(a a a a b c c a a d e e e e))
> ===>
> ((a a a a) (b) (c c) (a a) (d) (e e e e))

Shorter:

(use srfi-1) ;; car+cdr

(define (place x acc)
(let-values (((a b) (car+cdr acc)))
(if (or (null? a) (equal? x (car a)))
(cons (cons x a) b)
(cons* (list x) a b))))

(define (clump the-list)
(fold-right
place
'(())
the-list))

Re: .Re: About Clisp

<sumsah$1d8v$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!HdRI8HG02/q79WbJOQUZww.user.46.165.242.75.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.lisp
Subject: Re: .Re: About Clisp
Date: Fri, 18 Feb 2022 01:21:23 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <sumsah$1d8v$1@gioia.aioe.org>
References: <sul72u$1kb3$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="46367"; posting-host="HdRI8HG02/q79WbJOQUZww.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. - Fri, 18 Feb 2022 01:21 UTC

On 2/17/2022, Robert L. wrote:

> John Thingstad wrote:
>
> > > CL-USER> (pack '(a a a a b c c a a d e e e e))
> > > (NIL (A A A A) (B) (C C) (A A) (D) (E E E E))
> > >
> > > and cons of the list seemed to have unnecessary NIL.
> > >
> > > I'm not sure if it is a bug on clisp.
> > > Please give me some advice.
> > >
> > > Sorry about my strange English. (I'm not a native speaker)
> >
> > I have a devil of a time understanding your code.
> > After translating it I came up with:
> >
> > (defun pack (list)
> > (labels ((build (source sub-list result)
> > (let ((current (first source))
> > (previous (first sub-list)))
> > (cond ((null source)
> > (nreverse (cons sub-list result)))
> > ((eql current previous)
> > (build (rest source) (cons current sub-list) result))
> > (t
> > (build (rest source) (cons current nil)
> > (if (consp sub-list) (cons sub-list result)
> > result))))))) ; this is different
> > (build list nil nil)))
> >
> > The problem came from cons'ing ls1 to ls2 the first time the function is
> > called when ls1 is nil.
> > The code here corrects the problem.
> > This way of solving the problem using tail recursion and accumulators is
> > very Scheem'ish.
> > Here is a more Lisp'ish solution.
> >
> > (defun pack (list)
> > (let (result-list sub-list)
> > (do ((current list (rest current))
> > (previous nil current))
> > ((null current)
> > (push sub-list result-list)
> > (nreverse result-list))
> > (when (and (not (eql (first current) (first previous))) (consp
> > sub-list))
> > (push sub-list result-list)
> > (setf sub-list nil))
> > (push (first current) sub-list))))
>
> Gauche Scheme:
>
> (define (place x a b)
> (let ((ok (or (null? a) (equal? x (car a)))))
> (list (cons x (if ok a '()))
> (if ok b (cons a b)))))
>
> (define (clump the-list)
> (apply cons
> (fold-right
> (cut apply place <> <>)
> '(() ())
> the-list)))
>
> (clump '(a a a a b c c a a d e e e e))
> ===>
> ((a a a a) (b) (c c) (a a) (d) (e e e e))

(use srfi-1) ;; car+cdr for Gauche Scheme
or
(require srfi/1) ;; car+cdr for Racket

(define (clump them r)
(if (null? them)
r
(let ((x (car them)))
(let-values
(((a b)
(if (and (pair? r) (equal? x (caar r)))
(car+cdr r)
(values '() r))))
(clump (cdr them) (cons (cons x a) b))))))

(clump '(a a b c c) '())
===>
((c c) (b) (a a))


devel / comp.lang.lisp / .Re: About Clisp

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor