Re: .Re: simple lisp function

Liste des GroupesRevenir à cl lisp 
Sujet : Re: .Re: simple lisp function
De : HenHanna (at) *nospam* dev.null (HenHanna)
Groupes : comp.lang.lisp
Date : 06. Jun 2024, 22:21:06
Autres entêtes
Organisation : novaBBS
Message-ID : <806cc1215afc0176956ea8bfdb3cbcff@www.novabbs.com>
References : 1
User-Agent : Rocksolid Light
B. Pym wrote:

Pascal Bourguignon wrote:

this simple function i'm trying to write is giving me headaches!
basically i want to do something that does:
(variations 'x '(y z)) -> ((x y z) (y x z) (y z x))
>
i come from a procedural programming background and find functional
programming very confusing (especially recursion).  can someone give
me some hints?  my attempts at this make no sense so pasting them
here
would only confirm my newbish forray into LSIP.  thanks for any help!
 (defun variations (item list)
  (if (null list)
    (list (list item))
    (cons (cons item list)
          (mapcar (lambda (rest) (cons (car list) rest))
                  (variations item (cdr list))))))

Gauche Scheme:

(use srfi-1)  ;; split-at
(use srfi-42) ;; list-ec

(define (variations x lst)
  (list-ec (: i (+ 1 (length lst)))
    (receive (a b) (split-at lst i)
      `(,@a ,x ,@b))))

(variations '- '(a b c))     ===>   ((- a b c) (a - b c) (a b - c) (a b
c -))
(variations '- '(a))         ===>   ((- a) (a -))
(variations '- '())          ===>   ((-))
I remember writing this in Lisp and Python.  a few years ago.
Is Scheme (or Gauche) used outside of the Academia?     What kind of people (other than Grad students, Researchers in
Prog.Lang design)
               would know about  Split-at  and  List-ec  and  Receive ?

Date Sujet#  Auteur
6 Jun 24 * .Re: simple lisp function4B. Pym
6 Jun 24 +* Re: .Re: simple lisp function2HenHanna
10 Aug 24 i`- Re: .Re: simple lisp function1steve g
7 Jun 24 `- Re: .Re: simple lisp function1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal