skx / gobasic

A BASIC interpreter written in golang.
https://blog.steve.fi/tags/basic/
GNU General Public License v2.0
323 stars 27 forks source link

Add SPC #104

Closed skx closed 5 years ago

skx commented 5 years ago

SPC(N) returns a string containing N space-characters. Simple to add, and useful.

With that implemented we can borrow this example:

Rewritten here as:

  $ cat circle.bas 
  10 RADIUS=20
  20 FOR I=1 TO RADIUS-1
  30 W=RADIUS*SIN(180/RADIUS*I*3.1415/180)
  40 PRINT SPC(RADIUS-W)
  50 LET m = W * 2
  60 FOR J=1 TO m
  70 PRINT "*"
  80 NEXT J
  90 PRINT "\n"
  100 NEXT I

Output:

   ./gobasic circle.bas  | perl -pi -e "s/^/          /g"
                       ******
                    ************
                 ******************
               ***********************
            ****************************
          ********************************
         ***********************************
       **************************************
       ***************************************
       ***************************************
       ***************************************
       **************************************
         ***********************************
          ********************************
            ****************************
               ***********************
                 ******************
                    ************
                       ******
                          **
skx commented 5 years ago

See also #103.