### Author Topic: BASIC difference  (Read 1660 times)

#### B+

• Full Member
• Posts: 215
##### BASIC difference
« on: April 20, 2015 »
Here are some notes to those with some Basic experience:
Code: [Select]
`rem string test.txt 2015-04-19 B+rem what the heck happened to right\$ function the other night?rem Maybe I tried Right\$ not right\$rem Maybe Naalaa counts between letters like Python doestest\$="Hi NaaLaa"wln "test\$="+test\$+", with length of:"+str\$(len(test\$))wlnfor i=0 to len(test\$)+1write "For i="+str\$(i)+":"write "  left\$(test\$,i)="+left\$(test\$,i)write "  mid\$(test\$,i)="+mid\$(test\$,i)write "  right\$(test\$,i)="+right\$(test\$,i)wlnwlnnextwln "results: mid\$ is one off normal basic experience, 0 to len(word\$)-1"wln "right\$ is wacky as all heck, no wonder I had such a time the other night!"wln "left\$ is the only normal, BTW mid\$ does 1 charater automatic with 2 parameter." wln "What is nice is that it doesn't error out when i exceeds the string length!" wait keydown`
B+

#### B+

• Full Member
• Posts: 215
##### Re: BASIC difference
« Reply #1 on: April 30, 2015 »
Some impressive comparisons to SmallBasic after Simple Sieve modified in a couple of places, ironically I discover them while playing with the slowest BASIC I've ever encountered, BASIC 256:

Code: [Select]
`rem Simple Sieve v2.txt 2015-04-30 B+ some improvementslistmode=1d=1000rem Simple Sieve before V 2 rem   1,000,000     78,498 primes in     967 msecs,     961 msecsrem  10,000,000    664,579 primes in  10,100 msecs,  10,123 msecsrem 100,000,000  5,761,455 primes in 109,596 msecs, 109,872 msecsrem V 2 changesrem   1,000,000     78,498 primes in     931 msecs,     914 msecsrem  10,000,000    664,579 primes in   9,940 msecs,   9,834 msecsrem 100,000,000  5,761,455 primes in 106,775 msecs, 106,976 msecsset window 0,0,800,600toc=time()wln "Primes to "+str\$(d)+":"wlnc[d+1]cnt=0i=4while i<=d c[i]=1 i=i+2wendcnt=1if listmode=1 then write rite\$("     "+str\$(2),5)i=3while i<=d if c[i]=0 cnt=cnt+1 if listmode=1 write rite\$("    "+str\$(i),5) if cnt % 15=0 then wln endif if i*i<=d j=2*i          while j<=d                   c[j]=1               j=j+i            wend endif endif i=i+2wendtic=time()wlnwlnwln "prime count is "+str\$(cnt)+", in "+str\$(tic-toc)+" msecs."rem better be 168 for 1000wait keydownendfunction rite\$(stringy\$,amount)l=len(stringy\$)return mid\$(stringy\$,l-amount,amount)endfunc`
SmallBASIC couldn't get past 25,000,000 and was doing 10,000,000 in over 20 secs.
But with that I could STEP through FOR/NEXT loops...

B+
B+

#### Hemulius

• Newbie
• Posts: 4
##### Re: BASIC difference
« Reply #2 on: August 27, 2015 »
Translated Simple Sieve to VM, for fun and exercise mainly.
Code: [Select]
`rem Simple Sieve v2.txt 2015-04-30 B+ some improvementsrem listmode=0 ...related lines removed for convenienced=1000000set window 0,0,800,600toc=time()wln "Primes to "+str\$(d)+":"wlnrem --------- c[d+1] cnt = 0 i = 4 MOV @0 c@start: STP @0 i MOV [@0] 1 ADD i 2 CMP d 1 JLE start cnt = 1 i = 3 j = 0@inner: rem while i<=d rem if c[i]=0 MOV @0 c STP @0 i CMP [@0] 0 JNE exit rem cnt=cnt+1        ADD cnt 1 rem if i*i<=d MOV @0 i MUL @0 i CMP @0 d JG exit rem j=2*i MOV @0 i MUL @0 2 MOV j @0 rem while j<=d MOV @0 j CMP @0 d JG exit@outer: rem c[j]=1 MOV @0 c STP @0 j MOV [@0] 1 rem j=j+i        ADD j i MOV @0 j CMP @0 d JLE outer@exit: rem i=i+2        ADD i 2 MOV @0 i CMP @0 d JLE innerrem ---------tic=time()wlnwln "prime count is "+str\$(cnt)+", in "+str\$(tic-toc)+" msecs."wait keydownend`
« Last Edit: August 31, 2015 by Hemulius »

#### aurel

• Jr. Member
• Posts: 61
##### Re: BASIC difference
« Reply #3 on: September 03, 2015 »
Ha Ha ha...
anyone of you master jumper can explain this experssion:

set prime = i + i + 3

#### Rick3137

• Sr. Member
• Posts: 341
• May the Force be with You
##### Re: BASIC difference
« Reply #4 on: September 05, 2015 »
Looks like Greek to me.

#### B+

• Full Member
• Posts: 215
##### Son of B!
« Reply #5 on: August 30, 2016 »

Code: [Select]
`' compare strings test.txt for Naalaa [B+=MGA] 2016-08-30' I spent a couple of frustrating hours before realizing...set window 100, 40, 800, 600a\$ = "1"'alternate next line 0, 1, 2b\$ = "0"if a\$ = b\$ then wln a\$ + " = " + b\$elseif a\$ < b\$ then wln a\$ + " < " + b\$elseif a\$ > b\$ then wln a\$ + " > " + b\$'oh add this test! Yes can detect a difference!elseif a\$ <> b\$ then wln a\$ + " <> " + b\$else wln "Naalaa does not compare strings at all!"endif'another test, will this eraseset caret 0, 0wln "                        "'result NO! could have been usefulset caret 0, 0wln "______"wait keydown`
B+

#### Marcus

• Hero Member
• Posts: 541
##### Re: BASIC difference
« Reply #6 on: August 31, 2016 »
Nah, naalaa just uses < and > to compare the lengths of strings for some reason. Might just be a leftover since the early days of naalaa (no, i don't mess around with strings much). I'll change it to a character based comparison in the next update, don't think anyone has ever used < or > anyway.
.\\\opz

#### Marcus

• Hero Member
• Posts: 541
##### Re: BASIC difference
« Reply #7 on: August 31, 2016 »
To be sure, what you're looking for is this:

Code: [Select]
`function StringGreater(a\$, b\$) if strcmp(a, b) > 0 then return true return falseendfuncfunction StringGreaterOrEqual(a\$, b\$) if strcmp(a, b) >= 0 then return true return falseendfuncfunction StringSmaller(a\$, b\$) if strcmp(a, b) < 0 then return true return falseendfuncfunction StringSmallerOrEqual(a\$, b\$) if strcmp(a, b) <= 0 then return true return falseendfuncfunction strcmp(a\$, b\$) la = len(a); lb = len(b) for i = 0 to min(la, lb) - 1 ca = asc(mid(a, i)); cb = asc(mid(b, i)) if ca > cb; return 1 elseif ca < cb; return -1 endif next if la > lb; return 1 elseif la < lb; return -1 endif return 0endfunc`
but applied to >, >=, < and <=?

Sorry for the inconvenience, I admit not using strings much at all for anything
.\\\opz

#### B+

• Full Member
• Posts: 215
##### Re: BASIC difference
« Reply #8 on: August 31, 2016 »
To be sure, what you're looking for is this:

Code: [Select]
`function StringGreater(a\$, b\$) if strcmp(a, b) > 0 then return true return falseendfuncfunction StringGreaterOrEqual(a\$, b\$) if strcmp(a, b) >= 0 then return true return falseendfuncfunction StringSmaller(a\$, b\$) if strcmp(a, b) < 0 then return true return falseendfuncfunction StringSmallerOrEqual(a\$, b\$) if strcmp(a, b) <= 0 then return true return falseendfuncfunction strcmp(a\$, b\$) la = len(a); lb = len(b) for i = 0 to min(la, lb) - 1 ca = asc(mid(a, i)); cb = asc(mid(b, i)) if ca > cb; return 1 elseif ca < cb; return -1 endif next if la > lb; return 1 elseif la < lb; return -1 endif return 0endfunc`
but applied to >, >=, < and <=?

Sorry for the inconvenience, I admit not using strings much at all for anything

I worked out similar but yours is more elegant    much more!!

BTW, I like how MID does not error when asking for neg position or one greater than length of source string.
B+