Re: [SPOILER] Re: Perl Quiz of the Week #25 (RPN calculator)
Mike and Valerie <mikeandval-kucEqjffpRpWk0Htik3J/[email protected]> Thu, 7 Oct 2004 08:19:46 -0400
| Newsgroups | gmane.comp.lang.perl.qotw.discuss |
|---|---|
| Message-ID | <[email protected]> |
On Oct 6, 2004, at 8:52 AM, Peter Haworth wrote:
> On Tue, 5 Oct 2004 13:01:28 -0400, Mark Jason Dominus wrote:
>> On Oct 5, 2004, at 12:42 PM, Peter Haworth wrote:
>>>
>>> I'm thinking about allowing user-defined functions, but not being
>>> a Forth programmer, I'm not sure how the syntax ought to look.
>>
>> In PostScript you define a procedure by doing something like:
>>
>> { 2 mul } /double def
>>
>> After processing the '}' operator, the stack contains an anonymous
>> function. '/double' pushes the "name object" representing the name
>> "double", and then "def" is a binary operator which expects a name
>> and a value and associates the two in the current dictionary.
> --
> Peter Haworth [email protected]
> "I even make off-by-one errors counting on my fingers.
> No wonder I can't debug my programs :-)"
> -- Nathan Torkington
Just a point of clarification, the postscript would actually be:
/double { 2 mul } def
or
{ 2 mul } /double exch def
Don't know if this would make for a simpler RPN implementation here
or not. But, if anyone were to try this within postscript, they
would at best get "strange" results, or more probably get a stack
exception.
mike