Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
howto:calculate-dc [2017/01/02 07:19]
gerbehar typo corrected, semicolon inserted
howto:calculate-dc [2018/06/21 23:36] (current)
izxle added missing <nowiki> </nowiki>
Line 160: Line 160:
 </​code>​ </​code>​
  
-The above snippet ​use newlines to embed comments, but it doesn'​t+The above snippet ​uses newlines to embed comments, but it doesn'​t
 really matter, you can use ''​echo '​12sa10la+p'​| dc'',​ with the same results. really matter, you can use ''​echo '​12sa10la+p'​| dc'',​ with the same results.
  
-The register can contain more that just a value, **each register is a+The register can contain more than just a value, **each register is a
 stack on its own**. stack on its own**.
  
Line 181: Line 181:
 ===== Macros ===== ===== Macros =====
  
-''​dc''​ lets you push aribtrary ​strings on the stack when the strings are enclosed in ''​[]''​.+''​dc''​ lets you push arbitrary ​strings on the stack when the strings are enclosed in ''​[]''​.
 You can print it with ''​p'':​ ''<​nowiki>​dc <<<​ '​[Hello World!]p'</​nowiki>''​ and you can You can print it with ''​p'':​ ''<​nowiki>​dc <<<​ '​[Hello World!]p'</​nowiki>''​ and you can
 evalute it with x: ''<​nowiki>​dc <<<​ '[1 2+]xp'</​nowiki>''​. evalute it with x: ''<​nowiki>​dc <<<​ '[1 2+]xp'</​nowiki>''​.
  
 This is not that interesting until combined with registers. This is not that interesting until combined with registers.
-First let's say we want the to calculate the square of a number+Firstlet's say we want to calculate the square of a number
 (don't forget to include ''​f''​ if you get lost!): (don't forget to include ''​f''​ if you get lost!):
 <​code>​ <​code>​
Line 196: Line 196:
 </​code>​ </​code>​
  
-Now we have several ​cube to calculate, we could use ''<​nowiki>​dd**</​nowiki>''​ several times, or+Now we have several ​cubes to calculate, we could use ''<​nowiki>​dd**</​nowiki>''​ several times, or
 use a macro. use a macro.
  
Line 228: Line 228:
 Some ''​dc''​ have ''>​R <R =R'',​ GNU ''​dc''​ had some more, check your manual. Note Some ''​dc''​ have ''>​R <R =R'',​ GNU ''​dc''​ had some more, check your manual. Note
 that the test "​consumes"​ its operands: the 2 first elements are popped that the test "​consumes"​ its operands: the 2 first elements are popped
-off the stack (you can verify that ''​dc <<<​ "[f]sR 2 1 >R 1 2 >R f"''​+off the stack (you can verify that ''​<​nowiki>​dc <<<​ "[f]sR 2 1 >R 1 2 >R f"</​nowiki>​''​
 doesn'​t print anything) doesn'​t print anything)
  
 Have you noticed how we can //include// a macro (string) in a macro? and as ''​dc''​ Have you noticed how we can //include// a macro (string) in a macro? and as ''​dc''​
-relies on a stack we can in fact use the macro recursively (have your+relies on a stack we canin factuse the macro recursively (have your
 favorite control-c key combo ready ;)) : favorite control-c key combo ready ;)) :
  
Line 252: Line 252:
   1 -      # we decrement the index by one   1 -      # we decrement the index by one
   si    # store decremented index (i=i-1)   si    # store decremented index (i=i-1)
- 0 li >L   # if i > 0 the execute L+ 0 li >L   # if i > 0 then execute L
 ] sL       # store our macro with the name L ] sL       # store our macro with the name L
    
  • howto/calculate-dc.1483341541.txt
  • Last modified: 2017/01/02 07:19
  • by gerbehar