diff --git a/src/Collections-Homogeneous/TypingJudgement.extension.st b/src/Collections-Homogeneous/TypingJudgement.extension.st new file mode 100644 index 000000000..c07d532bc --- /dev/null +++ b/src/Collections-Homogeneous/TypingJudgement.extension.st @@ -0,0 +1,10 @@ +Extension { #name : #TypingJudgement } + +{ #category : #'*Collections-Homogeneous' } +TypingJudgement >> asSlot [ + term isString ifFalse:[ + self error:'term must be a string or symbol'. + ^nil. + ]. + ^TypedSlot named: term asSymbol type: type +] diff --git a/src/MathNotation/TypedSlot.extension.st b/src/MathNotation/TypedSlot.extension.st new file mode 100644 index 000000000..6c224ae1b --- /dev/null +++ b/src/MathNotation/TypedSlot.extension.st @@ -0,0 +1,25 @@ +Extension { #name : #TypedSlot } + +{ #category : #'*MathNotation' } +TypedSlot >> definitionString [ + | scanner typeString | + + "Try to put parenthesis around term and type + when needed. + " + scanner := RBScanner new initializeClassificationTable. + + ^String streamContents: [ :aStream| + name storeOn: aStream. + aStream nextPutAll: ' ∷ '. + + typeString := type printString. + (typeString anySatisfy:[:char | | charCls | (charCls := scanner classify: char) ~~ #alphabetic and:[ charCls ~~ #digit ]]) ifTrue:[ + aStream nextPut:$(. + type printOn: aStream. + aStream nextPut:$). + ] ifFalse:[ + type printOn: aStream + ]. + ] +]