Skip to main content
added 12 characters in body
Source Link
Chris Dodd
  • 795
  • 2
  • 4

Stack based langauges that directly use RPN tend to have quite different syntaxes for conditionals, built up from their underlying stack operations.


In FORTH, you have words that compile directly to (conditional) branches and branch targets:

  • IF: pop stack and conditional branch forward if value popped is 0 (false)
  • ELSE: unconditional forward branch + target of last unresolved IF branch
  • THEN: target of last unresolved IF or ELSE branch

That gives you code that looks like

cond IF iftrue ELSE iffalse THEN

where cond is RPN code that leaves a boolean value on the stack, after which either the iftrue or iffalse code will run depending on whether that value was non-zero or zero.


In Postscript, things are built around the {...} construct that compiles stored procedures -- any code in curly braces is compiled and a reference to the compiled code is pushed on the stack. That give the constructgives you code that looks like

cond {iftrue} {iffalse} ifelse

where ifelse just pops three things from the stack (condition and two stored procedure refs) and executes one of the stored procedures. If either of the latter is not a stored procedure, it will just be pushed back on the stack, so if you just want a value in either slot (rather than actual conditional execution), the braces are unneeded.

Stack based langauges that directly use RPN tend to have quite different syntaxes for conditionals, built up from their underlying stack operations.


In FORTH, you have words that compile directly to (conditional) branches and branch targets:

  • IF: pop stack and conditional branch forward if value popped is 0 (false)
  • ELSE: unconditional forward branch + target of last unresolved IF branch
  • THEN: target of last unresolved IF or ELSE branch

That gives you code that looks like

cond IF iftrue ELSE iffalse THEN

where cond is RPN code that leaves a boolean value on the stack, after which either the iftrue or iffalse code will run depending on whether that value was non-zero or zero.


In Postscript, things are built around the {...} construct that compiles stored procedures -- any code in curly braces is compiled and a reference to the compiled code is pushed on the stack. That give the construct

cond {iftrue} {iffalse} ifelse

where ifelse just pops three things from the stack (condition and two stored procedure refs) and executes one of the stored procedures. If either of the latter is not a stored procedure, it will just be pushed back on the stack, so if you just want a value in either slot (rather than actual conditional execution), the braces are unneeded.

Stack based langauges that directly use RPN tend to have quite different syntaxes for conditionals, built up from their underlying stack operations.


In FORTH, you have words that compile directly to (conditional) branches and branch targets:

  • IF: pop stack and conditional branch forward if value popped is 0 (false)
  • ELSE: unconditional forward branch + target of last unresolved IF branch
  • THEN: target of last unresolved IF or ELSE branch

That gives you code that looks like

cond IF iftrue ELSE iffalse THEN

where cond is RPN code that leaves a boolean value on the stack, after which either the iftrue or iffalse code will run depending on whether that value was non-zero or zero.


In Postscript, things are built around the {...} construct that compiles stored procedures -- any code in curly braces is compiled and a reference to the compiled code is pushed on the stack. That gives you code that looks like

cond {iftrue} {iffalse} ifelse

where ifelse just pops three things from the stack (condition and two stored procedure refs) and executes one of the stored procedures. If either of the latter is not a stored procedure, it will just be pushed back on the stack, so if you just want a value in either slot (rather than actual conditional execution), the braces are unneeded.

added 4 characters in body
Source Link
Chris Dodd
  • 795
  • 2
  • 4

Stack based langauges that directly use RPN tend to have quite different syntaxes for conditionals, built up from their underlying stack operations.


In FORTHFORTH, you have words that compile directly to (conditional) branches and branch targets:

  • IF: pop stack and conditional branch forward if value popped is 0 (false)
  • ELSE: unconditional forward branch + target of last unresolved IF branch
  • THEN: target of last unresolved IF or ELSE branch

That gives you code that looks like

cond IF iftrue ELSE iffalse THEN

where cond is RPN code that leaves a boolean value on the stack, after which either the iftrue or iffalse code will run depending on whether that value was non-zero or zero.


In Postscript, things are built around the {...} construct that compiles stored procedures -- any code in curly braces is compiled and a reference to the compiled code is pushed on the stack. That give the construct

cond {iftrue} {iffalse} ifelse

where ifelse just pops three things from the stack (condition and two stored procedure refs) and executes one of the stored procedures. If either of the latter is not a stored procedure, it will just be pushed back on the stack, so if you just want a value in either slot (rather than actual conditional execution), the braces are unneeded.

Stack based langauges that directly use RPN tend to have quite different syntaxes for conditionals, built up from their underlying stack operations.


In FORTH, you have words that compile directly to (conditional) branches and branch targets:

  • IF: pop stack and conditional branch forward if value popped is 0 (false)
  • ELSE: unconditional forward branch + target of last unresolved IF branch
  • THEN: target of last unresolved IF or ELSE branch

That gives you code that looks like

cond IF iftrue ELSE iffalse THEN

where cond is RPN code that leaves a boolean value on the stack, after which either the iftrue or iffalse code will run depending on whether that value was non-zero or zero.


In Postscript, things are built around the {...} construct that compiles stored procedures -- any code in curly braces is compiled and a reference to the compiled code is pushed on the stack. That give the construct

cond {iftrue} {iffalse} ifelse

where ifelse just pops three things from the stack (condition and two stored procedure refs) and executes one of the stored procedures. If either of the latter is not a stored procedure, it will just be pushed back on the stack, so if you just want a value in either slot (rather than actual conditional execution), the braces are unneeded.

Stack based langauges that directly use RPN tend to have quite different syntaxes for conditionals, built up from their underlying stack operations.


In FORTH, you have words that compile directly to (conditional) branches and branch targets:

  • IF: pop stack and conditional branch forward if value popped is 0 (false)
  • ELSE: unconditional forward branch + target of last unresolved IF branch
  • THEN: target of last unresolved IF or ELSE branch

That gives you code that looks like

cond IF iftrue ELSE iffalse THEN

where cond is RPN code that leaves a boolean value on the stack, after which either the iftrue or iffalse code will run depending on whether that value was non-zero or zero.


In Postscript, things are built around the {...} construct that compiles stored procedures -- any code in curly braces is compiled and a reference to the compiled code is pushed on the stack. That give the construct

cond {iftrue} {iffalse} ifelse

where ifelse just pops three things from the stack (condition and two stored procedure refs) and executes one of the stored procedures. If either of the latter is not a stored procedure, it will just be pushed back on the stack, so if you just want a value in either slot (rather than actual conditional execution), the braces are unneeded.

added 165 characters in body
Source Link
Chris Dodd
  • 795
  • 2
  • 4

Stack based langauges that directly use RPN tend to have quite different syntaxes for conditionals, built up from their underlying stack operations.


In FORTH, you have words that compile directly to (conditional) branches and branch targets:

  • IF: pop stack and conditional branch forward if value popped is 0 (false)
  • ELSE: unconditional forward branch + target of last unresolved IF branch
  • THEN: target of last unresolved IF or ELSE branch

That gives you code that looks like

cond IF iftrue ELSE iffalse THEN

where cond is RPN code that leaves a boolean value on the stack, after which either the iftrue or iffalse code will run depending on whether that value was non-zero or zero.


In Postscript, things are built around the {...} construct that compiles stored procedures -- any code in curly braces is compiled and a reference to the compiled code is pushed on the stack. That give the construct

cond {iftrue} {iffalse} ifelse

where ifelse just pops three things from the stack (condition and two stored procedure refs) and executes one of the stored procedures. If either of the latter is not a stored procedure, it will just be pushed back on the stack, so if you just want a value in either slot (rather than actual conditional execution), the braces are unneeded.

Stack based langauges that directly use RPN tend to have quite different syntaxes for conditionals, built up from their underlying stack operations.


In FORTH, you have words that compile directly to (conditional) branches and branch targets:

  • IF pop stack and conditional branch forward if value popped is 0 (false)
  • ELSE unconditional forward branch + target of last unresolved IF branch
  • THEN target of last unresolved IF or ELSE branch

That gives you code that looks like

cond IF iftrue ELSE iffalse THEN

where cond is RPN code that leaves a boolean value on the stack, after which either the iftrue or iffalse code will run depending on whether that value was non-zero or zero.


In Postscript, things are built around the {...} construct that compiles stored procedures -- any code in curly braces is compiled and a reference to the compiled code is pushed on the stack. That give the construct

cond {iftrue} {iffalse} ifelse

where ifelse just pops three things from the stack (condition and two stored procedure refs) and executes one of the stored procedures.

Stack based langauges that directly use RPN tend to have quite different syntaxes for conditionals, built up from their underlying stack operations.


In FORTH, you have words that compile directly to (conditional) branches and branch targets:

  • IF: pop stack and conditional branch forward if value popped is 0 (false)
  • ELSE: unconditional forward branch + target of last unresolved IF branch
  • THEN: target of last unresolved IF or ELSE branch

That gives you code that looks like

cond IF iftrue ELSE iffalse THEN

where cond is RPN code that leaves a boolean value on the stack, after which either the iftrue or iffalse code will run depending on whether that value was non-zero or zero.


In Postscript, things are built around the {...} construct that compiles stored procedures -- any code in curly braces is compiled and a reference to the compiled code is pushed on the stack. That give the construct

cond {iftrue} {iffalse} ifelse

where ifelse just pops three things from the stack (condition and two stored procedure refs) and executes one of the stored procedures. If either of the latter is not a stored procedure, it will just be pushed back on the stack, so if you just want a value in either slot (rather than actual conditional execution), the braces are unneeded.

Source Link
Chris Dodd
  • 795
  • 2
  • 4
Loading