SiteMap / AllPages / Out

VisualBasicVsScheme

Here is something on the benefits of Scheme, posted with permission by the author.

 From: Bruce R. Lewis
 Subject: Re: Why does FSF recommend Scheme?
 Newsgroups: gnu.misc.discuss
 Date: 14 Jun 2001 16:25:49 -0400
 Organization: MIT Alumni

[...]

I did a google search for "VBA examples", clicked on the top link, and chose one for comparison that seemed to involve slightly more than a hook into an application, since comparing RenderFancyGraphics() vs (render-fancy-graphics) syntax isn't particularly enlightening.

http://www.mindspring.com/~tflynn/excelvba4.html#Arrays

    Sub MyTestArray()
    Dim myCrit(1 To 4) As String ' Declaring array and setting bounds
    Dim Response As String
    Dim i As Integer
    Dim myFlag As Boolean
    myFlag = False
    '  To fill array with values
        myCrit(1) = "A"
        myCrit(2) = "B"
        myCrit(3) = "C"
        myCrit(4) = "D"
    Do Until myFlag = True
    Response = InputBox("Please enter your choice: (i.e. A,B,C or D)")
    '  Check if Response matches anything in array
        For i = 1 To 4  'UCase ensures that Response and myCrit are the same case
            If UCase(Response) = UCase(myCrit(i)) Then
                myFlag = True: Exit For
            End If
        Next i
    Loop
    End Sub

Scheme equivalent

    (define (my-test-array)
      (define response
        (input-box "Please enter your choice: (i.e. A,B,C or D)"))
      (if (member (string-upcase response) (list "A" "B" "C" "D"))
          response
          (my-test-array)))

In this example I assume the app defines an input-box function that does the equivalent of Excel's InputBox(). Everything else is standard Scheme.

Prior familiarity is the only thing that can make the VBA example more readable. Someone starting from scratch could learn to understand and mimic the Scheme example faster.

Scheme is difficult when used to solve inherently difficult problems. Unfortunately, that's the only context many programmers see it in, i.e. in Computer Science courses. It's perfectly good for MIS-type programming too.


SiteMap / AllPages / Out / kensanata@gmail.com / Last change: 2001-06-30