Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

But you'll notice Perl has a goto. -- Larry Wall in <199710211624.JAA17833@wall.org>


devel / comp.lang.lisp / .Re: newbie exploring better ways

SubjectAuthor
o .Re: newbie exploring better waysRobert L.

1
.Re: newbie exploring better ways

<suh0pk$c9a$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!wwAjkVBqdsnwMg+mhOQQnw.user.46.165.242.75.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.lisp
Subject: .Re: newbie exploring better ways
Date: Tue, 15 Feb 2022 20:00:53 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <suh0pk$c9a$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="12586"; posting-host="wwAjkVBqdsnwMg+mhOQQnw.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. - Tue, 15 Feb 2022 20:00 UTC

Ken Tilton wrote:

> > The following function removes only the first occurrence of an element
> > from a list. Is this very different than how experienced Lispers do
> > things? The function is part of my homework assignment. However, my
> > homework is just to write a function that does its job. I am trying to
> > learn if there are better ways to do it.
> >
> > (defun remv (item l)
> > "a function to remove (without modifying the list) the FIRST
> > occurrence of a given element"
> > (let ((result-list nil)(flag 0))
> > (dolist (curr l)
> > (if (equalp curr item)
> > ( if(equalp flag 1) (push curr result-list) (setq flag 1))
> > (push curr result-list)))
> > (reverse result-list)))
>
> Not (remove item l :count 1)? :)
>
> OK, presuming you were under orders to roll your own implementation from
> more basic stuff, Griff has given you excellent guidance on how to
> create a neater solution. On a grander level...
>
> I think you asked because you already sensed it could be done more
> easily. I know the feeling, witness a couple of threads I started here
> on real-world problems that began "There's gotta be a better way" and
> like you I was just going from a gut feel in re the contrast between the
> task and the code I had produced to accomplish it.
>
> So in this case, an experienced lisper would conclude (as you seemed to
> have) whoa that is too much. How about?:
>
> (loop with nailed
> for x in l
> if nailed collect x
> else if (equalp x item) do (setf nailed t)
> else collect x)
>
> But in this case Griff's recursive solution is vastly nicer and more
> elegant and functional and good with children, you should work that out.

Gauche Scheme

(use srfi-1) ;; break

(define (remfirst x xs)
(let-values (((fore aft) (break (cut equal? <> x) xs)))
(append fore (drop* aft 1))))

(remfirst 33 '(2 3 33 33 44 8))
===>
(2 3 33 44 8)

--
archive.org/details/nolies


devel / comp.lang.lisp / .Re: newbie exploring better ways

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor