String patterns #28

Closed
opened 2024-04-05 22:50:47 +00:00 by scott · 3 comments
Owner

For building an Eliza, we have determined that we want & need string pattern matching, not just collections.

The way this will go is using template strings as a mirror. So, consider:

let bar = "bar"
let foo = "foo"
let foobar = "{foo} {bar}" &-> "foo bar"

match str with {
  "foo" -> :foo & matches only "foo"
  "foo {x}" -> :foo-and-then & matches "foo " with any positive string after it
    & bindings must be at least one character long? or can they bind empty string?
  "{x} and then {y}" -> :and-then & matches "a and then b" or "x and then y"
}

The only unresolved question I can think of right now is whether a binding in a string pattern (including the placeholder) matches zero-or-more or one-or-more characters.

One-or-more is the obvious answer, and I think that's probably a good place to start.

For building an Eliza, we have determined that we want & need string pattern matching, not just collections. The way this will go is using template strings as a mirror. So, consider: ``` let bar = "bar" let foo = "foo" let foobar = "{foo} {bar}" &-> "foo bar" match str with { "foo" -> :foo & matches only "foo" "foo {x}" -> :foo-and-then & matches "foo " with any positive string after it & bindings must be at least one character long? or can they bind empty string? "{x} and then {y}" -> :and-then & matches "a and then b" or "x and then y" } ``` The only unresolved question I can think of right now is whether a binding in a string pattern (including the placeholder) matches zero-or-more or one-or-more characters. One-or-more is the obvious answer, and I think that's probably a good place to start.
scott added the
enhancement
proposal
question
semantics
syntax
ux
labels 2024-04-05 22:51:14 +00:00
Author
Owner

MNL and SCR chatted, and right now we think a zero-char match/binding is actually a different thing.

So bindings in string patterns in this way match more than one character.

MNL and SCR chatted, and right now we think a zero-char match/binding is actually a different thing. So bindings in string patterns in this way match more than one character.
scott added the
accepted
next
labels 2024-04-05 22:55:46 +00:00
scott added this to the (deleted) project 2024-04-26 21:11:59 +00:00
scott added this to the Computer Class milestone 2024-04-26 21:14:33 +00:00
scott added a new dependency 2024-05-06 16:40:50 +00:00
Author
Owner

Implemented in 5deab18356. Not closing yet for to do more testing. At current, the following works as expected:

match "You are the eggman" with {
  "I {verb} the {noun}" -> (verb, noun)
  "You {verb} the {noun}" -> (verb, noun)
  _ -> :nope
} &=> ("are", "eggman")

I believe this is sufficient for Computer Class.

Implemented in 5deab18356. Not closing yet for to do more testing. At current, the following works as expected: ``` match "You are the eggman" with { "I {verb} the {noun}" -> (verb, noun) "You {verb} the {noun}" -> (verb, noun) _ -> :nope } &=> ("are", "eggman") ``` I believe this is sufficient for Computer Class.
Author
Owner

Closing for now. If testing uncovers bugs, will file bugfix issues.

Closing for now. If testing uncovers bugs, will file bugfix issues.
scott closed this issue 2024-05-19 18:42:21 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Blocks
You do not have permission to read 2 dependencies
Reference: twc/ludus#28
No description provided.