[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-smalltalk] Presource example: #% (StringBindWithMacro)
From: |
Stephen Compall |
Subject: |
[Help-smalltalk] Presource example: #% (StringBindWithMacro) |
Date: |
Tue, 26 Jun 2007 02:54:42 -0500 |
Attached is an example of using Presource for writing compiler-macros
instead of language extensions (like #condSelect). I don't think the
last post of Presource itself will run it, but I'll roll another later.
st> (StringBindWithMacro new expandMessageWithLocalReturn:
(Presrc.CodeTemplate parseExpr:
'''%1 = %2. (%1 %<>|<=>3 0)''
% {expression printString. 2 + 2. 2 + 2 strictlyPositive}'))
printNl!
RBMessageNode(
[| gensym166 formatTmp167 formatTmp168 formatTmp169 |
gensym166 := WriteStream on: (String new: 45).
formatTmp167 := expression.
formatTmp168 := 2 + 2.
formatTmp169 := 2 + 2 strictlyPositive.
formatTmp167 printOn: gensym166.
' = ' displayOn: gensym166.
formatTmp168 displayOn: gensym166.
'. (' displayOn: gensym166.
formatTmp167 printOn: gensym166.
' ' displayOn: gensym166.
(formatTmp169 ifTrue: ['>'] ifFalse: ['<=']) displayOn: gensym166.
' 0)' displayOn: gensym166.
gensym166 contents] value)
Writing this also showed me that I should introduce a #condEvery and a
#condSome macro, variations on the #condSelect theme, which I will
probably want to finish (and do unit tests for all of this) before
posting Presource again.
--
;;; Stephen Compall ** http://scompall.nocandysw.com/blog **
"Peta" is Greek for fifth; a petabyte is 10 to the fifth power, as
well as fifth in line after kilo, mega, giga, and tera.
-- Lee Gomes, performing every Wednesday in his tech column
"Portals" on page B1 of The Wall Street Journal
+StringBindWithMacro.st
Description: Text document
signature.asc
Description: This is a digitally signed message part
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Help-smalltalk] Presource example: #% (StringBindWithMacro),
Stephen Compall <=