Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Your reasoning powers are good, and you are a fairly good planner.


comp / comp.lang.lisp / .Re: simple lisp function

SubjectAuthor
* .Re: simple lisp functionB. Pym
+* Re: .Re: simple lisp functionHenHanna
|`- Re: .Re: simple lisp functionsteve g
`- Re: .Re: simple lisp functionB. Pym

1
Subject: .Re: simple lisp function
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Thu, 6 Jun 2024 10:38 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: .Re: simple lisp function
Date: Thu, 6 Jun 2024 10:38:54 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <v3s3jt$1fhlp$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Thu, 06 Jun 2024 12:38:54 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="e7864bfc360e71a963a102a78e3bcf96";
logging-data="1558201"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/GdrZ6naW38szeXJHXxO6b"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:06InufgmAtrETGEuyAqvVRWIgLA=
View all headers

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 '- '())
===>
((-))

Subject: Re: .Re: simple lisp function
From: HenHanna
Newsgroups: comp.lang.lisp
Organization: novaBBS
Date: Thu, 6 Jun 2024 20:21 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: HenHanna@dev.null (HenHanna)
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
View all headers

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
?

Subject: Re: .Re: simple lisp function
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Thu, 6 Jun 2024 23:31 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: .Re: simple lisp function
Date: Thu, 6 Jun 2024 23:31:05 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <v3tgrm$1nift$1@dont-email.me>
References: <v3s3jt$1fhlp$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Fri, 07 Jun 2024 01:31:06 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="0664cbc0701e7189d76401c36ed24bc2";
logging-data="1821181"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18beMOgP8s0oNDZWG1nira4"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:kwuvhThgNugHTYyiZpJE9vjcAhk=
View all headers

On 6/6/2024, 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 '- '())
> ===>
> ((-))
>

Gauche or Racket Scheme:

(use srfi-42) ;; list-ec for Gauche
or
(require srfi/42) ;; list-ec for Racket

(define (variations item seq)
(list-ec (: i (+ 1 (length seq)))
`(,@(take seq i) ,item ,@(drop seq i))))

Subject: Re: .Re: simple lisp function
From: steve g
Newsgroups: comp.lang.lisp
Date: Sat, 10 Aug 2024 17:33 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!border-3.nntp.ord.giganews.com!local-4.nntp.ord.giganews.com!border-1.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sat, 10 Aug 2024 17:33:15 +0000
From: sgonedes1977@gmail.com (steve g)
Newsgroups: comp.lang.lisp
Subject: Re: .Re: simple lisp function
References: <v3s3jt$1fhlp$1@dont-email.me>
<806cc1215afc0176956ea8bfdb3cbcff@www.novabbs.com>
Date: Sat, 10 Aug 2024 13:33:15 -0400
Message-ID: <87bk20ffl0.fsf@gmail.com>
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:lfB+iibynsVbmrSpMCm9u2KWnZI=
MIME-Version: 1.0
Content-Type: text/plain
Lines: 51
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-pm30bw+OwFLIMXgaBifPL+6kE9APkRSokme61F8UEBp/vh1KQ3kRW7UindaS6ni39nnXiWng4sohUvI!I+uGitODtmmYCQjG2BUmIyTJ/haOTGPicf1BLV8ypZk8IK8=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
View all headers

HenHanna <HenHanna@dev.null> writes:

> 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 ?

lisp programmers?

CL-USER> (mapcon #'list '(X 1 2 3 4))
((X 1 2 3 4) (1 2 3 4) (2 3 4) (3 4) (4))

1

rocksolid light 0.9.8
clearnet tor