Presource example: #% (StringBindWithMacro)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Presource example: #% (StringBindWithMacro)

S11001001
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

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

+StringBindWithMacro.st (12K) Download Attachment
signature.asc (196 bytes) Download Attachment