neilsf / XC-BASIC

A compiling BASIC dialect for the Commodore-64
https://xc-basic.net/
MIT License
74 stars 15 forks source link

10 PRINT in XC-Basic #139

Closed frenchfaso closed 3 years ago

frenchfaso commented 3 years ago

I know it's silly, but... how would one write the famous 10 PRINT one-liner in XC-Basic?

10 PRINT CHR$(205.5+RND(1)); : GOTO 10

something like this would work...

dim c! fast
loop:
  c! = cast!(205.5 + rnd%()) - 205
  on c! goto lab1, lab2

lab1:
  print "{205}";
  goto loop

lab2:
  print "{206}";
  goto loop

..but it's obviously not a one-liner :grin: Is it possible to print a variable (byte) as PETSCI with the print statement?

loop: print cast!(205.5 + rnd%()); : goto loop
neilsf commented 3 years ago

Since strings are static in XC=BASIC v2, you can only manipulate them using POKE. This one is pretty short and it works:

char$ = " "
loop:
  poke char$, 205 + rshift!(rnd!(),7)
  print char$;
  goto loop

IMHO source code size doesn't really matter for a compiled language. It should be readable rather than compact.

frenchfaso commented 3 years ago

I like that! and it is blazingly fast :open_mouth:

IMHO source code size doesn't really matter for a compiled language. It should be readable rather than compact.

good point, it totally makes sense, it's the compiler that will optimize it for speed and/or compactness.