BASIC vs Python

Dan Bishop danb_83 at yahoo.com
Fri Dec 17 20:34:02 CET 2004


Peter Otten wrote:
> Peter Hickman wrote:
>
> > Mike Meyer wrote:
> >> BASIC as implented by Microsoft for the Apple II and the TRS 80
(among
> >> others) is simply the worst programming language I have ever
> >> encountered. Assembler was better - at least you had recursion
with
> >> assembler.
> >
> > Basic has progressed much since you last looked at it, time to
update your
> > facts. Basic has recursion, it compiles to native code, it has
objects,
> > can be event driven and everything else you would expect of a
language.
> >
> > Computing changes too fast to allow you to think you know it all.
Keep up
> > to date granddad.
> >
> > However what basic doesn't have is a portable language definition.
>
> May you could give us an idea of the current state of basic affairs
then by
> translating the following example snippet:
>
> It's me wrote:
>
> > I saw this code from an earlier post:
> >
> > lst1 = ["ab", "ac", "ba", "bb", "bc"]
> > lst2 = ["ac", "ab", "bd", "cb", "bb"]
> > dct1 = dict.fromkeys(lst1) # <-- I'll assume "lst2" was intended.
> > print [x for x in lst1 if x not in dct1]
> > print [x for x in lst1 if x in dct1]
> >
> > It's simply remarkable for somebody to be able to do it so cleanly
(and so
> > obviously) - "out of the box", if you may.
> >
> > Sure, you can do it in Basic.  Ur...sure?  Yes, sure...

In Microsoft QBasic (1987), this could be written as:

DECLARE FUNCTION INARRAY% (ARR() AS STRING, X AS STRING)

DIM LST1(4) AS STRING
DIM LST2(4) AS STRING
DIM I AS INTEGER

FOR I = 0 TO UBOUND(LST1)
READ LST1(I)
NEXT

FOR I = 0 TO UBOUND(LST2)
READ LST2(I)
NEXT

' Print the elements of LST1 that are NOT in LST2
FOR I = 0 TO UBOUND(LST1)
IF INARRAY(LST2(), LST1(I)) = 0 THEN PRINT LST1(I); " ";
NEXT
PRINT

' Print the elements of LST1 that are in LST2
FOR I = 0 TO UBOUND(LST1)
IF INARRAY(LST2(), LST1(I)) = 1 THEN PRINT LST1(I); " ";
NEXT
PRINT

' Elements of LST1
DATA "AB", "AC", "BA", "BB", "BC"
' Elements of LST2
DATA "AC", "AB", "BD", "CB", "BB"

FUNCTION INARRAY% (ARR() AS STRING, X AS STRING)
' Return 1 if X in ARR, 0 otherwise
DIM I AS INTEGER
FOR I = LBOUND(ARR) TO UBOUND(ARR)
IF X = ARR(I) THEN
INARRAY = 1
EXIT FUNCTION
      END IF
   NEXT
   INARRAY = 0
END FUNCTION




More information about the Python-list mailing list