Administrator
|
Interesting observation and nice workaround Kirill!
Ah, the %^&%ing joys of Macro ;-) "!MAIN. *But with the help of !EVAL and being put in apostrophes, it works allright."
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by Kirill Orlov
At 01:48 AM 1/17/2014, Kirill Orlov wrote:
>Richard Ristow wrote: >>When you write >>!LET !Output = !F(!Input) >>!F's output has gone to the SPSS code space, or code stream, and >>the calling macro has no access to it. > >+1, Richard. >But it is possible to make the text !F() produces a value accessible >to the parent macro via !EVAL + quoting, - as I've shown above. >!LET !Output = !EVAL('!F(!Input)') Bravo, and thank you, Kirill! Now that you've shown this, I realize that my own !MacEcho (appended) uses the output of an !EVAL as within-macro text, and manipulates it. I do not claim prior discovery; I've used !MacEcho for years, but never recognized the importance of what I had. ======================================================== APPENDIX: !MacEcho - display a macro call and its result ======================================================== * Macro /* !MacEcho */ is used to display the macro expansion . DEFINE !MacEcho(!POS !NOEXPAND !CMDEND) ECHO !QUOTE(!CONCAT(' Call : ',!1)). ECHO !QUOTE(!CONCAT(' Result: ',!EVAL(!1))). !ENDDEFINE. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Administrator
|
In my mind the beauty of this is resolving return values from parameterized macros ;-)
I just thought of another way to do it using what I will refer to as a "callback". Closely related to the Recursion ideas we were exploring recently. One could of course set up the parameterization in !Main so it could have several new objects returned from !SUBMacro. Of course with modification, !SubMacro could also "Chain" to other submacros etc... One could also set up the parameterization of !SUBMacro so it would behave differently dependent upon values of !2. I think this is actually much cleaner and more general than what Kirill built out. DEFINE !SUBMacro ( !POS !CHAREND("/") / !POS !TOKENS(1) ). !IF (!2 !EQ 1) !THEN !Main !1 /Return /0 . !IFEND !ENDDEFINE . DEFINE !Main ( !POS !CHAREND("/") / !POS !CHAREND("/") !DEFAULT ("") / !POS !CMDEND !DEFAULT (1) ). !IF (!3 !EQ 1) !THEN !SUBMacro !1 / 1 . !IFEND /* Process return value(s) from call to !SUBMacro */. !IF (!3 !EQ 0) !THEN ECHO !QUOTE(!CONCAT(!1," ",!2)). !IFEND !ENDDEFINE. !Main GoingIn . Result: GoingIn Return
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Administrator
|
A modification which passes the callback macro into !SubMacro ;-) DEFINE !SUBMacro ( !POS !CHAREND("/") / !POS !CHAREND("/") / !POS !TOKENS(1)). !IF (!3 !EQ 1) !THEN !UNQUOTE(!2) !1 /Return /0 . !IFEND !ENDDEFINE . DEFINE !Main ( !POS !CHAREND("/") / !POS !CHAREND("/") !DEFAULT ("") / !POS !CMDEND !DEFAULT (1) ). !IF (!3 !EQ 1) !THEN !SUBMacro !1 / !2 / 1 . !IFEND !IF (!3 !EQ 0) !THEN ECHO !QUOTE(!CONCAT(!1," ",!2)). !IFEND !ENDDEFINE. !Main GoingIn / '!Main' / .
On Sun, Jan 19, 2014 at 6:19 PM, David Marso [via SPSSX Discussion] <[hidden email]> wrote: In my mind the beauty of this is resolving return values from parameterized macros ;-)
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Administrator
|
An example of "chaining" macros and parsing a stack of return values.
-- DEFINE !S2( !POS !CHAREND("/") / !POS !CHAREND("/") ). !LET !MSG="S2" !UNQUOTE(!HEAD(!2)) !CONCAT (!1," ",!QUOTE(!MSG))/!TAIL(!2) . !ENDDEFINE . DEFINE !SUBMacro ( !POS !CHAREND("/") / !POS !CHAREND("/") ). !LET !MSG="SubMacro" !UNQUOTE(!HEAD(!2)) !CONCAT(!1," ",!QUOTE(!MSG))/!TAIL(!2) . !ENDDEFINE . /* Call stack / Macro Chain / State */. DEFINE !Main ( !POS !CHAREND("/") / !POS !CHAREND("/") !DEFAULT ("") / !POS !CMDEND !DEFAULT (1) ). !LET !MSG="Main" !IF (!2 !NE !NULL) !THEN !UNQUOTE(!HEAD (!2)) !CONCAT(!1," ",!QUOTE(!MSG)) / !TAIL(!2) . !IFEND !IF (!2 !EQ !NULL) !THEN !LET !Return=!CONCAT(!1," ",!2," ",!QUOTE(!MSG)) ECHO !QUOTE(!CONCAT('Return=',!Return)). !DO !Arg !IN (!Return) ECHO !QUOTE(!arg). !DOEND !IFEND !ENDDEFINE. SET PRINTBACK Off MPRINT Off. !Main 'GoingIn' /'!SubMacro' '!S2' '!Main' . --- OUTPUT--- Return='GoingIn' 'Main' 'SubMacro' 'S2' 'Main' 'GoingIn' 'Main' 'SubMacro' 'S2' 'Main' ===
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Free forum by Nabble | Edit this page |