class: Cons
added:
#readLispAtomFrom:
#readLispListFrom:
removed:
#realLispAtomFrom:
#realLispListFrom:
changed: #readLispFrom: (send #readLispListFrom: instead of #realLispListFrom:, send #readLispAtomFrom: instead of #realLispAtomFrom:)
--- a/Cons.st Tue Apr 29 15:27:27 2014 +0200
+++ b/Cons.st Wed Apr 30 13:03:07 2014 +0200
@@ -125,6 +125,30 @@
!Cons class methodsFor:'sExpressions'!
+readLispAtomFrom:aStream
+ |chars n|
+
+ aStream skipSeparators.
+ aStream atEnd ifTrue:[^ nil].
+
+ chars := aStream upToMatching:[:ch | ch isSeparator or:[ch = $( or:[ch = $)]]].
+ (n := Number readFromString:chars onError:nil) notNil ifTrue:[
+ "/ smalltalk allows +n; scheme does not
+ (chars startsWith:'+') ifFalse:[
+ ^ n
+ ].
+ ].
+ ^ chars asSymbol
+
+ "
+ self readLispFrom:('(cons 1 2)' readStream).
+ self readLispFrom:('(cons 1+ 2)' readStream).
+ self readLispFrom:('(cons +1 2)' readStream).
+ "
+
+ "Created: / 08-08-2010 / 17:15:18 / cg"
+!
+
readLispFrom:aStream
aStream skipSeparators.
aStream atEnd ifTrue:[^ nil].
@@ -136,9 +160,9 @@
].
aStream peek ==$( ifTrue:[
- ^ self realLispListFrom:aStream
+ ^ self readLispListFrom:aStream
].
- ^ self realLispAtomFrom:aStream
+ ^ self readLispAtomFrom:aStream
"
self readLispFrom:('(cons 1 2)' readStream).
@@ -147,26 +171,7 @@
"Created: / 08-08-2010 / 17:07:49 / cg"
!
-realLispAtomFrom:aStream
- |atom|
-
- aStream skipSeparators.
- aStream atEnd ifTrue:[^ nil].
-
- aStream peek isDigit ifTrue:[
- ^ Number readFrom:aStream
- ].
- atom := aStream upToMatching:[:ch | ch isSeparator or:[ch = $( or:[ch = $)]]].
- ^ atom asSymbol
-
- "
- self readLispFrom:('(cons 1 2)' readStream).
- "
-
- "Created: / 08-08-2010 / 17:15:18 / cg"
-!
-
-realLispListFrom:aStream
+readLispListFrom:aStream
|first this prev element|
aStream next. "/ the leading '('
@@ -696,9 +701,10 @@
!Cons class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/Cons.st,v 1.21 2012-07-26 22:04:19 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/Cons.st,v 1.22 2014-04-30 11:03:07 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic2/Cons.st,v 1.21 2012-07-26 22:04:19 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/Cons.st,v 1.22 2014-04-30 11:03:07 cg Exp $'
! !
+