Si am un bug!! E in legatura cu consecintele folosirii variabilelor globale (nu se mai stie cine le modifica, cand le modifica)
27 noiembrie 2014
Parameter passing convention (value, reference, lazy) in Eopl3 unified
Si am un bug!! E in legatura cu consecintele folosirii variabilelor globale (nu se mai stie cine le modifica, cand le modifica)
09 noiembrie 2014
Grading situation
Cand si studentii s-au plictisit de atatea instructiuni si detalii de tinut cont pentru tema...
Cand in sfarsit inteleg durerea asistentului care trebuie sa verifice de 30 ori aceleasi si aceleasi instructiuni....
Un student trimite o rezolvare impecabila cu urmatoarele comentarii:
______________________________
# Description: Today we'll be reading a data file of information on the sales of a movie before printing out the information in a tedious-for-the-programmer fashion
# for your viewing pleasure. Afterwards we kick things over to Mike and Stan on "Who Bought the Most Tickets", America's #1 Show. Hopefully I won't get docked.
# for your viewing pleasure. Afterwards we kick things over to Mike and Stan on "Who Bought the Most Tickets", America's #1 Show. Hopefully I won't get docked.
------------------ urmeaza codul sursa, dupa care:
#Make it look nicer.......or less jumbled since technically that print statement up there already made it look nicer
print()
#I suppose you could say more more nicer, or aesthetic improvement if you want a reason to use the word aesthetic.
print()
#I don't see why you wouldn't. Say it once and see if just doesn't stick....aesthetic.
#Yes I realize the previous 3 comments and this one explaining those 3 comments have little to do with actual code.
#And this one here isn't even commenting on anything. It's just here......floating along...like clouds.
print()
#I suppose you could say more more nicer, or aesthetic improvement if you want a reason to use the word aesthetic.
print()
#I don't see why you wouldn't. Say it once and see if just doesn't stick....aesthetic.
#Yes I realize the previous 3 comments and this one explaining those 3 comments have little to do with actual code.
#And this one here isn't even commenting on anything. It's just here......floating along...like clouds.
------------------ urmeaza obisnuitul print al rezultatelor -----------
------------------ sau nu:
#I hope I don't get docked for this, but here goes:
print("Statistics (Game Show in this case)")
print("_____________________________________________________________________________________________________________")
print("Total tickets sold: ", total)
print()
print('Stan: "Ladies and Gentlemen, it has been an excitig show so far. Now to announce our winners!!"')
print()
print('Mike: "First up, our award for the most purchased adult tickets goes to: ', maxAdult, 'with a total of', maxAdultTickets,'"')
print()
print('Stan: "And last, but definitely not least, our award for the most purchased child tickets goes to: "')
print('Mike: "Drumroll please!!!!"')
print()
print('Stan: "Ladies and gentlemen!!! YOUR NEW LIGHTWEIGHT HEAVYWEIGHT ADULT CHILDRENS CHAMP OF THE WORLD!!! THE ONE AND ONLY TRUE KING. THE GLORIOUS..."')
print()
print('Mike: "Umm...Stan?"')
print()
print('Stan: "Hmm?, Oh yes, congratulations', maxChild, 'for purchasing the most child tickets with a total of', maxChildTickets, '"')
print()
print('Mike: "Alright folks, that concludes the series finale of Who Bought the Most Tickets. Goodbye and good riddance"')
print("____________________________________________________________________________________________________________")
print("Statistics (Game Show in this case)")
print("_____________________________________________________________________________________________________________")
print("Total tickets sold: ", total)
print()
print('Stan: "Ladies and Gentlemen, it has been an excitig show so far. Now to announce our winners!!"')
print()
print('Mike: "First up, our award for the most purchased adult tickets goes to: ', maxAdult, 'with a total of', maxAdultTickets,'"')
print()
print('Stan: "And last, but definitely not least, our award for the most purchased child tickets goes to: "')
print('Mike: "Drumroll please!!!!"')
print()
print('Stan: "Ladies and gentlemen!!! YOUR NEW LIGHTWEIGHT HEAVYWEIGHT ADULT CHILDRENS CHAMP OF THE WORLD!!! THE ONE AND ONLY TRUE KING. THE GLORIOUS..."')
print()
print('Mike: "Umm...Stan?"')
print()
print('Stan: "Hmm?, Oh yes, congratulations', maxChild, 'for purchasing the most child tickets with a total of', maxChildTickets, '"')
print()
print('Mike: "Alright folks, that concludes the series finale of Who Bought the Most Tickets. Goodbye and good riddance"')
print("____________________________________________________________________________________________________________")
-------------------- studentul doreste interactiune criptata:
#I'm curious, and apparently I have so little to do in life that I'm about to make a commented out if statement that may or may not receive a reply.
#From you of course
#if (you read these comments):
#if (You at least cracked a smile and I got a perfect score):
#Put "Brilliant!!!" (yes, 3 exclamation points) in the comments when you grade
#elif (You at least cracked a smile and I got close to a perfect score):
#Write "So Close!!" (this time 2 exclamation points) in the comments when you grade
#else:
#Anything beyond the first two conditions is impossible.
#else:
#Well then there isn't much point to this else statement now is there
#From you of course
#if (you read these comments):
#if (You at least cracked a smile and I got a perfect score):
#Put "Brilliant!!!" (yes, 3 exclamation points) in the comments when you grade
#elif (You at least cracked a smile and I got close to a perfect score):
#Write "So Close!!" (this time 2 exclamation points) in the comments when you grade
#else:
#Anything beyond the first two conditions is impossible.
#else:
#Well then there isn't much point to this else statement now is there
---------------- feedback-ul meu ----------------------------------
+0p: output is correct, aesthetic
-0p: it would be great if you stick only with the relevant stuff to output, I appreciate the sense of humor
-0p: it would be great if you stick only with the relevant stuff to output, I appreciate the sense of humor
--------------- conflictul interior intre dorinta de a pastra lucrurile la obiect si incurajarea spicing up the boring grading time este castigat de primul
29 octombrie 2014
Recursivitate in limbajul PROC (EOPL 3) | Simulating recursivity in PROC language, Eopl3
PROC nu suportă recursivitatea.
Pentru a o simula, se folosește artificiul numit y-combinator și se creează un caz de test în tests.scm pentru fiecare operație dorită.
1) Suma nr. 1 ... N
(sum-1-to-N
"let p = proc(f) proc(x)
if zero?(x) then 0 else -(((f f) -(x,1)), -(0,x))
in ((p p) 10)" 55)
2) Numerele Fibonacci: fibo (N) = fibo (N-1) + fibo(N-2)
(fibonacci "
let p = proc(f) proc(x)
if zero?(x) then 0 else if zero?(-(x,1)) then 1 else -( ((f f) -(x,1)), -(0, ((f f) -(x, 2))))
in ((p p) 10)
" 55)
3) Înmulțirea a două numere
(x*y
"let p = proc(f) proc(x) proc(y) proc(z)
if zero?(z) then x else ((((f f) -(x, -(0,y))) y) -(z, 1))
in ((((p p) 0) 6) 7)" 42)
4) Factorial: N! = 1 * 2 * ... * N
(factorial
"let multipl = proc(a) proc(b)
let p = proc(f) proc(x) proc(y) proc(z)
if zero?(z) then x else ((((f f) -(x, -(0,y))) y) -(z, 1))
in ((((p p) 0) a) b)
in
let fun = proc (f) proc(x)
if zero?(-(x,1)) then 1 else ((multipl x) ((f f) -(x,1)))
in ((fun fun) 5)" 120)
Pentru a o simula, se folosește artificiul numit y-combinator și se creează un caz de test în tests.scm pentru fiecare operație dorită.
1) Suma nr. 1 ... N
(sum-1-to-N
"let p = proc(f) proc(x)
if zero?(x) then 0 else -(((f f) -(x,1)), -(0,x))
in ((p p) 10)" 55)
2) Numerele Fibonacci: fibo (N) = fibo (N-1) + fibo(N-2)
(fibonacci "
let p = proc(f) proc(x)
if zero?(x) then 0 else if zero?(-(x,1)) then 1 else -( ((f f) -(x,1)), -(0, ((f f) -(x, 2))))
in ((p p) 10)
" 55)
3) Înmulțirea a două numere
(x*y
"let p = proc(f) proc(x) proc(y) proc(z)
if zero?(z) then x else ((((f f) -(x, -(0,y))) y) -(z, 1))
in ((((p p) 0) 6) 7)" 42)
4) Factorial: N! = 1 * 2 * ... * N
(factorial
"let multipl = proc(a) proc(b)
let p = proc(f) proc(x) proc(y) proc(z)
if zero?(z) then x else ((((f f) -(x, -(0,y))) y) -(z, 1))
in ((((p p) 0) a) b)
in
let fun = proc (f) proc(x)
if zero?(-(x,1)) then 1 else ((multipl x) ((f f) -(x,1)))
in ((fun fun) 5)" 120)
Extensii pentru limbajul LET | EOPL3 Let language extensions - Stack operations
Constructori:
* stack -> list
* push : expVal x list -> list
Observatori:
* top : list -> expVal
* pop : list -> list
* size : list -> num-val
> lang.scm_________________________________________________
;; the grammar
(expression ("stack") stack-exp)
(expression ("push" expression expression) push-exp)
(expression ("top" expression) top-exp)
(expression ("pop" expression) pop-exp)
(expression ("size" "(" expression ")") size-exp)
> interp.scm_______________________________________________
;; value-of
(stack-exp ()
'())
(push-exp (exp1 exp2)
(cons (value-of exp1 env) (value-of exp2 env)))
(top-exp (exp1)
(car (value-of exp1 env))
)
(pop-exp (exp1)
(cdr (value-of exp1 env))
)
(size-exp (exp1)
(num-val (length (value-of exp1 env)))
)
> tests.scm__________________________________________________
(stack-1 "top stack" error)
(stack-2 "top push 3 push 4 stack" 3)
(stack-3 "pop stack" error)
(stack-4 "pop push 1 push 2 push zero?(0) stack" (2 #t))
(stack-5 "size(stack)" 0)
(stack-6 "size(push 100 stack)" 1)
(stack-7 "let x=1 in let y=2 in top pop push x push -(x,y) push y stack" -1)
_____________________________________________________________
* stack -> list
* push : expVal x list -> list
Observatori:
* top : list -> expVal
* pop : list -> list
* size : list -> num-val
> lang.scm_________________________________________________
;; the grammar
(expression ("stack") stack-exp)
(expression ("push" expression expression) push-exp)
(expression ("top" expression) top-exp)
(expression ("pop" expression) pop-exp)
(expression ("size" "(" expression ")") size-exp)
> interp.scm_______________________________________________
;; value-of
(stack-exp ()
'())
(push-exp (exp1 exp2)
(cons (value-of exp1 env) (value-of exp2 env)))
(top-exp (exp1)
(car (value-of exp1 env))
)
(pop-exp (exp1)
(cdr (value-of exp1 env))
)
(size-exp (exp1)
(num-val (length (value-of exp1 env)))
)
> tests.scm__________________________________________________
(stack-1 "top stack" error)
(stack-2 "top push 3 push 4 stack" 3)
(stack-3 "pop stack" error)
(stack-4 "pop push 1 push 2 push zero?(0) stack" (2 #t))
(stack-5 "size(stack)" 0)
(stack-6 "size(push 100 stack)" 1)
(stack-7 "let x=1 in let y=2 in top pop push x push -(x,y) push y stack" -1)
_____________________________________________________________
Extensii pentru limbajul LET | EOPL3 Let language extensions for list: cons, car, cdr, ...
Constructori:
* listagoala -> ListofExpval
* adauga : expVal x ListofExpval -> ListofExpval
Observatori:
* primul : ListofExpval -> expVal
* restul : ListofExpval -> ListofExpval
* e_goala : ListofExpval -> Bool
> lang.scm___________________________________________________
;;; in the grammar
(expression
("lista-goala")
gol-exp)
(expression
("adauga" expression "la" expression)
add-exp)
(expression
("primul" "din" expression)
car-exp)
(expression
("restul" "din" expression)
cdr-exp)
(expression
("e-goala" "(" expression ")")
isempty-exp)
> interp.scm__________________________________________________
;; in value-of
(gol-exp ()
'()
)
(add-exp (exp1 exp2)
(cons (value-of exp1 env) (value-of exp2 env)))
(car-exp (exp1)
(car (value-of exp1 env)))
(cdr-exp (exp1)
(cdr (value-of exp1 env)))
(isempty-exp (exp1)
(bool-val (null? (value-of exp1 env))))
> tests.scm____________________________________________________
(lista-test1 "adauga 5 la adauga 6 la lista-goala" (5 6))
(lista-test2 "lista-goala" ())
(lista-test3 "let x=1 in adauga x la lista-goala" (1))
(lista-test4 "adauga zero?(1) la adauga 5 la adauga let x = 2 in -(x,1) la lista-goala" (#f 5 1))
(lista-test5 "e-goala(lista-goala)" #t)
(lista-test6 "e-goala(adauga 3 la lista-goala)" #f)
(lista-test7 "primul din let x=1 in adauga x la lista-goala" 1)
(lista-test8 "restul din adauga zero?(1) la adauga 5 la adauga let x = 2 in -(x,1) la lista-goala" (5 1))
> top.scm______________________________________________________
;;; in sloppy->expval (for tests.scm)
((list? sloppy-val) (map sloppy->expval sloppy-val))
* listagoala -> ListofExpval
* adauga : expVal x ListofExpval -> ListofExpval
Observatori:
* primul : ListofExpval -> expVal
* restul : ListofExpval -> ListofExpval
* e_goala : ListofExpval -> Bool
> lang.scm___________________________________________________
;;; in the grammar
(expression
("lista-goala")
gol-exp)
(expression
("adauga" expression "la" expression)
add-exp)
(expression
("primul" "din" expression)
car-exp)
(expression
("restul" "din" expression)
cdr-exp)
(expression
("e-goala" "(" expression ")")
isempty-exp)
> interp.scm__________________________________________________
;; in value-of
(gol-exp ()
'()
)
(add-exp (exp1 exp2)
(cons (value-of exp1 env) (value-of exp2 env)))
(car-exp (exp1)
(car (value-of exp1 env)))
(cdr-exp (exp1)
(cdr (value-of exp1 env)))
(isempty-exp (exp1)
(bool-val (null? (value-of exp1 env))))
> tests.scm____________________________________________________
(lista-test1 "adauga 5 la adauga 6 la lista-goala" (5 6))
(lista-test2 "lista-goala" ())
(lista-test3 "let x=1 in adauga x la lista-goala" (1))
(lista-test4 "adauga zero?(1) la adauga 5 la adauga let x = 2 in -(x,1) la lista-goala" (#f 5 1))
(lista-test5 "e-goala(lista-goala)" #t)
(lista-test6 "e-goala(adauga 3 la lista-goala)" #f)
(lista-test7 "primul din let x=1 in adauga x la lista-goala" 1)
(lista-test8 "restul din adauga zero?(1) la adauga 5 la adauga let x = 2 in -(x,1) la lista-goala" (5 1))
> top.scm______________________________________________________
;;; in sloppy->expval (for tests.scm)
((list? sloppy-val) (map sloppy->expval sloppy-val))
Abonați-vă la:
Postări (Atom)