Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You are deeply attached to your friends and acquaintances.


comp / comp.lang.scheme / Re: function to split a string into a list of characters

SubjectAuthor
o Re: function to split a string into a list of charactersB. Pym

1
Subject: Re: function to split a string into a list of characters
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Fri, 13 Sep 2024 21:50 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: function to split a string into a list of characters
Date: Fri, 13 Sep 2024 21:50:55 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <vc2c3r$1244m$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Fri, 13 Sep 2024 23:50:55 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="b23a757b35dd03cbd4947edb1cfbe6d8";
logging-data="1118358"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+OADNM2IjxKbp9BawnBbJL"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:YXj2z0+PjKg/830LNNkjBS/mGx8=
View all headers

Eric Smith wrote:

> ; (rm1 "abc" 0) ==> "bc" (rm1 "tea" 1) ==> "ta"
> (defun rm1 (seq which)
> (remove-if #'true seq :start which :end (1+ which)))
>
> ; (consword #\a "bc") ==> "abc"
> (defun consword (char word)
> (concatenate 'string (string char) word))
>
> ; (anagrams "ah") ==> ("ah" "ha")
> (defun anagrams (word)
> (if (= (length word) 1) (list word)
> (loop as x across word
> as i upfrom 0
> as subword = (rm1 word i)
> nconc (loop as y in (anagrams subword)
> collect (consword x y)))))

Gauche Scheme

(use util.combinations) ;; permutations

(define (anagrams word)
;; Clojure-style threading or pipelining.
(->> word string->list permutations (map list->string)))

(anagrams "try")
===>
("try" "tyr" "rty" "ryt" "ytr" "yrt")

Given:

(define-syntax ->>
(syntax-rules ()
[(_ x) x]
[(_ x (y ...) z ...)
(->> (y ... x) z ...)]
[(_ x y z ...)
(->> (y x) z ...)]))

1

rocksolid light 0.9.8
clearnet tor