Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Hell is empty and all the devils are here. -- Wm. Shakespeare, "The Tempest"


comp / comp.lang.lisp / Re: string chains

SubjectAuthor
* string chainsB. Pym
`* Re: string chainsHenHanna
 `- Re: string chainsKaz Kylheku

1
Subject: string chains
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Mon, 5 Aug 2024 23:34 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
Subject: string chains
Date: Mon, 5 Aug 2024 23:34:32 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <v8rni4$15nl8$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Tue, 06 Aug 2024 01:34:32 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="51ec0738d78fae23c740e6e73e04a0c7";
logging-data="1236648"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195vPZLsLLv5L3Xl7tGETe8"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:nuR71LXQe71X2xqE27ZwpBslZDs=
View all headers

> The task is to somehow implement Amb, and demonstrate it with
> a program which chooses one word from each of the following
> four sets of character strings to generate a four-word
> sentence:
>
> "the" "that" "a"
> "frog" "elephant" "thing"
> "walked" "treaded" "grows"
> "slowly" "quickly"
>
> The constraint to be satisfied is that the last character of
> each word (other than the last) is the same as the first
> character of its successor.
>
> The only successful sentence is "that thing grows slowly";
> other combinations do not satisfy the constraint and thus
> fail.

newLISP

(define (cartesian-product lists)
(if (null? lists)
'(())
(let (subproduct (cartesian-product (rest lists)))
(apply append
(map
(fn (x) (map (fn (xs) (cons x xs)) subproduct))
(first lists))))))

(define (good? xs)
(for-all
(fn (pair) (starts-with (pair 1) ((pair 0) -1)))
(map list (0 -1 xs) (rest xs))))

(filter good?
(cartesian-product
'(("preconize" "cozy" "Lilliputian")
("climb" "nub" "snob" "end" "yet")
("however" "by" "but" "so" "tot")
("the" "that" "a" "tack" "of")
("frog" "elephant" "thing")
("walked" "treaded" "grows")
("slowly" "quickly")
("yank" "can" "you" "choose")
("won't" "understand"))))

(("cozy" "yet" "tot" "that" "thing" "grows" "slowly" "you"
"understand")
("Lilliputian" "nub" "but" "that" "thing" "grows" "slowly"
"you" "understand"))

Subject: Re: string chains
From: HenHanna
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Tue, 6 Aug 2024 17:02 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna@devnull.tb (HenHanna)
Newsgroups: comp.lang.lisp
Subject: Re: string chains
Date: Tue, 6 Aug 2024 10:02:30 -0700
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <v8tkv7$1n9hq$3@dont-email.me>
References: <v8rni4$15nl8$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 06 Aug 2024 19:02:32 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="e8f11e744464abe1aea113e5c87782ad";
logging-data="1812026"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ZDCWM1bRvUGvd76nrXqhHofsANl2BBZk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:IamhzVnu7bCA5bRPohTwVF0+/qg=
Content-Language: en-US
In-Reply-To: <v8rni4$15nl8$1@dont-email.me>
View all headers

On 8/5/2024 4:34 PM, B. Pym wrote:
>> The task is to somehow implement Amb, and demonstrate it with
>> a program which chooses one word from each of the following
>> four sets of character strings to generate a four-word
>> sentence:
>>
>> "the" "that" "a"
>> "frog" "elephant" "thing"
>> "walked" "treaded" "grows"
>> "slowly" "quickly"
>>
>> The constraint to be satisfied is that the last character of
>> each word (other than the last) is the same as the first
>> character of its successor.
>>
>> The only successful sentence is "that thing grows slowly";
>> other combinations do not satisfy the constraint and thus
>> fail.
>
> newLISP
>
> (define (cartesian-product lists)
> (if (null? lists)
> '(())
> (let (subproduct (cartesian-product (rest lists)))
> (apply append
> (map
> (fn (x) (map (fn (xs) (cons x xs)) subproduct))
> (first lists))))))
>
> (define (good? xs)
> (for-all
> (fn (pair) (starts-with (pair 1) ((pair 0) -1)))
> (map list (0 -1 xs) (rest xs))))
>
> (filter good?
> (cartesian-product
> '(("preconize" "cozy" "Lilliputian")
> ("climb" "nub" "snob" "end" "yet")
> ("however" "by" "but" "so" "tot")
> ("the" "that" "a" "tack" "of")
> ("frog" "elephant" "thing")
> ("walked" "treaded" "grows")
> ("slowly" "quickly")
> ("yank" "can" "you" "choose")
> ("won't" "understand"))))
>
> (("cozy" "yet" "tot" "that" "thing" "grows" "slowly" "you"
> "understand")
> ("Lilliputian" "nub" "but" "that" "thing" "grows" "slowly"
> "you" "understand"))

Did you avoid using Scheme because it's bad for this
type of string manipulation?

----- e.g. in Python the last char of string is just String[-1]

>>> May 12, 2019 — newLISP is a general purpose scripting
language for developing web applications and programs in general in the
domains of artificial ...

Subject: Re: string chains
From: Kaz Kylheku
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Wed, 7 Aug 2024 03:51 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 643-408-1753@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp
Subject: Re: string chains
Date: Wed, 7 Aug 2024 03:51:20 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 88
Message-ID: <20240806204852.766@kylheku.com>
References: <v8rni4$15nl8$1@dont-email.me> <v8tkv7$1n9hq$3@dont-email.me>
Injection-Date: Wed, 07 Aug 2024 05:51:20 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="2df3d935c340d38657208d5227a16b17";
logging-data="2285645"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Aap+EWPWSHYOODLRK+WMxmMzEZOIYAxg="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:rWJ/2X6o6IHPvsM2Q6Dpl8ROIfY=
View all headers

On 2024-08-06, HenHanna <HenHanna@devnull.tb> wrote:
> On 8/5/2024 4:34 PM, B. Pym wrote:
>>> The task is to somehow implement Amb, and demonstrate it with
>>> a program which chooses one word from each of the following
>>> four sets of character strings to generate a four-word
>>> sentence:
>>>
>>> "the" "that" "a"
>>> "frog" "elephant" "thing"
>>> "walked" "treaded" "grows"
>>> "slowly" "quickly"
>>>
>>> The constraint to be satisfied is that the last character of
>>> each word (other than the last) is the same as the first
>>> character of its successor.
>>>
>>> The only successful sentence is "that thing grows slowly";
>>> other combinations do not satisfy the constraint and thus
>>> fail.
>>
>> newLISP
>>
>> (define (cartesian-product lists)
>> (if (null? lists)
>> '(())
>> (let (subproduct (cartesian-product (rest lists)))
>> (apply append
>> (map
>> (fn (x) (map (fn (xs) (cons x xs)) subproduct))
>> (first lists))))))
>>
>> (define (good? xs)
>> (for-all
>> (fn (pair) (starts-with (pair 1) ((pair 0) -1)))
>> (map list (0 -1 xs) (rest xs))))
>>
>> (filter good?
>> (cartesian-product
>> '(("preconize" "cozy" "Lilliputian")
>> ("climb" "nub" "snob" "end" "yet")
>> ("however" "by" "but" "so" "tot")
>> ("the" "that" "a" "tack" "of")
>> ("frog" "elephant" "thing")
>> ("walked" "treaded" "grows")
>> ("slowly" "quickly")
>> ("yank" "can" "you" "choose")
>> ("won't" "understand"))))
>>
>> (("cozy" "yet" "tot" "that" "thing" "grows" "slowly" "you"
>> "understand")
>> ("Lilliputian" "nub" "but" "that" "thing" "grows" "slowly"
>> "you" "understand"))
>
>
> Did you avoid using Scheme because it's bad for this
> type of string manipulation?

There isn't a lot of string manipulation here; just checking
that the last character of a string is or isn't the same
as the first character of another.

1> (defun is-shiritori (wlist)
(if-match @(scan @(require (@w1 @w2 . @nil)
(or (empty w1)
(empty w2)
(neq [w1 -1] [w2 0]))))
wlist
nil t))
is-shiritori
2> [apply maprend [chain list [iff is-shiritori list]]
'(("preconize" "cozy" "Lilliputian")
("climb" "nub" "snob" "end" "yet")
("however" "by" "but" "so" "tot")
("the" "that" "a" "tack" "of")
("frog" "elephant" "thing")
("walked" "treaded" "grows")
("slowly" "quickly")
("yank" "can" "you" "choose")
("won't" "understand"))]
(("cozy" "yet" "tot" "that" "thing" "grows" "slowly" "you" "understand")
("Lilliputian" "nub" "but" "that" "thing" "grows" "slowly" "you"
"understand"))

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

1

rocksolid light 0.9.8
clearnet tor