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

Support SWAP #92

Closed skx closed 5 years ago

skx commented 5 years ago

This pull-request will implement support for the SWAP primitive, and will close #90 once merged.

Sample usage:

   10 LET a = 3
   20 LET b = 41
   30 PRINT "A:" , a, " B:", b, "\n"
   40 SWAP a,b
   50 PRINT "A:" , a, " B:", b, "\n"
   60 PRINT "\n"

   100 DIM a(10)
   110 a[2] = 33
   120 PRINT "a[2]:", a[2], " a[3]", a[3], "\n"
   130 SWAP a[2], a[3]
   140 PRINT "a[2]:", a[2], " a[3]", a[3], "\n"
   150 PRINT "\n"

   1000 DIM a(3)
   1010 LET a[1] = "steve"
   1020 LET a[2] = "kemp"
   1030 PRINT a[1], " ", a[2], "\n"
   2000 SWAP a[1], a[2]
   2010 PRINT a[1], " ", a[2], "\n"
   2020 PRINT "\n"

Once implemented this is the expected outcome:

   frodo ~/go/src/github.com/skx/gobasic $ ./gobasic swap.bas 
   A: 3  B: 41 
   A: 41  B: 3 

   a[2]: 33  a[3] 0 
   a[2]: 0  a[3] 33 

   steve   kemp 
   kemp   steve