-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to notate
TypedSlot
using term ∷ type
notation
This together with `TypingJudgement >> asSlot` allows to use `term ∷ type` notation when defining typed instance variables and elements of future class `Record`.
- Loading branch information
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
]. | ||
] | ||
] |