Deutsch   English   Français   Italiano  
<vc2c3r$1244m$1@dont-email.me>

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

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: "B. Pym" <Nobody447095@here-nor-there.org>
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=
Bytes: 1887

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 ...)]))