forked from alex-eg/sex
write a sum's constructors in place
A constructor was a static function per variant. One taking an array field cannot exist, its parameter being a pointer, and building some variants in place and others by call would make two kinds of constructor. In place, every one is a constant where one is wanted, an lvalue a method can take the address of, and nothing a pub sum has to paste into its importer. What the function did for free is done here instead: arity is checked, since a short compound literal zero-fills quietly, and an argument is converted against its field's closure type. The price is that a constructor is no longer a function value; a lambda makes one.
This commit is contained in:
@@ -80,8 +80,8 @@
|
||||
(free self)))
|
||||
|
||||
;;; A pub sum is pasted whole, so the importer builds its own copy of
|
||||
;;; the declarations -- and of the constructors, which is why those are
|
||||
;;; static: two units defining colourːrgb would not link.
|
||||
;;; the declarations; a constructor is written in place where it is
|
||||
;;; called, so there is no function for two units to both define.
|
||||
(pub sum colour ((rgb ((r int) (g int) (b int))) (none ())))
|
||||
|
||||
;;; A spec and a realization over the boundary. The written method
|
||||
|
||||
Reference in New Issue
Block a user