Skip to content

Commit

Permalink
generic.multi: Some convience syntax for dispatch tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
timor committed Feb 17, 2021
1 parent b2a104b commit 6490460
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
26 changes: 22 additions & 4 deletions core/generic/multi/multi.factor
@@ -1,8 +1,8 @@
USING: accessors arrays assocs classes classes.algebra classes.algebra.private
classes.private combinators definitions effects effects.parser generalizations
generic generic.parser generic.single generic.single.private generic.standard
kernel make math math.order namespaces parser quotations sequences sets sorting
vectors words ;
classes.private combinators definitions effects effects.parser fry
generalizations generic generic.parser generic.single generic.single.private
generic.standard kernel make math math.order namespaces parser
prettyprint.custom quotations sequences sets sorting vectors words ;

IN: generic.multi

Expand Down Expand Up @@ -295,3 +295,21 @@ ERROR: empty-dispatch-spec seq ;
] with-definition ;

SYNTAX: MM: (MM:) define ;

! * Literal syntax for dispatch specifiers

! Currently only covariant-tuple. For the moment just some convenience to
! identify and print multi-methods using the existing single method code with
! something like M\ D{ class1 class2 } generic
! But defining with M: D{ class1 class2 } generic ... ; does not turn the generic
! into a multi-generic !

SYNTAX: D{
\ } [ <covariant-tuple> ] parse-literal ;

M: covariant-tuple pprint* pprint-object ;

M: covariant-tuple pprint-delims
drop \ D{ \ } ;

M: covariant-tuple >pprint-sequence classes>> ;
2 changes: 1 addition & 1 deletion core/syntax/syntax.factor
Expand Up @@ -112,7 +112,7 @@ IN: bootstrap.syntax

"POSTPONE:" [ scan-word suffix! ] define-core-syntax
"\\" [ scan-word <wrapper> suffix! ] define-core-syntax
"M\\" [ scan-word scan-word lookup-method <wrapper> suffix! ] define-core-syntax
"M\\" [ scan-class scan-word lookup-method <wrapper> suffix! ] define-core-syntax
"inline" [ last-word make-inline ] define-core-syntax
"recursive" [ last-word make-recursive ] define-core-syntax
"foldable" [ last-word make-foldable ] define-core-syntax
Expand Down

0 comments on commit 6490460

Please sign in to comment.