Skip to Content.
Sympa Menu

k-user - RE: [[K-user] ] Choose something in the middle of a list

k-user AT lists.cs.illinois.edu

Subject: K-user mailing list

List archive

RE: [[K-user] ] Choose something in the middle of a list


Chronological Thread 
  • From: "Chen, Xiaohong" <xc3 AT illinois.edu>
  • To: Derek Sorensen <derek AT pyrofex.net>
  • Cc: "k-user AT lists.cs.illinois.edu" <k-user AT lists.cs.illinois.edu>
  • Subject: RE: [[K-user] ] Choose something in the middle of a list
  • Date: Wed, 15 Aug 2018 22:48:39 +0000
  • Accept-language: en-US
  • Authentication-results: illinois.edu; spf=pass smtp.mailfrom=xc3 AT illinois.edu; dmarc=pass header.from=illinois.edu

Hi Derek,

The pattern you wrote needs associative and commutative matching (AC
matching),
which is not fully supported.

You could define an auxillary function that scan the list and pick an element,
in the standard functional programming head::tail style, or create a new cell
and put your list there. Then you could write
rule <cell> ... X => something ... <\cell>
as AC matching in cells is supported.

Best,
Xiaohong

-------------------------
Chen, Xiaohong
BSc, Peking University
PhD student, UIUC

________________________________________
From: Derek Sorensen
[derek AT pyrofex.net]
Sent: Wednesday, August 15, 2018 5:19 PM
To:
k-user AT lists.cs.illinois.edu
Subject: [[K-user] ] Choose something in the middle of a list

Hi all,

I’m trying to tell K5 to choose an element of a list, saying that it could be
anywhere in the list. In K3.4 I could just write as a pattern

ListHead:List ListItem(X) ListTail:List

and K would match this pattern if X was anywhere in the list, since ListHead
or ListTail could be potentially empty. K5 doesn’t let me do that; it returns
an error saying “Unsupported associative matching on list.” Is there any way
to choose something out of a list without needing it to be the first or last
element?

Thanks,
Derek



Archive powered by MHonArc 2.6.19.

Top of Page