[plt-dev] struct match-expander a la struct-copy
On Jun 2, Jay McCarthy wrote:
> The structure patterns in scheme/match have always bugged me that
> they didn't let you put the fields in any order and you had to put
> in _ for the fields you didn't care about.
>
> I've remedied this with a new match expander, struct*. I'd like to
> put in the tree. Do people agree?
But the problem with that is that it's even farther away from the
syntax to create an instance. Ideally, I'd like to see options to
`define-struct' that can get you a keyword-based constructor instead
or in addition to the positional one. ("In addition too" is a better
option, re the thread on renaming a constructor -- since you'll be
able to specify the name of each constructor.) Then define whatever
constructor was made as a match pattern too. Something like:
(define-struct foo (x y)
#:positional-constructor make-foo1
#:keyworded-cosntrutor make-foo2)
(match ...
[(make-foo1 x y) ...]
;; or
[(make-foo2 #:x x #:y y) ...])
(But I'm not sure about the syntax to define this constructor, it
might be better to follow the syntax for functions:
(define-struct foo (#:x x #:y y))
perhaps even use that to specify defaults. But there are cases where
you want both the positional and the keyworded versions...)
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://www.barzilay.org/ Maze is Life!