Skip to content

yoonjaecho/Scheme_Interpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

9432fd3 · Jul 24, 2016

History

48 Commits
May 22, 2016
May 22, 2016
Jul 24, 2016
Jul 24, 2016

Repository files navigation

Scheme_Interpreter

Scheme Interpreter in python following Cute16 grammar.

How to use ?

Just run this file with..

python Scheme_Interpreter.py

About this

  1. Process with "define" about variable or function.

  2. Lambda function.

  3. In functions, It can call global functions.

  4. Scope

  5. Nested function.

  6. Recursion function.

Example

( ( 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 ) ) ) ) ) ) )