RU beehive logo ITEC dept promo banner
ITEC 380
2009fall
ibarland

homeinfolecturesexamshwsarchive

lect11c
prolog finish
project comments

Mention N3;
  scope of let;
  bound variable vs free variable;
  binding occurrence.



Project stuff:
 - backquote
    (define x 17)
    `(a 3 x y)   = (list 'a 3 'x 'y)
    `(a 3 ,x y)  = (list 'a 3 17 y)
    `(((sqrt 25)))  = (list (list (list 'sqrt 25)))
    `((,(sqrt 25))) = (list (list 5))

    So inside a back-quoted list, everything is a symbol (or nested list), unless you precede it with a comma which means “evaluate the next expression, and include the result in the list”.

    An example of where it’s particularly handy:
    If we are handling XML as nested lists in scheme, we might have
    `(p "This is some " (em "emphasized") " text.")
    I might want to create some XML where part of the result is computed, e.g.:
    `("this page generated on " ,(date->string (current-date)) " by " ,USER-NAME)

 - testing:
   - My suite does limited testing.
   - You can add '(require test-engine/scheme-tests)' if you want
     regular ol' check-expect in your module language.
   - In Java: print out the actual/expected, e.g.:

        String e1 = "let x = (3 plus 4) in (x times 2);";
        S.o.p.( "Got " + Expr.parse(e1) + " expected "
              + new LetExpr( "x",
                             new BinExpr( new Number(3), "plus", new Number(4)),
                             new BinExpr( new IDExpr("x"), "times", new Number(2))))
         Note a: 'toString' better work;
         Note b: override 'equals'

 - how to represent Id`s?
 - write all of ID stuff before starting Let.
 - can't eval an ID (!)  (throw an error)
 1  len([],0).
 2  len([_|R],X) :- len(R,Y), X is Y+1.
 3      
 4  len2(Data,TheLen) :-
 5    len2Help(0,Data,TheLen).
 6  
 7  % You might think:
 8  % len2Help(LenSoFar, Data, TheAns)
 9  %   :- LenSoFar=[], TheAns = LenSoFar.
10  
11  % A Better way:
12  len2Help(LenSoFar, [], LenSoFar).
13  
14  %len2Help(LenSoFar, Data, TheAns) :-
15  %  Data = [_|R], 
16  %  len2Help(X, R, TheRecAns),
17  %  X is LenSoFar + 1,
18  %  TheAns = TheRecAns.
19  
20  % A better way:
21  len2Help(LenSoFar, [_|R], TheAns) :-
22    X is LenSoFar + 1,
23    len2Help(X, R, TheAns).
24    
25  
26  
27  
28  
29  
30  

homeinfolecturesexamshwsarchive


©2009, Ian Barland, Radford University
Last modified 2009.Nov.16 (Mon)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme