Scheme Interpreter in python following Cute16 grammar.
Just run this file with..
python Scheme_Interpreter.py
-
Process with "define" about variable or function.
-
Lambda function.
-
In functions, It can call global functions.
-
Scope
-
Nested function.
-
Recursion function.
( ( lambda ( x ) ( + x 1 ) ) 100 )
( ( lambda ( x ) ( + x ( ( lambda ( y ) ( + y 1 ) ) 1 ) ) ) 1 )
( define plus1 ( lambda ( x ) ( + x 1 ) ) )
( define plus2 ( lambda ( x ) ( + ( plus1 x ) 1 ) ) )
( define cube ( lambda ( n ) ( define sqrt ( lambda ( n ) ( * n n ) ) ) ( * ( sqrt n ) n ) ) )
( define foo ( lambda ( x y ) ( define goo ( lambda ( x ) ( * 2 x ) ) ) ( * ( goo x ) y ) ) )
( define quadra ( lambda ( n ) ( define cube ( lambda ( n )
( define sqrt ( lambda ( n ) ( * n n ) ) ) ( * ( sqrt n ) n ) ) ) ( * ( cube n ) n ) ) )
( quadra 5 )
( define lastitem ( lambda ( ls ) ( cond ( ( null? ( cdr ls ) ) ( car ls ) ) ( #T ( lastitem ( cdr ls ) ) ) ) ) )
( lastitem ' ( 1 2 3 ) )
( define length ( lambda ( ls ) ( cond ( ( null? ls ) 0 ) ( #T ( + 1 ( length ( cdr ls ) ) ) ) ) ) )
( length ' ( 1 2 3 4 5 ) )
( ( lambda ( a b ) ( + a b ) ) 24 5 )
( define fact ( lambda ( n ) ( cond ( ( = n 0 ) 1 ) ( #T ( * n ( fact ( - n 1 ) ) ) ) ) ) )