guicho271828 / trivia

Pattern Matcher Compatible with Optima
Other
332 stars 22 forks source link

Support for FSet #127

Closed mdbergmann closed 3 years ago

mdbergmann commented 3 years ago

Hi.

I have created some rudimentary patterns for FSet support.

I'm not entirely happy about the fset:seq patterns. It seems fset:seq is an indexed map sort of thing, so probably more similar to a vector. But I couldn't make that work. The 'sequence' pattern seemed simple enough. What can the vector/array pattern do more than the sequence pattern?

The fset-seq-ht is supposed to match for head and tail. But I'm not happy with that either. Well, the whole fset-seq pattern should work more like list/list or vector/vector. However, I couldn't figure out easily how the vector pattern works and how I could apply that for fset:seq.

Any input is appreciated.

mdbergmann commented 3 years ago

OK. I think I got somethink better now. fset-seq and fset-seq* now work similar as list and list*.

mdbergmann commented 3 years ago

I'm satisfied for a first version. When merged I would add some documentation to the wiki.

guicho271828 commented 3 years ago

Could you consider renaming some patterns so that it reflects the duality between the constructor and the destructor? I also believe fset-equal should you just reuse equal? symbol in fset, and so on.

mdbergmann commented 3 years ago

Could you consider renaming some patterns so that it reflects the duality between the constructor and the destructor?

Hmm. I'm not entirely certain what you mean?

I also believe fset-equal should you just reuse equal? symbol in fset, and so on.

fset-equal uses fset:equal? in the guard1 test-form. Or do you mean something else?

guicho271828 commented 3 years ago

duality between the constructor and the destructor XXX deconstructor

It is that the pattern match (deconstructor, sorry I misspelled) form has the same visual form as the constructor. So a pattern for matching a list should take the same form as making a list, thus it should be (list a b c). Same thing --- patterns for matching an fset object should roughly correspond to the form that makes a new fset object.

guicho271828 commented 3 years ago

fset-equal uses fset:equal? in the guard1 test-form. Or do you mean something else?

I just mean (defpatttern fset:equal? ... ) just like other equality patterns are reusing CL symbols, e.g., (defpattern cl:equal ...)

mdbergmann commented 3 years ago

duality between the constructor and the destructor XXX deconstructor

It is that the pattern match (deconstructor, sorry I misspelled) form has the same visual form as the constructor. So a pattern for matching a list should take the same form as making a list, thus it should be (list a b c). Same thing --- patterns for matching an fset object should roughly correspond to the form that makes a new fset object.

OK, got it. That is the case for all except fset:map. I'll see if I can get this working.

mdbergmann commented 3 years ago

fset-equal uses fset:equal? in the guard1 test-form. Or do you mean something else?

I just mean (defpatttern fset:equal? ... ) just like other equality patterns are reusing CL symbols, e.g., (defpattern cl:equal ...)

OK. I'll rename them to match the real fset functions.

mdbergmann commented 3 years ago

fset-equal uses fset:equal? in the guard1 test-form. Or do you mean something else?

I just mean (defpatttern fset:equal? ... ) just like other equality patterns are reusing CL symbols, e.g., (defpattern cl:equal ...)

Hmm. I need a bit guidance here. A pattern: (defpattern fset:equal? does that work? At least I'm getting an error when trying to export fset:equal?. I believe that's why I used fset-equal.

mdbergmann commented 3 years ago

Alright. Sorry my constant steam of messages here.

Seems like stuff that is readily defined in fset, like fset:map can be added as pattern and no export is necessary. But I don't quite understand how that would work for fset:seq* which doesn't exist in fset?

mdbergmann commented 3 years ago

Changed patterns to match the construction. Pattern are now available as: fset:equal?, fset:map, fset:set, fset:seq.

guicho271828 commented 3 years ago

Thanks for the update. The change seems to reflect what I imagined.