Deutsch   English   Français   Italiano  
<806cc1215afc0176956ea8bfdb3cbcff@www.novabbs.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder9.news.weretis.net!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: HenHanna <HenHanna@dev.null>
Newsgroups: comp.lang.lisp
Subject: Re: .Re: simple lisp function
Date: Thu, 6 Jun 2024 20:21:06 +0000
Organization: novaBBS
Message-ID: <806cc1215afc0176956ea8bfdb3cbcff@www.novabbs.com>
References: <v3s3jt$1fhlp$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
	logging-data="3399614"; mail-complaints-to="usenet@i2pn2.org";
	posting-account="25PjXUQKTQXKZnoxTqVufZcfCkmLjnu8AjjfHtuMysE";
User-Agent: Rocksolid Light
X-Rslight-Posting-User: 5a1f1f09909a70d7ae18ae9af00e018f83ece577
X-Spam-Checker-Version: SpamAssassin 4.0.0
X-Face: P#KeQ)CUdd!==@fw~Ms1=,Hb`IWtb6:Mw)x3B=H1BfNC\lz?Nb&)M9}$>?'X7l;CuB}utlJ=PHsRBSG6X>dYZ$[>P]$~+`>@V6$t}hTLoQ7XC~W\>:`B3ALU]SH;d(\MEc}znW8m}-ma&yPFkJ2@KSQrz=!Y;><;6a>z6N+mt`ClCt.PAE<o+B$qjwejZSZ,w]^;vrdl24z5(pm={l,F10qRDF
X-Rslight-Site: $2y$10$taH786gVGvB5BP1QOWjZy.XAmenOwLXjlhglyGhwodJQJ1XRstONq
Bytes: 2578
Lines: 45

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 
?